From: Tim Otten Date: Fri, 3 Apr 2015 09:00:56 +0000 (-0700) Subject: crmConfirm - Allow confirmation dialogs using Angular partials X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6a6d0f4139f242151a37b9eb4bdcefd0aea00c84;p=civicrm-core.git crmConfirm - Allow confirmation dialogs using Angular partials --- diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index 3e821bb7e5..7dd588aeda 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -906,7 +906,8 @@ // Example: // Example: - .directive('crmConfirm', function () { + // Example: + .directive('crmConfirm', function ($compile, $rootScope, $templateRequest, $q) { // Helpers to calculate default options for CRM.confirm() var defaultFuncs = { 'disable': function (options) { @@ -940,6 +941,7 @@ }; } }; + var confirmCount = 0; return { link: function (scope, element, attrs) { $(element).click(function () { @@ -948,9 +950,35 @@ options.title = attrs.title; } var defaults = (options.type) ? defaultFuncs[options.type](options) : {}; + + var tpl = null, stubId = null; + if (!options.message) { + if (options.templateUrl) { + tpl = $templateRequest(options.templateUrl); + } + else if (options.template) { + tpl = options.template; + } + if (tpl) { + stubId = 'crmUiConfirm_' + (++confirmCount); + options.message = '
'; + } + } + CRM.confirm(_.extend(defaults, options)) - .on('crmConfirm:yes', function () { scope.$apply(attrs.onYes); }) - .on('crmConfirm:no', function () { scope.$apply(attrs.onNo); }); + .on('crmConfirm:yes', function() { scope.$apply(attrs.onYes); }) + .on('crmConfirm:no', function() { scope.$apply(attrs.onNo); }); + + if (tpl && stubId) { + $q.when(tpl, function(html) { + var scope = options.scope || $rootScope.$new(); + if (options.export) { + angular.extend(scope, options.export); + } + var linker = $compile(html); + $('#' + stubId).append($(linker(scope))); + }); + } }); } };