From: Tim Otten Date: Thu, 10 Jul 2014 07:53:38 +0000 (-0700) Subject: CRM-14789 - crmCaseType - Allow enable/disable/delete X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4b8c8b422073535287b9f467fb6e0cd14aac1028;p=civicrm-core.git CRM-14789 - crmCaseType - Allow enable/disable/delete --- diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index db82722007..d144c37715 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -127,11 +127,51 @@ } }; }) + // Example: + // Example: + .directive('crmConfirm', function () { + // Helpers to calculate default options from CRM.confirm() + var defaultFuncs = { + 'disable': function (options) { + return { + message: ts('Are you sure you want to disable this?'), + options: {no: ts('Cancel'), yes: ts('Disable')}, + width: 300, + title: ts('Disable %1?', { + 1: options.obj.title || options.obj.label || options.obj.name || ts('the record') + }) + }; + }, + 'delete': function (options) { + return { + message: ts('Are you sure you want to delete this?'), + options: {no: ts('Cancel'), yes: ts('Delete')}, + width: 300, + title: ts('Delete %1?', { + 1: options.obj.title || options.obj.label || options.obj.name || ts('the record') + }) + }; + } + }; + return { + template: '', + link: function (scope, element, attrs) { + $(element).click(function () { + var options = scope.$eval(attrs['crmConfirm']); + var defaults = (options.type) ? defaultFuncs[options.type](options) : {}; + CRM.confirm(_.extend(defaults, options)) + .on('crmConfirm:yes', function () { scope.$apply(attrs['onYes']); }) + .on('crmConfirm:no', function () { scope.$apply(attrs['onNo']); }); + }); + } + }; + }) .run(function($rootScope, $location) { /// Example: $rootScope.goto = function(path) { $location.path(path); }; + // useful for debugging: $rootScope.log = console.log || function() {}; }) ; diff --git a/js/angular-crmCaseType.js b/js/angular-crmCaseType.js index e617064d2b..131dd62f87 100644 --- a/js/angular-crmCaseType.js +++ b/js/angular-crmCaseType.js @@ -284,6 +284,25 @@ crmCaseType.controller('CaseTypeListCtrl', function($scope, crmApi, caseTypes) { $scope.caseTypes = caseTypes.values; + $scope.toggleCaseType = function (caseType) { + caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; + crmApi('CaseType', 'create', caseType, true) + .then(function (data) { + if (data.is_error) { + caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; // revert + $scope.$digest(); + } + }); + }; + $scope.deleteCaseType = function (caseType) { + crmApi('CaseType', 'delete', {id: caseType.id}, true) + .then(function (data) { + if (!data.is_error) { + delete caseTypes.values[caseType.id]; + $scope.$digest(); + } + }); + }; }); })(angular, CRM.$, CRM._); \ No newline at end of file diff --git a/partials/crmCaseType/list.html b/partials/crmCaseType/list.html index ee4fc37df3..316d9a5eaa 100644 --- a/partials/crmCaseType/list.html +++ b/partials/crmCaseType/list.html @@ -17,13 +17,37 @@ Required vars: caseTypes - + {{caseType.title}} {{caseType.name}} {{caseType.description}} {{caseType.is_active == 1 ? 'Yes' : 'No'}} - Edit - + + + + Edit + + + more + + + + +