From a7d4e1e8233458472c042a53831afa0fa095beb7 Mon Sep 17 00:00:00 2001 From: Andrew Kanieski Date: Sat, 4 Jan 2014 18:46:31 -0500 Subject: [PATCH] Added Asynchronous Success function support If asyncSuccess is true then the success function will be called with the controller(this) as the first parameter and the close dialog function as the second parameter. This allows you to conditionally continue. In my case I needed the success to not close the dialog if perhaps the data entered in the dialog was invalid. Also I needed to validate asynchronously. FYI if this is not something fundoo-solutions doesn't want in createDialog thats fine. I just needed it for my project. :-) --- src/createDialog.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/createDialog.js b/src/createDialog.js index 859141b..e97d007 100644 --- a/src/createDialog.js +++ b/src/createDialog.js @@ -6,6 +6,7 @@ angular.module('fundoo.services', []).factory('createDialog', ["$document", "$co templateUrl: null, title: 'Default Title', backdrop: true, + asyncSuccess: false, success: {label: 'OK', fn: null}, cancel: {label: 'Close', fn: null}, controller: null, //just like route controller declaration @@ -109,8 +110,12 @@ angular.module('fundoo.services', []).factory('createDialog', ["$document", "$co }; scope.$modalSuccess = function () { var callFn = options.success.fn || closeFn; - callFn.call(this); - scope.$modalClose(); + if (options.asyncSuccess) { + callFn(this, scope.$modalClose); + } else { + callFn.call(this); + scope.$modalClose(); + } }; scope.$modalSuccessLabel = options.success.label; scope.$modalCancelLabel = options.cancel.label;