Created
March 10, 2014 12:38
-
-
Save rik/9464270 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apps/communications/dialer/index.html | 3 + | |
apps/communications/dialer/js/call_button.js | 10 ++- | |
apps/communications/dialer/js/index.js | 3 +- | |
.../dialer/locales/sim.en-US.properties | 6 +- | |
apps/communications/dialer/style/sim.css | 5 ++ | |
.../communications/dialer/test/unit/keypad_test.js | 7 +- | |
.../dialer/test/unit/mock_call_button.js | 1 - | |
shared/js/sim_picker.js | 82 ++++++++++++++-------- | |
8 files changed, 79 insertions(+), 38 deletions(-) | |
diff --git a/apps/communications/dialer/index.html b/apps/communications/dialer/index.html | |
index 16d4860..e413faf 100644 | |
--- a/apps/communications/dialer/index.html | |
+++ b/apps/communications/dialer/index.html | |
@@ -71,6 +71,7 @@ | |
<link rel="import" href="elements/edit-mode.html"> | |
<link rel="import" href="elements/add-contact-action-menu.html"> | |
+ <link rel="import" href="elements/sim-picker.html"> | |
<link rel="import" href="elements/confirmation-message.html"> | |
</head> | |
<body role="application"> | |
@@ -211,6 +212,8 @@ | |
<form is="add-contact-action-menu" id="add-contact-action-menu" role="dialog" data-type="action" hidden></form> | |
+ <form is="sim-picker" id="sim-picker" role="dialog" data-type="action" hidden></form> | |
+ | |
<form is="confirmation-message" id="confirmation-message" class="hide no-opacity" role="dialog" data-type="confirm"></form> | |
<form id="suggestion-overlay" role="dialog" data-type="action" class="overlay" hidden> | |
diff --git a/apps/communications/dialer/js/call_button.js b/apps/communications/dialer/js/call_button.js | |
index 3b25a63..c36f365 100644 | |
--- a/apps/communications/dialer/js/call_button.js | |
+++ b/apps/communications/dialer/js/call_button.js | |
@@ -7,9 +7,17 @@ var CallButton = { | |
_phoneNumberGetter: null, | |
_imports: ['/shared/js/option_menu.js', | |
'/shared/js/sim_picker.js', | |
- '/shared/js/sim_settings_helper.js'], | |
+ '/shared/js/sim_settings_helper.js', | |
+ // document.getElementById('sim-picker') | |
+ ], | |
init: function cb_init(button, phoneNumberGetter) { | |
+ // window.navigator.mozMobileConnections = [1, 2]; | |
+ // LazyLoader.load(this._imports, function() { | |
+ // SimPicker.show(1, '12345', function(cardIndex) { | |
+ // console.log('WESH', cardIndex); | |
+ // }); | |
+ // }); | |
this._phoneNumberGetter = phoneNumberGetter; | |
button.addEventListener('click', this._click.bind(this)); | |
diff --git a/apps/communications/dialer/js/index.js b/apps/communications/dialer/js/index.js | |
index 0a322bc..cf8683f 100644 | |
--- a/apps/communications/dialer/js/index.js | |
+++ b/apps/communications/dialer/js/index.js | |
@@ -9,7 +9,8 @@ window.addEventListener('load', function dialerSetup() { | |
setTimeout(function nextTick() { | |
var lazyPanels = ['add-contact-action-menu', | |
'confirmation-message', | |
- 'edit-mode']; | |
+ 'edit-mode', | |
+ 'sim-picker']; | |
var lazyPanelsElements = lazyPanels.map(function toElement(id) { | |
return document.getElementById(id); | |
diff --git a/apps/communications/dialer/locales/sim.en-US.properties b/apps/communications/dialer/locales/sim.en-US.properties | |
index 7da076f..37e8b82 100644 | |
--- a/apps/communications/dialer/locales/sim.en-US.properties | |
+++ b/apps/communications/dialer/locales/sim.en-US.properties | |
@@ -1,4 +1,4 @@ | |
# SIM list | |
-select-sim-dial-via=Dial {{ phoneNumber }} via | |
-select-sim-menu-button=SIM {{ n }} | |
-select-sim-menu-button-default=(default) | |
+sim-picker-dial-via=Dial {{ phoneNumber }} via | |
+sim-picker-button=SIM {{ n }} | |
+sim-picker-button-default=(default) | |
diff --git a/apps/communications/dialer/style/sim.css b/apps/communications/dialer/style/sim.css | |
index a2cfdca..f20c69d 100644 | |
--- a/apps/communications/dialer/style/sim.css | |
+++ b/apps/communications/dialer/style/sim.css | |
@@ -3,7 +3,12 @@ | |
} | |
.sim-default { | |
+ display: none; | |
margin-left: 5px; | |
font-size: 1.4rem; | |
font-style: italic; | |
} | |
+ | |
+.is-default .sim-default { | |
+ display: initial; | |
+} | |
diff --git a/apps/communications/dialer/test/unit/keypad_test.js b/apps/communications/dialer/test/unit/keypad_test.js | |
index fd79084..434d50f 100644 | |
--- a/apps/communications/dialer/test/unit/keypad_test.js | |
+++ b/apps/communications/dialer/test/unit/keypad_test.js | |
@@ -1,7 +1,7 @@ | |
-/* globals CallHandler, CallLogDBManager, gTonesFrequencies, KeypadManager, | |
+/* globals CallButton, CallLogDBManager, gTonesFrequencies, KeypadManager, | |
MockCall, MockCallsHandler, MockDialerIndexHtml, MockMozTelephony, | |
- MockSettingsListener, MocksHelper, MockTonePlayer, | |
- telephonyAddCall */ | |
+ MockSettingsListener, MocksHelper, MockTonePlayer, telephonyAddCall | |
+*/ | |
'use strict'; | |
@@ -25,7 +25,6 @@ var mocksHelperForKeypad = new MocksHelper([ | |
'LazyLoader', | |
'Utils', | |
'CallButton', | |
- 'CallHandler', | |
'CallsHandler', | |
'CallLogDBManager', | |
'HandledCall', | |
diff --git a/apps/communications/dialer/test/unit/mock_call_button.js b/apps/communications/dialer/test/unit/mock_call_button.js | |
index 87d174d..d3d3406 100644 | |
--- a/apps/communications/dialer/test/unit/mock_call_button.js | |
+++ b/apps/communications/dialer/test/unit/mock_call_button.js | |
@@ -1,4 +1,3 @@ | |
-/* globals CallHandler, KeypadManager */ | |
/* exported MockCallButton */ | |
'use strict'; | |
diff --git a/shared/js/sim_picker.js b/shared/js/sim_picker.js | |
index b249757..e772208 100644 | |
--- a/shared/js/sim_picker.js | |
+++ b/shared/js/sim_picker.js | |
@@ -1,50 +1,76 @@ | |
-/* global OptionMenu */ | |
+/* global LazyL10n */ | |
/* exported SimPicker */ | |
'use strict'; | |
(function(exports) { | |
- | |
/* | |
* SimPicker is a helper to dynamically generate menus for selecting SIM | |
* cards when making calls, sending SMS, etc. | |
*/ | |
var SimPicker = { | |
+ _domBuilt: false, | |
+ _simPickerElt: null, | |
+ | |
show: function hk_show(defaultCardIndex, phoneNumber, simSelectedCallback) { | |
- var params = { | |
- headerL10nId: 'select-sim-dial-via', | |
- headerL10nArgs: {phoneNumber: phoneNumber}, | |
- classes: ['select-sim-menu'], | |
- items: [] | |
- }; | |
- | |
- for (var i = 0; i < window.navigator.mozMobileConnections.length; i++) { | |
- var appendElem = null; | |
- if (i === defaultCardIndex) { | |
- appendElem = document.createElement('span'); | |
- appendElem.classList.add('sim-default'); | |
- appendElem.textContent = | |
- navigator.mozL10n.localize(appendElem, | |
- 'select-sim-menu-button-default'); | |
+ this._simSelectedCallback = simSelectedCallback; | |
+ this._simPickerElt = document.getElementById('sim-picker'); | |
+ | |
+ this._buildDom(); | |
+ var self = this; | |
+ LazyL10n.get(function() { | |
+ navigator.mozL10n.localize(document.getElementById( | |
+ 'sim-picker-dial-via'), | |
+ 'sim-picker-dial-via', {phoneNumber: phoneNumber}); | |
+ var simButtons = self._simPickerElt.querySelectorAll( | |
+ 'button[data-card-index]'); | |
+ for (var i = 0; i < simButtons.length; i++) { | |
+ if (simButtons[i].dataset.cardIndex == defaultCardIndex) { | |
+ simButtons[i].classList.add('is-default'); | |
+ } | |
} | |
- params.items.push({ | |
- l10nId: 'select-sim-menu-button', | |
- l10nArgs: {n: i+1}, | |
- method: simSelectedCallback, | |
- append: appendElem, | |
- params: [i] | |
- }); | |
+ self._simPickerElt.hidden = false; | |
+ }); | |
+ }, | |
+ | |
+ _buildDom: function() { | |
+ if (this._domBuilt) { | |
+ return; | |
} | |
- params.items.push({ | |
- l10nId: 'cancel', | |
- incomplete: true | |
+ | |
+ this._domBuilt = true; | |
+ var self = this; | |
+ LazyL10n.get(function() { | |
+ var templateNode = document.getElementById( | |
+ 'sim-picker-button-template'); | |
+ for (var i = 0; i < window.navigator.mozMobileConnections.length; i++) { | |
+ var clonedNode = templateNode.cloneNode(true); | |
+ clonedNode.dataset.cardIndex = i; | |
+ navigator.mozL10n.localize(clonedNode.querySelector('span'), | |
+ 'sim-picker-button', {n: i + 1}); | |
+ templateNode.parentNode.insertBefore(clonedNode, templateNode); | |
+ } | |
+ templateNode.remove(); | |
+ | |
+ var simPickerElt = document.getElementById('sim-picker'); | |
+ simPickerElt.addEventListener('click', self); | |
}); | |
+ }, | |
+ | |
+ handleEvent: function(e) { | |
+ if (e.target.nodeName !== 'BUTTON') { | |
+ return; | |
+ } | |
- new OptionMenu(params).show(); | |
+ if (e.target.dataset.cardIndex) { | |
+ this._simSelectedCallback(e.target.dataset.cardIndex); | |
+ } | |
+ document.getElementById('sim-picker').hidden = true; | |
} | |
}; | |
+ | |
exports.SimPicker = SimPicker; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment