Skip to content
Browse files

Bug 813458 - FTE fixed. As the service is not launched on start-up, s…

…ome deep modifications have been made.
  • Loading branch information...
1 parent 09a7583 commit 4f6fd340a41e09096ade359c3a073d27ce345111 @delapuente delapuente committed Nov 20, 2012
View
2 apps/costcontrol/index.html
@@ -233,7 +233,7 @@ <h1 data-l10n-id="data-usage">Data usage</h1>
</section>
<!-- Settings view -->
- <iframe id="settings-view" src="settings.html" class="view" data-viewport="bottom"></iframe>
+ <iframe id="settings-view" class="view" data-viewport="bottom"></iframe>
<!-- FTE view -->
<iframe id="fte-view" class="view" data-viewport="bottom"></iframe>
View
14 apps/costcontrol/js/app.js
@@ -100,7 +100,6 @@ function setupApp() {
// Initializes the cost control module: basic parameters, automatic and manual
// updates.
- var _initialized = false;
function _init() {
var status = Service.getServiceStatus();
if (status.fte) {
@@ -117,9 +116,16 @@ function setupApp() {
for (var viewId in Views)
Views[viewId].init();
+ var settingsIframe = document.getElementById('settings-view');
+ settingsIframe.src = 'settings.html';
+
// Handle web activity
navigator.mozSetMessageHandler('activity',
function settings_handleActivity(activityRequest) {
+ var status = Service.getServiceStatus();
+ if (status.fte)
+ return;
+
var name = activityRequest.source.name;
settingsVManager.closeCurrentView();
switch (name) {
@@ -152,17 +158,13 @@ function setupApp() {
viewManager.changeViewTo(TAB_DATA_USAGE);
dataUsageTab.classList.add('standalone');
}
-
- _initialized = true;
}
// Update UI when localized
window.addEventListener('localized', function ccapp_onLocalized() {
- if (!_initialized)
- _init();
-
for (var viewid in Views) if (Views.hasOwnProperty(viewid))
Views[viewid].localize();
});
+ _init();
}
View
140 apps/costcontrol/js/service/cost_control_service.js
@@ -73,8 +73,8 @@ setService(function cc_setupCostControlService() {
datausage: false
};
- // App settings object to control settings
- var _appSettings = (function cc_appSettings() {
+ // Class to create cached local options by SIM iccid
+ function AppSettings(iccid, options) {
// Application settings
var _cachedOptions = {
@@ -119,27 +119,6 @@ setService(function cc_setupCostControlService() {
var _listeners = {};
- function _initializeSettings(options) {
- // No options, first time experience
- if (!options) {
- // It is implicit but let's make it explicit
- _cachedOptions['fte'] = true;
- debug('First Time Experience for this SIM');
- return;
- }
-
- var event, value, defaultValue;
- for (var option in _cachedOptions) {
- defaultValue = _cachedOptions[option];
- value = options[option];
- if (typeof value !== 'undefined')
- _cachedOptions[option] = value;
-
- event = _newLocalSettingsChangeEvent(option, value, defaultValue);
- window.dispatchEvent(event);
- }
- }
-
function _newLocalSettingsChangeEvent(key, value, oldValue) {
return new CustomEvent('localsettingschanged', {
detail: { key: key, value: value, oldValue: oldValue }
@@ -180,7 +159,7 @@ setService(function cc_setupCostControlService() {
debug('Setting ' + key + ' to ' + value + ' (' + typeof value + ')');
_cachedOptions[key] = value; // update cache
- asyncStorage.setItem(_iccid, _cachedOptions,
+ asyncStorage.setItem(iccid, _cachedOptions,
function dispatchSettingsChange() {
var event = _newLocalSettingsChangeEvent(key, value, oldValue);
window.dispatchEvent(event);
@@ -200,28 +179,32 @@ setService(function cc_setupCostControlService() {
window.dispatchEvent(event);
}
- var _iccid;
+ // No options, first time experience
+ if (!options) {
+ // It is implicit but let's make it explicit
+ _cachedOptions['fte'] = true;
+ debug('First Time Experience for this SIM');
+
+ } else {
+
+ var event, value, defaultValue;
+ for (var option in _cachedOptions) {
+ defaultValue = _defaults[option];
+ value = options[option];
+ if (typeof value !== 'undefined')
+ _cachedOptions[option] = value;
- // Recover application settings from DB using the ICCID as key
- function _init() {
- _iccid = _conn.iccInfo.iccid;
- if (!_iccid) {
- console.warn('No ICCID available, using NOICCID as ICCID instead');
- _iccid = 'NOICCID';
+ event = _newLocalSettingsChangeEvent(option, value, defaultValue);
+ window.dispatchEvent(event);
}
- debug('Loading options for SIM: ' + _iccid);
- asyncStorage.getItem(_iccid, _initializeSettings);
- }
- _init();
+ }
- return {
- observe: _observe,
- option: _option,
- defaultValue: _defaultValue,
- touch: _touch
- };
- }());
+ this.observe = _observe;
+ this.option = _option;
+ this.defaultValue = _defaultValue;
+ this.touch = _touch;
+ }
// Inner class: Balance.
// Balance keeps an amount, a timestamp and a currency accesible by
@@ -311,6 +294,21 @@ setService(function cc_setupCostControlService() {
};
}
+ // Load local by SIM application settings, then continue with afterCallback
+ var _appSettings, _iccid;
+ function _loadAppSettings(afterCallback) {
+ _iccid = _conn.iccInfo.iccid;
+ if (!_iccid) {
+ console.warn('No ICCID available, using NOICCID as ICCID instead');
+ _iccid = 'NOICCID';
+ }
+ debug('Loading options for SIM: ' + _iccid);
+ asyncStorage.getItem(_iccid, function(options) {
+ _appSettings = new AppSettings(_iccid, options);
+ afterCallback();
+ });
+ }
+
// Attach event listeners for automatic updates on balance:
// * Periodically
function _configureBalance() {
@@ -512,39 +510,47 @@ setService(function cc_setupCostControlService() {
// Initializes the cost control module:
// critical parameters, automatic updates and state-dependant settings
function _init() {
+ // XXX: Synchronizing two async methods:
+ // 1- Load OEM configuration
+ // 2- Load application `by SIM` settings
+ // 3- Setup the service
+ // Hail CPS! (Continuation-Passing Style)
_loadConfiguration(function cc_afterConfiguration() {
- _configureAutoreset();
+ _loadAppSettings(function cc_afterAppSettings() {
- _configureDataUsage();
- console.info('Cost Control: data usage enabled.');
+ _configureAutoreset();
- if (_checkEnableConditions()) {
- _configureBalance();
- _configureTelephony();
- console.info('Cost Control: valid SIM card for balance and telephony.');
- } else {
- console.warn(
- 'Cost Control: non valid SIM card for balance nor telephony.');
- }
+ _configureDataUsage();
+ console.info('Cost Control: data usage enabled.');
- // State dependant settings allow simultaneous updates and
- // topping up tasks
- _state[STATE_UPDATING_BALANCE] = false;
- _state[STATE_TOPPING_UP] = false;
- _state[STATE_UPDATING_DATA_USAGE] = false;
- _smsTimeout[STATE_UPDATING_BALANCE] = 0;
- _smsTimeout[STATE_TOPPING_UP] = 0;
- _onSMSReceived[STATE_UPDATING_BALANCE] = _onBalanceSMSReceived;
- _onSMSReceived[STATE_TOPPING_UP] = _onConfirmationSMSReceived;
+ if (_checkEnableConditions()) {
+ _configureBalance();
+ _configureTelephony();
+ console.info('Cost Control: valid SIM card for ' +
+ 'balance and telephony.');
+ } else {
+ console.warn(
+ 'Cost Control: non valid SIM card for balance nor telephony.');
+ }
- // If data or voice change
- _conn.onvoicechange = _dispatchServiceStatusChangeEvent;
- _conn.ondatachange = _dispatchServiceStatusChangeEvent;
+ // State dependant settings allow simultaneous updates and
+ // topping up tasks
+ _state[STATE_UPDATING_BALANCE] = false;
+ _state[STATE_TOPPING_UP] = false;
+ _state[STATE_UPDATING_DATA_USAGE] = false;
+ _smsTimeout[STATE_UPDATING_BALANCE] = 0;
+ _smsTimeout[STATE_TOPPING_UP] = 0;
+ _onSMSReceived[STATE_UPDATING_BALANCE] = _onBalanceSMSReceived;
+ _onSMSReceived[STATE_TOPPING_UP] = _onConfirmationSMSReceived;
- // See service_utils.js for information
- nowIAmReady();
+ // If data or voice change
+ _conn.onvoicechange = _dispatchServiceStatusChangeEvent;
+ _conn.ondatachange = _dispatchServiceStatusChangeEvent;
+ // See service_utils.js for information
+ nowIAmReady();
+ });
});
}
View
33 apps/costcontrol/js/widget.js
@@ -140,6 +140,22 @@ function setupWidget() {
}
+ // Full mode for data usage when only data is available
+ function _adaptLayout(evt) {
+
+ _widget.classList.remove('full');
+ _leftPanel.setAttribute('aria-hidden', 'false');
+
+ var status = evt.detail;
+ if (!status.enabledFunctionalities.balance &&
+ !status.enabledFunctionalities.telephony) {
+
+ _widget.classList.add('full');
+ _leftPanel.setAttribute('aria-hidden', 'true');
+ }
+ };
+
+
// Attach event listeners for manual updates
function _configureWidget() {
@@ -170,21 +186,8 @@ function setupWidget() {
_updateUI();
});
- // Full mode for data usage when only data is available
- Service.onservicestatuschange = function ccwidget_adaptLayout(evt) {
-
- _widget.classList.remove('full');
- _leftPanel.setAttribute('aria-hidden', 'false');
-
- var status = evt.detail;
- if (!status.enabledFunctionalities.balance &&
- !status.enabledFunctionalities.telephony) {
-
- _widget.classList.add('full');
- _leftPanel.setAttribute('aria-hidden', 'true');
- }
- };
-
+ Service.onservicestatuschange = _adaptLayout;
+ _adaptLayout({ detail: Service.getServiceStatus() });
_updateUI();
}

0 comments on commit 4f6fd34

Please sign in to comment.
Something went wrong with that request. Please try again.