Bug 1092953: show a modal confirm dialog when a user attempts to delete a room. r=paolo

This commit is contained in:
Mike de Boer 2014-11-28 11:45:17 +01:00
parent dee3c94d20
commit c20ee339fb
5 changed files with 81 additions and 45 deletions

View File

@ -365,21 +365,31 @@ function injectLoopAPI(targetWindow) {
/** /**
* Displays a confirmation dialog using the specified strings. * Displays a confirmation dialog using the specified strings.
* *
* Callback parameters: * @param {Object} options Confirm dialog options
* - err null on success, non-null on unexpected failure to show the prompt. * @param {Function} callback Function that will be invoked once the operation
* - {Boolean} True if the user chose the OK button. * 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: { confirm: {
enumerable: true, enumerable: true,
writable: true, writable: true,
value: function(bodyMessage, okButtonMessage, cancelButtonMessage, callback) { value: function(options, callback) {
try { let buttonFlags;
let buttonFlags = if (options.okButton && options.cancelButton) {
buttonFlags =
(Ci.nsIPrompt.BUTTON_POS_0 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING) + (Ci.nsIPrompt.BUTTON_POS_0 * Ci.nsIPrompt.BUTTON_TITLE_IS_STRING) +
(Ci.nsIPrompt.BUTTON_POS_1 * 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, "", let chosenButton = Services.prompt.confirmEx(null, "",
bodyMessage, buttonFlags, okButtonMessage, cancelButtonMessage, options.message, buttonFlags, options.okButton, options.cancelButton,
null, null, {}); null, null, {});
callback(null, chosenButton == 0); callback(null, chosenButton == 0);

View File

@ -403,25 +403,25 @@ loop.contacts = (function(_, mozL10n) {
this.props.startForm("contacts_edit", contact); this.props.startForm("contacts_edit", contact);
break; break;
case "remove": case "remove":
navigator.mozLoop.confirm( navigator.mozLoop.confirm({
mozL10n.get("confirm_delete_contact_alert"), message: mozL10n.get("confirm_delete_contact_alert"),
mozL10n.get("confirm_delete_contact_remove_button"), okButton: mozL10n.get("confirm_delete_contact_remove_button"),
mozL10n.get("confirm_delete_contact_cancel_button"), cancelButton: mozL10n.get("confirm_delete_contact_cancel_button")
(err, result) => { }, (err, result) => {
if (err) {
throw err;
}
if (!result) {
return;
}
navigator.mozLoop.contacts.remove(contact._guid, err => {
if (err) { if (err) {
throw err; throw err;
} }
if (!result) {
return;
}
navigator.mozLoop.contacts.remove(contact._guid, err => {
if (err) {
throw err;
}
});
}); });
});
break; break;
case "block": case "block":
case "unblock": case "unblock":

View File

@ -403,25 +403,25 @@ loop.contacts = (function(_, mozL10n) {
this.props.startForm("contacts_edit", contact); this.props.startForm("contacts_edit", contact);
break; break;
case "remove": case "remove":
navigator.mozLoop.confirm( navigator.mozLoop.confirm({
mozL10n.get("confirm_delete_contact_alert"), message: mozL10n.get("confirm_delete_contact_alert"),
mozL10n.get("confirm_delete_contact_remove_button"), okButton: mozL10n.get("confirm_delete_contact_remove_button"),
mozL10n.get("confirm_delete_contact_cancel_button"), cancelButton: mozL10n.get("confirm_delete_contact_cancel_button")
(err, result) => { }, (err, result) => {
if (err) {
throw err;
}
if (!result) {
return;
}
navigator.mozLoop.contacts.remove(contact._guid, err => {
if (err) { if (err) {
throw err; throw err;
} }
if (!result) {
return;
}
navigator.mozLoop.contacts.remove(contact._guid, err => {
if (err) {
throw err;
}
});
}); });
});
break; break;
case "block": case "block":
case "unblock": case "unblock":

View File

@ -617,10 +617,23 @@ loop.panel = (function(_, mozL10n) {
handleDeleteButtonClick: function(event) { handleDeleteButtonClick: function(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// XXX We should prompt end user for confirmation; see bug 1092953. navigator.mozLoop.confirm({
this.props.dispatcher.dispatch(new sharedActions.DeleteRoom({ message: mozL10n.get("rooms_list_deleteConfirmation_label"),
roomToken: this.props.room.roomToken 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) { renameRoom: function(newRoomName) {

View File

@ -617,10 +617,23 @@ loop.panel = (function(_, mozL10n) {
handleDeleteButtonClick: function(event) { handleDeleteButtonClick: function(event) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
// XXX We should prompt end user for confirmation; see bug 1092953. navigator.mozLoop.confirm({
this.props.dispatcher.dispatch(new sharedActions.DeleteRoom({ message: mozL10n.get("rooms_list_deleteConfirmation_label"),
roomToken: this.props.room.roomToken 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) { renameRoom: function(newRoomName) {