From c18b882545efb8e66048a01d183759f5b5256183 Mon Sep 17 00:00:00 2001 From: Derek McTavish Mounce Date: Mon, 4 Jun 2012 16:17:39 -0400 Subject: [PATCH 1/4] Return false from ui.Confirmation callback will avoid closing the dialog. --- build/ui.js | 19 ++++++++++--------- lib/components/confirmation/confirmation.js | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/build/ui.js b/build/ui.js index d2f24df..46c8b17 100644 --- a/build/ui.js +++ b/build/ui.js @@ -330,9 +330,9 @@ Dialog.prototype.hide = function(ms){ // hide / remove this.el.addClass('hide'); if (this._effect) { - setTimeout(function(self){ + setTimeout(function(){ self.remove(); - }, 500, this); + }, 500); } else { self.remove(); } @@ -448,7 +448,7 @@ Overlay.prototype.hide = function(){ exports.Confirmation = Confirmation; /** - * Return a new `Confirmation` dialog with the given + * Return a new `Confirmation` dialog with the given * `title` and `msg`. * * @param {String} title or msg @@ -562,15 +562,16 @@ Confirmation.prototype.render = function(options){ actions.find('.cancel').click(function(e){ e.preventDefault(); self.emit('cancel'); - self.callback(false); + self.callback(false) self.hide(); }); actions.find('.ok').click(function(e){ e.preventDefault(); self.emit('ok'); - self.callback(true); - self.hide(); + if (self.callback(true) !== false) { + self.hide(); + } }); }; @@ -1148,9 +1149,9 @@ Notification.prototype.hide = function(ms){ // hide / remove this.el.addClass('hide'); if (this._effect) { - setTimeout(function(self){ + setTimeout(function(){ self.remove(); - }, 500, this); + }, 500); } else { self.remove(); } @@ -1297,7 +1298,7 @@ exports.Menu = Menu; */ exports.menu = function(){ - return new Menu(); + return new Menu; }; /** diff --git a/lib/components/confirmation/confirmation.js b/lib/components/confirmation/confirmation.js index f04b07b..93e7774 100644 --- a/lib/components/confirmation/confirmation.js +++ b/lib/components/confirmation/confirmation.js @@ -6,7 +6,7 @@ exports.Confirmation = Confirmation; /** - * Return a new `Confirmation` dialog with the given + * Return a new `Confirmation` dialog with the given * `title` and `msg`. * * @param {String} title or msg @@ -120,14 +120,15 @@ Confirmation.prototype.render = function(options){ actions.find('.cancel').click(function(e){ e.preventDefault(); self.emit('cancel'); - self.callback(false); + self.callback(false) self.hide(); }); actions.find('.ok').click(function(e){ e.preventDefault(); self.emit('ok'); - self.callback(true); - self.hide(); + if (self.callback(true) !== false) { + self.hide(); + } }); }; From 0e57ec8903596f2534df7ec52fb805a5a2030d73 Mon Sep 17 00:00:00 2001 From: Derek McTavish Mounce Date: Mon, 4 Jun 2012 17:11:42 -0400 Subject: [PATCH 2/4] Work on async for confirmation callback --- build/ui.js | 14 ++++++++++---- lib/components/confirmation/confirmation.js | 12 +++++++++--- lib/components/dialog/dialog.js | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/build/ui.js b/build/ui.js index 46c8b17..8a6f53c 100644 --- a/build/ui.js +++ b/build/ui.js @@ -117,7 +117,7 @@ var active; exports.Dialog = Dialog; /** - * Return a new `Dialog` with the given + * Return a new `Dialog` with the given * (optional) `title` and `msg`. * * @param {String} title or msg @@ -529,10 +529,11 @@ Confirmation.prototype.ok = function(text){ * @api public */ -Confirmation.prototype.show = function(fn){ +Confirmation.prototype.show = function(fn, async){ ui.Dialog.prototype.show.call(this); this.el.find('.ok').focus(); this.callback = fn || function(){}; + this.async = async || false; return this; }; @@ -569,8 +570,13 @@ Confirmation.prototype.render = function(options){ actions.find('.ok').click(function(e){ e.preventDefault(); self.emit('ok'); - if (self.callback(true) !== false) { - self.hide(); + if(self.async){ + self.callback(true, function(){ + self.hide(); + }); + } + else{ + self.callback(true) !== false && self.hide(); } }); }; diff --git a/lib/components/confirmation/confirmation.js b/lib/components/confirmation/confirmation.js index 93e7774..69cb8cb 100644 --- a/lib/components/confirmation/confirmation.js +++ b/lib/components/confirmation/confirmation.js @@ -87,10 +87,11 @@ Confirmation.prototype.ok = function(text){ * @api public */ -Confirmation.prototype.show = function(fn){ +Confirmation.prototype.show = function(fn, async){ ui.Dialog.prototype.show.call(this); this.el.find('.ok').focus(); this.callback = fn || function(){}; + this.async = async || false; return this; }; @@ -127,8 +128,13 @@ Confirmation.prototype.render = function(options){ actions.find('.ok').click(function(e){ e.preventDefault(); self.emit('ok'); - if (self.callback(true) !== false) { - self.hide(); + if(self.async){ + self.callback(true, function(){ + self.hide(); + }); + } + else{ + self.callback(true) !== false && self.hide(); } }); }; diff --git a/lib/components/dialog/dialog.js b/lib/components/dialog/dialog.js index 7c33b6a..1f68086 100644 --- a/lib/components/dialog/dialog.js +++ b/lib/components/dialog/dialog.js @@ -12,7 +12,7 @@ var active; exports.Dialog = Dialog; /** - * Return a new `Dialog` with the given + * Return a new `Dialog` with the given * (optional) `title` and `msg`. * * @param {String} title or msg From fae23cc0fb7f5c2ec9392145c6e758c6d50a5824 Mon Sep 17 00:00:00 2001 From: Derek McTavish Mounce Date: Tue, 5 Jun 2012 14:28:08 -0400 Subject: [PATCH 3/4] More complete (and non-notworking) async Confirmation callback support --- lib/components/confirmation/confirmation.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/components/confirmation/confirmation.js b/lib/components/confirmation/confirmation.js index 69cb8cb..253922a 100644 --- a/lib/components/confirmation/confirmation.js +++ b/lib/components/confirmation/confirmation.js @@ -121,6 +121,14 @@ Confirmation.prototype.render = function(options){ actions.find('.cancel').click(function(e){ e.preventDefault(); self.emit('cancel'); + if(self.async){ + self.callback(false, function () { + self.hide(); + }); + } + else { + (self.callback(false) !== false && self.hide()); + } self.callback(false) self.hide(); }); @@ -134,7 +142,7 @@ Confirmation.prototype.render = function(options){ }); } else{ - self.callback(true) !== false && self.hide(); + (self.callback(true) !== false && self.hide()); } }); }; From 87ff76ebac01a0df260dc61435cafb6fefd0aa54 Mon Sep 17 00:00:00 2001 From: Derek McTavish Mounce Date: Tue, 5 Jun 2012 14:36:20 -0400 Subject: [PATCH 4/4] Remove duplicate code. --- build/ui.js | 10 +++++++++- lib/components/confirmation/confirmation.js | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/build/ui.js b/build/ui.js index 8a6f53c..8279cd0 100644 --- a/build/ui.js +++ b/build/ui.js @@ -563,6 +563,14 @@ Confirmation.prototype.render = function(options){ actions.find('.cancel').click(function(e){ e.preventDefault(); self.emit('cancel'); + if(self.async){ + self.callback(false, function () { + self.hide(); + }); + } + else { + (self.callback(false) !== false && self.hide()); + } self.callback(false) self.hide(); }); @@ -576,7 +584,7 @@ Confirmation.prototype.render = function(options){ }); } else{ - self.callback(true) !== false && self.hide(); + (self.callback(true) !== false && self.hide()); } }); }; diff --git a/lib/components/confirmation/confirmation.js b/lib/components/confirmation/confirmation.js index 253922a..0a7f4a1 100644 --- a/lib/components/confirmation/confirmation.js +++ b/lib/components/confirmation/confirmation.js @@ -129,8 +129,6 @@ Confirmation.prototype.render = function(options){ else { (self.callback(false) !== false && self.hide()); } - self.callback(false) - self.hide(); }); actions.find('.ok').click(function(e){