Repository navigation
Expand file tree
/
Copy pathicc_menu.js
More file actions
136 lines (119 loc) · 4.16 KB
/
Copy pathicc_menu.js
File metadata and controls
136 lines (119 loc) · 4.16 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
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
(function() {
var iccMainHeader = document.getElementById('icc-mainheader');
var iccEntries = document.getElementById('icc-entries');
var iccLoaded = false;
function loadIccPage(callback) {
callback = (typeof callback === 'function') ? callback : function() {};
if (iccLoaded) {
return callback();
}
Settings.currentPanel = '#icc';
window.addEventListener('iccPageLoaded',
function oniccPageLoaded(event) {
iccLoaded = true;
callback();
});
}
function executeIccCmd(iccMessage) {
if (!iccMessage) {
return;
}
// Clear cache
var reqIccData = window.navigator.mozSettings.createLock().set({
'icc.data': null
});
reqIccData. icc_getIccData() {
DUMP('ICC Cache cleared');
};
// Open ICC section
DUMP('ICC message to execute: ', iccMessage);
loadIccPage(function() {
var event = new CustomEvent('stkasynccommand', {
detail: { 'message': iccMessage }
});
window.dispatchEvent(event);
});
}
setTimeout(function updateStkMenu() {
DUMP('Showing STK main menu');
// XXX https://bugzilla.mozilla.org/show_bug.cgi?id=844727
// We should use Settings.settingsCache first
var settings = Settings.mozSettings;
var lock = settings.createLock();
function showStkEntries(menu) {
DUMP('STK cached menu: ', menu);
if (!menu || typeof menu !== 'object' || Object.keys(menu).length == 0) {
DUMP('No STK available - exit');
iccMainHeader.hidden = true;
iccEntries.hidden = true;
return;
}
// Clean current entries
iccEntries.innerHTML = '';
iccMainHeader.hidden = true;
iccEntries.hidden = true;
// update and show the entry in settings
Object.keys(menu).forEach(function(SIMNumber) {
DUMP('STK Menu for SIM ' + SIMNumber +
' (' + menu[SIMNumber].iccId + ') - ', menu[SIMNumber].entries);
var li = document.createElement('li');
var small = document.createElement('small');
// XXX this line requires a better l10n support, see bug 968853
small.textContent = 'SIM ' + SIMNumber;
small.classList.add('menu-item-desc');
li.appendChild(small);
var a = document.createElement('a');
a.textContent = menu[SIMNumber].entries.title;
a.id = 'menuItem-icc-' + menu[SIMNumber].iccId;
a.classList.add('menu-item');
a.classList.add('menuItem-icc');
a.href = '#icc';
a. menu_icc_onclick() {
DUMP('Touched ' + menu[SIMNumber].iccId);
loadIccPage(function() {
var event = new CustomEvent('stkmenuselection', {
detail: { 'menu': menu[SIMNumber] }
});
window.dispatchEvent(event);
});
};
li.appendChild(a);
iccEntries.appendChild(li);
iccMainHeader.hidden = false;
iccEntries.hidden = false;
});
}
// Check if SIM card sends an Applications menu
var reqApplications = lock.get('icc.applications');
reqApplications. icc_getApplications() {
var json = reqApplications.result['icc.applications'];
var menu = json && JSON.parse(json);
showStkEntries(menu);
};
settings.addObserver('icc.applications',
function icc_getApplications(event) {
var json = event.settingValue;
var menu = json && JSON.parse(json);
showStkEntries(menu);
});
// Check if there are pending STK commands
var reqIccData = lock.get('icc.data');
reqIccData. icc_getIccData() {
var cmd = reqIccData.result['icc.data'];
if (cmd) {
DUMP('ICC async command (launcher)');
executeIccCmd(JSON.parse(cmd));
}
};
settings.addObserver('icc.data', function(event) {
var value = event.settingValue;
if (value) {
DUMP('ICC async command while settings running: ', value);
executeIccCmd(JSON.parse(value));
}
});
});
})();