diff --git a/browser/components/loop/MozLoopAPI.jsm b/browser/components/loop/MozLoopAPI.jsm index b350e1c8ed72..06698671de8d 100644 --- a/browser/components/loop/MozLoopAPI.jsm +++ b/browser/components/loop/MozLoopAPI.jsm @@ -365,21 +365,31 @@ function injectLoopAPI(targetWindow) { /** * Displays a confirmation dialog using the specified strings. * - * Callback parameters: - * - err null on success, non-null on unexpected failure to show the prompt. - * - {Boolean} True if the user chose the OK button. + * @param {Object} options Confirm dialog options + * @param {Function} callback Function that will be invoked once the operation + * finished. The first argument passed will be an + * `Error` object or `null`. The second argument + * will be the result of the operation, TRUE if + * the user chose the OK button. */ confirm: { enumerable: true, writable: true, - value: function(bodyMessage, okButtonMessage, cancelButtonMessage, callback) { - try { - let buttonFlags = + value: function(options, callback) { + let buttonFlags; + if (options.okButton && options.cancelButton) { + buttonFlags = (Ci.nsIPrompt.BUTTON_POS_0 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING) + (Ci.nsIPrompt.BUTTON_POS_1 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING); + } else if (!options.okButton && !options.cancelButton) { + buttonFlags = Services.prompt.STD_YES_NO_BUTTONS; + } else { + callback(cloneValueInto(new Error("confirm: missing button options"), targetWindow)); + } + try { let chosenButton = Services.prompt.confirmEx(null, "", - bodyMessage, buttonFlags, okButtonMessage, cancelButtonMessage, + options.message, buttonFlags, options.okButton, options.cancelButton, null, null, {}); callback(null, chosenButton == 0); diff --git a/browser/components/loop/content/js/contacts.js b/browser/components/loop/content/js/contacts.js index 0c8989e2a4db..db4f2dafdd2a 100644 --- a/browser/components/loop/content/js/contacts.js +++ b/browser/components/loop/content/js/contacts.js @@ -403,25 +403,25 @@ loop.contacts = (function(_, mozL10n) { this.props.startForm("contacts_edit", contact); break; case "remove": - navigator.mozLoop.confirm( - mozL10n.get("confirm_delete_contact_alert"), - mozL10n.get("confirm_delete_contact_remove_button"), - mozL10n.get("confirm_delete_contact_cancel_button"), - (err, result) => { + navigator.mozLoop.confirm({ + message: mozL10n.get("confirm_delete_contact_alert"), + okButton: mozL10n.get("confirm_delete_contact_remove_button"), + cancelButton: mozL10n.get("confirm_delete_contact_cancel_button") + }, (err, result) => { + if (err) { + throw err; + } + + if (!result) { + return; + } + + navigator.mozLoop.contacts.remove(contact._guid, err => { if (err) { throw err; } - - if (!result) { - return; - } - - navigator.mozLoop.contacts.remove(contact._guid, err => { - if (err) { - throw err; - } - }); }); + }); break; case "block": case "unblock": diff --git a/browser/components/loop/content/js/contacts.jsx b/browser/components/loop/content/js/contacts.jsx index 7ccecf107d8b..ed9a2b2e5855 100644 --- a/browser/components/loop/content/js/contacts.jsx +++ b/browser/components/loop/content/js/contacts.jsx @@ -403,25 +403,25 @@ loop.contacts = (function(_, mozL10n) { this.props.startForm("contacts_edit", contact); break; case "remove": - navigator.mozLoop.confirm( - mozL10n.get("confirm_delete_contact_alert"), - mozL10n.get("confirm_delete_contact_remove_button"), - mozL10n.get("confirm_delete_contact_cancel_button"), - (err, result) => { + navigator.mozLoop.confirm({ + message: mozL10n.get("confirm_delete_contact_alert"), + okButton: mozL10n.get("confirm_delete_contact_remove_button"), + cancelButton: mozL10n.get("confirm_delete_contact_cancel_button") + }, (err, result) => { + if (err) { + throw err; + } + + if (!result) { + return; + } + + navigator.mozLoop.contacts.remove(contact._guid, err => { if (err) { throw err; } - - if (!result) { - return; - } - - navigator.mozLoop.contacts.remove(contact._guid, err => { - if (err) { - throw err; - } - }); }); + }); break; case "block": case "unblock": diff --git a/browser/components/loop/content/js/panel.js b/browser/components/loop/content/js/panel.js index 61e135eaf2df..760ec4db8ce6 100644 --- a/browser/components/loop/content/js/panel.js +++ b/browser/components/loop/content/js/panel.js @@ -617,10 +617,23 @@ loop.panel = (function(_, mozL10n) { handleDeleteButtonClick: function(event) { event.stopPropagation(); event.preventDefault(); - // XXX We should prompt end user for confirmation; see bug 1092953. - this.props.dispatcher.dispatch(new sharedActions.DeleteRoom({ - roomToken: this.props.room.roomToken - })); + navigator.mozLoop.confirm({ + message: mozL10n.get("rooms_list_deleteConfirmation_label"), + okButton: null, + cancelButton: null + }, function(err, result) { + if (err) { + throw err; + } + + if (!result) { + return; + } + + this.props.dispatcher.dispatch(new sharedActions.DeleteRoom({ + roomToken: this.props.room.roomToken + })); + }.bind(this)); }, renameRoom: function(newRoomName) { diff --git a/browser/components/loop/content/js/panel.jsx b/browser/components/loop/content/js/panel.jsx index edce0487913b..76c084b71f87 100644 --- a/browser/components/loop/content/js/panel.jsx +++ b/browser/components/loop/content/js/panel.jsx @@ -617,10 +617,23 @@ loop.panel = (function(_, mozL10n) { handleDeleteButtonClick: function(event) { event.stopPropagation(); event.preventDefault(); - // XXX We should prompt end user for confirmation; see bug 1092953. - this.props.dispatcher.dispatch(new sharedActions.DeleteRoom({ - roomToken: this.props.room.roomToken - })); + navigator.mozLoop.confirm({ + message: mozL10n.get("rooms_list_deleteConfirmation_label"), + okButton: null, + cancelButton: null + }, function(err, result) { + if (err) { + throw err; + } + + if (!result) { + return; + } + + this.props.dispatcher.dispatch(new sharedActions.DeleteRoom({ + roomToken: this.props.room.roomToken + })); + }.bind(this)); }, renameRoom: function(newRoomName) {