Skip to content

Commit

Permalink
Merge pull request mozilla-b2g#33379 from gasolin/issue-1228252
Browse files Browse the repository at this point in the history
Bug 1228252 - move openDialog from util.js to panel_utils, r=yzen
  • Loading branch information
gasolin committed Nov 27, 2015
2 parents ffd62f1 + aa35773 commit e6d4fb1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
40 changes: 39 additions & 1 deletion apps/settings/js/modules/panel_utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global openLink, openDialog */
/* global openLink */
/**
* PanelUtils is a singleton that defines panel related utility functions.
*
Expand All @@ -13,6 +13,44 @@ define(function(require) {

var _settings = navigator.mozSettings;

/**
* These so-called "dialog boxes" are just standard Settings panels
* (<section role="region" />) with reset/submit buttons: these buttons both
* return to the previous panel when clicked, and each button has its own
* (optional) callback.
*/
function openDialog(dialogID, onSubmit, onReset) {
if ('#' + dialogID === Settings.currentPanel) {
return;
}

var origin = Settings.currentPanel;

// Load dialog contents and show it.
Settings.currentPanel = dialogID;

var dialog = document.getElementById(dialogID);
var submit = dialog.querySelector('[type=submit]');
if (submit) {
submit.onclick = function onsubmit() {
if (typeof onSubmit === 'function') {
(onSubmit.bind(dialog))();
}
Settings.currentPanel = origin; // hide dialog box
};
}

var reset = dialog.querySelector('[type=reset]');
if (reset) {
reset.onclick = function onreset() {
if (typeof onReset === 'function') {
(onReset.bind(dialog))();
}
Settings.currentPanel = origin; // hide dialog box
};
}
}

/**
* Opens the dialog of a specified id.
*
Expand Down
40 changes: 1 addition & 39 deletions apps/settings/js/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global MozActivity, LazyLoader, DsdsSettings, SupportedNetworkTypeHelper */
/* exported reopenSettings, openLink, openDialog,
/* exported reopenSettings, openLink,
openIncompatibleSettingsDialog, DeviceStorageHelper,
sanitizeAddress, getIccByIndex */
'use strict';
Expand Down Expand Up @@ -34,44 +34,6 @@ function openLink(url) {
}
}

/**
* These so-called "dialog boxes" are just standard Settings panels (<section
* role="region" />) with reset/submit buttons: these buttons both return to the
* previous panel when clicked, and each button has its own (optional) callback.
*/

function openDialog(dialogID, onSubmit, onReset) {
if ('#' + dialogID === Settings.currentPanel) {
return;
}

var origin = Settings.currentPanel;

// Load dialog contents and show it.
Settings.currentPanel = dialogID;

var dialog = document.getElementById(dialogID);
var submit = dialog.querySelector('[type=submit]');
if (submit) {
submit.onclick = function onsubmit() {
if (typeof onSubmit === 'function') {
(onSubmit.bind(dialog))();
}
Settings.currentPanel = origin; // hide dialog box
};
}

var reset = dialog.querySelector('[type=reset]');
if (reset) {
reset.onclick = function onreset() {
if (typeof onReset === 'function') {
(onReset.bind(dialog))();
}
Settings.currentPanel = origin; // hide dialog box
};
}
}

function openIncompatibleSettingsDialog(dialogId, newSetting,
oldSetting, callback) {
var headerL10nMap = {
Expand Down
1 change: 0 additions & 1 deletion apps/settings/test/unit/mock_settings_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ define(function() {
'use strict';

var MockSettingsUtils = {
openDialog: function(dialogID, userOptions) {},
loadTemplate: function(templatePanelId, callback) {
callback();
}
Expand Down

0 comments on commit e6d4fb1

Please sign in to comment.