Repository navigation
Expand file tree
/
Copy pathinformation.js
More file actions
351 lines (308 loc) · 10.7 KB
/
Copy pathinformation.js
File metadata and controls
351 lines (308 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*global Utils, Template, Threads, ThreadUI, MessageManager, ContactRenderer,
Contacts, Settings*/
/*exported Information */
(function(exports) {
'use strict';
/*
Information view module is a subpanel belongs to TheadUI panel. This
module provide some default method for thiw view module:
show: Reuse the ThreadUI page for information view. Hiding unrelated icon,
reset the header, and render container for showing the view.
reset: Hide the view container, clean up the contact list and resume the
icons/header for ThreadUI.
renderContactList(participants, options): Rendering group-view style contact
list inside the page. Participants is an array of contact number and option
is for setting additional information for rendering other lock for contact
information.
*/
var TMPL = function createTemplate(tmpls) {
for (var key in tmpls) {
tmpls[key] = Template(tmpls[key]);
}
return tmpls;
}({
number: 'messages-number-tmpl',
report: 'information-report-tmpl'
});
function completeLocaleFormat(timestamp) {
return Utils.date.format.localeFormat(new Date(+timestamp),
navigator.mozL10n.get('report-dateTimeFormat')
);
}
function l10nContainsDateSetup(element, timestamp) {
element.dataset.l10nDate = timestamp;
element.dataset.l10nDateFormat = 'report-dateTimeFormat';
element.textContent = completeLocaleFormat(timestamp);
}
// Generate report Div contains delivery report and read report for showing
// report information within contact list
function createReportDiv(reports) {
var reportDiv = document.createElement('div');
var data = {
deliveryClass: '',
deliveryL10n: '',
deliveryDateL10n: '',
deliveryTimestamp: '',
readClass: '',
readL10n: '',
readDateL10n: '',
readTimestamp: ''
};
switch (reports.deliveryStatus) {
case 'pending':
data.deliveryL10n = 'message-requested';
break;
case 'success':
data.deliveryTimestamp = '' + reports.deliveryTimestamp;
data.deliveryDateL10n = completeLocaleFormat(reports.deliveryTimestamp);
break;
case 'error':
data.deliveryL10n = 'message-status-error';
break;
//'not-applicable' and other unknown status should hide the field
default:
data.deliveryClass = 'hide';
}
switch (reports.readStatus) {
case 'pending':
data.readL10n = 'message-requested';
break;
case 'success':
data.readTimestamp = '' + reports.readTimestamp;
data.readDateL10n = completeLocaleFormat(reports.readTimestamp);
break;
case 'error':
data.readL10n = 'message-status-error';
break;
//'not-applicable' and other unknown status should hide the field
default:
data.readClass = 'hide';
}
reportDiv.innerHTML = TMPL.report.interpolate(data);
return reportDiv;
}
function showSimInfo(element, iccId) {
var iccManager = navigator.mozIccManager;
// Hide the element when single SIM or no iccManager/mobileConnections
if (!(Settings.hasSeveralSim() && iccId && iccManager)) {
return;
}
var info =[];
// TODO: we might need to re-localize Sim name manually when language changes
var simId = Settings.getSimNameByIccId(iccId);
var operator = Settings.getOperatorByIccId(iccId);
var number = iccManager.getIccById(iccId).iccInfo.msisdn;
info = [simId, operator, number].filter(function(value){
return value;
});
element.querySelector('.sim-detail').textContent = info.join(', ');
element.classList.remove('hide');
}
// Compute attachment size and return the corresponding l10nId(KB/MB) and
// args (total attachment size for message)
function sizeL10nParam(attachments) {
var l10nId, l10nArgs;
var size = attachments.reduce(function(size, attachment) {
return (size += attachment.content.size);
}, 0);
var sizeKB = size / 1024;
if (sizeKB < 1000) {
l10nId = 'attachmentSize';
l10nArgs = { n: sizeKB.toFixed(1) };
} else {
l10nId = 'attachmentSizeMB';
l10nArgs = { n: (sizeKB / 1024).toFixed(1) };
}
return {
l10nId: l10nId,
l10nArgs: l10nArgs
};
}
// Incoming message: return array of sender number string;
// Outgoing message: return array of object(number and report div block).
function createListWithMsgInfo(message) {
var list = [];
if (message.delivery === 'received' ||
message.delivery === 'not-downloaded') { // received message
list.push(message.sender);
} else if (message.type === 'mms') { // sent mms message
message.deliveryInfo.forEach(function(info) {
list.push({number: info.receiver,
infoBlock: createReportDiv(info)});
});
} else { // sent sms message
var info = {};
info.deliveryStatus = message.deliveryStatus;
info.deliveryTimestamp = message.deliveryTimestamp;
list.push({number: message.receiver,
infoBlock: createReportDiv(info)});
}
return list;
}
var VIEWS = {
group: {
name: 'participants',
render: function renderGroup() {
var lastId = Threads.lastId;
var participants = lastId && Threads.get(lastId).participants;
this.renderContactList(participants);
navigator.mozL10n.localize(ThreadUI.headerText, 'participant', {
n: participants.length
});
},
elements: ['contact-list']
},
report: {
name: 'report',
render: function renderReport() {
var localize = navigator.mozL10n.localize;
var messageId = +window.location.hash.split('=')[1];
var request = MessageManager.getMessage(messageId);
request. {
var message = request.result;
var type = message.type;
this.subject.textContent = '';
// Fill in the description/status/size
if (type === 'sms') {
localize(this.type, 'message-type-sms');
this.sizeBlock.classList.add('hide');
} else { //mms
localize(this.type, 'message-type-mms');
// subject text content
var subject = message.subject;
if (subject) {
this.subject.textContent = subject;
}
// Message total size show/hide
if (message.attachments && message.attachments.length > 0) {
var params = sizeL10nParam(message.attachments);
localize(this.size, params.l10nId, params.l10nArgs);
this.sizeBlock.classList.remove('hide');
} else {
this.sizeBlock.classList.add('hide');
}
}
this.status.dataset.type = message.delivery;
localize(this.status, 'message-status-' + message.delivery);
// Set different layout/value for received and sent message
if (message.delivery === 'received' ||
message.delivery === 'not-downloaded') {
this.container.classList.add('received');
localize(this.contactTitle, 'report-from');
l10nContainsDateSetup(this.receivedTimeStamp, message.timestamp);
l10nContainsDateSetup(this.sentTimeStamp, message.sentTimestamp);
} else {
this.container.classList.remove('received');
localize(this.contactTitle, 'report-recipients');
l10nContainsDateSetup(this.datetime, message.timestamp);
}
//show sim information for dual sim device
showSimInfo(this.simInfo, message.iccId);
// Filled in the contact list. Only outgoing message contains detailed
// report information.
this.renderContactList(createListWithMsgInfo(message));
}).bind(this);
localize(ThreadUI.headerText, 'message-report');
},
elements: ['contact-list', 'status', 'size', 'size-block', 'sent-detail',
'type', 'subject', 'datetime', 'contact-title', 'received-detail',
'sent-timeStamp', 'received-timeStamp', 'sim-info']
}
};
var Information = function(type) {
var view = VIEWS[type];
var prefix = 'information-' + view.name;
this.container = document.getElementById(prefix);
this.render = view.render;
this.parent = document.getElementById('thread-messages');
view.elements.forEach(function(name) {
this[Utils.camelCase(name)] = this.container.querySelector('.' + name);
}, this);
this.reset();
if (this.contactList) {
this.contactList.addEventListener(
'click', function onListClick(event) {
event.stopPropagation();
event.preventDefault();
var target = event.target;
ThreadUI.promptContact({
number: target.dataset.number
});}
);
}
};
Information.prototype = {
constructor: Information,
show: function() {
// Hide the Messages edit icon, view container and composer form
this.parent.classList.add('information');
this.render();
// Append and Show the participants list
this.container.classList.remove('hide');
},
refresh: function() {
if (this.parent.classList.contains('information')) {
this.render();
}
},
reset: function() {
// Hide the information view
this.container.classList.add('hide');
// Remove all LIs
if (this.contactList) {
this.contactList.textContent = '';
}
// Restore message list view UI elements
this.parent.classList.remove('information');
},
// Param participants could be:
// - Array of contact number string or
// - Array of object({ number: number, infoBlock: infoBlock })
// for rendering the contact list.
renderContactList: function(participants) {
var ul = this.contactList;
var renderer = ContactRenderer.flavor('group-view');
ul.textContent = '';
participants.forEach(function(participant) {
var number, infoBlock, selector;
if (typeof participant === 'object') {
number = participant.number;
infoBlock = participant.infoBlock;
selector = '.suggestion';
} else {
number = participant;
}
Contacts.findByPhoneNumber(number, function(results) {
var isContact = results !== null && !!results.length;
if (isContact) {
renderer.render({
contact: results[0],
input: number,
infoBlock: infoBlock,
infoBlockParentSelector: selector,
target: ul
});
} else {
var li = document.createElement('li');
li.innerHTML = TMPL.number.interpolate({
number: number
});
var parentBlock = li.querySelector(selector);
if (parentBlock && infoBlock) {
parentBlock.appendChild(infoBlock);
navigator.mozL10n.translate(li);
}
ul.appendChild(li);
}
});
}.bind(this));
}
};
Information.initDefaultViews = function() {
// Create group / report information view
exports.GroupView = new Information('group');
exports.ReportView = new Information('report');
};
exports.Information = Information;
// end global closure
}(this));