Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #6557 from gtorodelvalle/dialer-bug-811283-unify-d…
Browse files Browse the repository at this point in the history
…ialog-messages-using-onclick

Bug 811283 - [BB] [Dialer] Unify the mechanism to show information messages (confirm dialogs) to the user (using onclick).
  • Loading branch information
gtorodelvalle committed Nov 21, 2012
2 parents 4714fca + aee0160 commit 3a6fc76
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions apps/communications/contacts/js/confirm_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ var ConfirmDialog = (function() {
var titleNode = screen.querySelector('h1');
var messageNode = screen.querySelector('p');
var action1Node = screen.querySelector('button:nth-of-type(1)');
var action1Callback;
var action2Node = screen.querySelector('button:nth-of-type(2)');
var action2Callback;

var callBackAndPreventDefault = function(ev) {
if (ev.target === action1Node) {
action1Callback();
ev.preventDefault();
return false;
} else if (ev.target === action2Node) {
action2Callback();
ev.preventDefault();
return false;
}
}

return {
hide: function dialog_hide() {
Expand All @@ -20,10 +34,10 @@ var ConfirmDialog = (function() {
messageNode.className = '';
action1Node.textContent = '';
action1Node.className = '';
action1Node.removeEventListener('click', action1Node.callback);
action1Node.onclick = null;
action2Node.textContent = '';
action2Node.className = '';
action2Node.removeEventListener('click', action2Node.callback);
action2Node.onclick = null;
screen.classList.add('hide');
},

Expand Down Expand Up @@ -54,9 +68,8 @@ var ConfirmDialog = (function() {
action1Node.classList.add('danger');
}
if (action1.callback) {
action1Node.addEventListener('click', action1.callback);
// To remove the listener on hide.
action1Node.callback = action1.callback;
action1Callback = action1.callback;
action1Node.onclick = callBackAndPreventDefault;
}
if (!action2) {
action2Node.classList.add('hide');
Expand All @@ -71,9 +84,8 @@ var ConfirmDialog = (function() {
action2Node.classList.add('danger');
}
if (action2.callback) {
action2Node.addEventListener('click', action2.callback);
// To remove the listener on hide.
action2Node.callback = action2.callback;
action2Callback = action2.callback;
action2Node.onclick = callBackAndPreventDefault;
}
if (!action1) {
action1Node.classList.add('hide');
Expand Down

0 comments on commit 3a6fc76

Please sign in to comment.