From a94867962dfb76369177f568c1c432f3f2c6fc66 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 14 Jun 2021 22:07:05 -0700 Subject: [PATCH] msgtplui - Misc - Add filter box. Cleanup some links. Consolidate list ctrls. --- ext/msgtplui/ang/msgtplui/ListCtrl.js | 42 +++++++++++++++++++++++++ ext/msgtplui/ang/msgtplui/User.html | 27 +++++++++++++--- ext/msgtplui/ang/msgtplui/User.js | 16 ++-------- ext/msgtplui/ang/msgtplui/Workflow.html | 37 ++++++++++++++++------ ext/msgtplui/ang/msgtplui/Workflow.js | 16 ++-------- 5 files changed, 97 insertions(+), 41 deletions(-) create mode 100644 ext/msgtplui/ang/msgtplui/ListCtrl.js diff --git a/ext/msgtplui/ang/msgtplui/ListCtrl.js b/ext/msgtplui/ang/msgtplui/ListCtrl.js new file mode 100644 index 0000000000..b827c32505 --- /dev/null +++ b/ext/msgtplui/ang/msgtplui/ListCtrl.js @@ -0,0 +1,42 @@ +(function(angular, $, _) { + + angular.module('msgtplui').controller('MsgtpluiListCtrl', function($scope, $route, crmApi4, crmStatus, crmUiAlert, crmUiHelp, records, $location) { + var ts = $scope.ts = CRM.ts('msgtplui'); + var hs = $scope.hs = crmUiHelp({file: 'CRM/msgtplui/User'}); // See: templates/CRM/msgtplui/User.hlp + $scope.crmUrl = CRM.url; + $scope.crmUiAlert = crmUiAlert; + + var ctrl = this; + ctrl.records = records; + + ctrl.editUrl = function(record, stage) { + var url = '#/edit?id=' + encodeURIComponent(record.id); + if (record['tx.language']) { + url = url + '&lang=' + encodeURIComponent(record['tx.language']); + } + if (stage === 'draft') { + url = url + '&status=draft'; + } + return url; + }; + + ctrl.delete = function (record) { + var q = crmApi4('MessageTemplate', 'delete', {where: [['id', '=', record.id]]}).then(function(){ + $route.reload(); + }); + return crmStatus({start: ts('Deleting...'), success: ts('Deleted')}, q); + }; + + ctrl.toggle = function (record) { + var wasActive = !!record.is_active; + var q = crmApi4('MessageTemplate', 'update', {where: [['id', '=', record.id]], values: {is_active: !wasActive}}) + .then(function(resp){ + record.is_active = !wasActive; + }); + return wasActive ? crmStatus({start: ts('Disabling...'), success: ts('Disabled')}, q) + : crmStatus({start: ts('Enabling...'), success: ts('Enabled')}, q); + }; + + }); + +})(angular, CRM.$, CRM._); diff --git a/ext/msgtplui/ang/msgtplui/User.html b/ext/msgtplui/ang/msgtplui/User.html index 4aa075218a..3d78ae04c7 100644 --- a/ext/msgtplui/ang/msgtplui/User.html +++ b/ext/msgtplui/ang/msgtplui/User.html @@ -1,18 +1,35 @@
-
+
+ +
+ + + + + + {{:: ts('Add Message Template') }} + +
+ + - - - + + + + diff --git a/ext/msgtplui/ang/msgtplui/User.js b/ext/msgtplui/ang/msgtplui/User.js index 6238b1b2d6..28f4e4cb85 100644 --- a/ext/msgtplui/ang/msgtplui/User.js +++ b/ext/msgtplui/ang/msgtplui/User.js @@ -1,14 +1,15 @@ (function(angular, $, _) { + // Display a list of user-driven message-templates. angular.module('msgtplui').config(function($routeProvider) { $routeProvider.when('/user', { - controller: 'MsgtpluiUser', + controller: 'MsgtpluiListCtrl', controllerAs: '$ctrl', templateUrl: '~/msgtplui/User.html', resolve: { records: function(crmApi4) { return crmApi4('MessageTemplate', 'get', { - select: ["id", "msg_title", "is_default"], + select: ["id", "msg_title", "msg_subject", "is_active"], where: [["workflow_name", "IS EMPTY"]], orderBy: {"msg_title":"ASC"}, }); @@ -18,15 +19,4 @@ } ); - // The controller uses *injection*. This default injects a few things: - // $scope -- This is the set of variables shared between JS and HTML. - // crmApi, crmStatus, crmUiHelp -- These are services provided by civicrm-core. - // myContact -- The current contact, defined above in config(). - angular.module('msgtplui').controller('MsgtpluiUser', function($scope, crmApi, crmStatus, crmUiHelp, records) { - var ts = $scope.ts = CRM.ts('msgtplui'); - var hs = $scope.hs = crmUiHelp({file: 'CRM/msgtplui/User'}); // See: templates/CRM/msgtplui/User.hlp - var ctrl = this; - ctrl.records = records; - }); - })(angular, CRM.$, CRM._); diff --git a/ext/msgtplui/ang/msgtplui/Workflow.html b/ext/msgtplui/ang/msgtplui/Workflow.html index f1e625273a..a9f46a5fd9 100644 --- a/ext/msgtplui/ang/msgtplui/Workflow.html +++ b/ext/msgtplui/ang/msgtplui/Workflow.html @@ -1,28 +1,45 @@
-
+
+ +
+ + +
{{ts('Title')}}{{ts('Subject')}}{{ts('Enabled?')}}
{{msgtpl.msg_title}} - (...Actions...) +
{{record.msg_title}}{{record.msg_subject}}{{record.is_active ? ts('Yes') : ts('No')}} + {{ts('Edit')}} + {{ts('Disable')}} + {{ts('Enable')}} + {{ts('Delete')}}
- - - + + + - - - + + + diff --git a/ext/msgtplui/ang/msgtplui/Workflow.js b/ext/msgtplui/ang/msgtplui/Workflow.js index 7198f34fb0..11ed5cf0e5 100644 --- a/ext/msgtplui/ang/msgtplui/Workflow.js +++ b/ext/msgtplui/ang/msgtplui/Workflow.js @@ -1,8 +1,9 @@ (function(angular, $, _) { + // Display a list of system-workflow message-templates. angular.module('msgtplui').config(function($routeProvider) { $routeProvider.when('/workflow', { - controller: 'MsgtpluiWorkflow', + controller: 'MsgtpluiListCtrl', controllerAs: '$ctrl', templateUrl: '~/msgtplui/Workflow.html', resolve: { @@ -12,7 +13,7 @@ join: [["Translation AS tx", "LEFT", null, ["tx.entity_table", "=", "'civicrm_msg_template'"], ["tx.entity_id", "=", "id"]]], where: [["workflow_name", "IS NOT EMPTY"]], groupBy: ["id", "tx.language"], - orderBy: {"msg_title":"ASC"}, + orderBy: {"msg_title":"ASC", "tx.language:label":"ASC"}, chain: {"statuses":["Translation", "get", {"select":["status_id:name"], "where":[["entity_table", "=", "civicrm_msg_template"], ["entity_id", "=", "$id"], ["language", "=", "$tx.language"]], "groupBy":["status_id"]}, "status_id:name"]} }); }, @@ -21,15 +22,4 @@ } ); - // The controller uses *injection*. This default injects a few things: - // $scope -- This is the set of variables shared between JS and HTML. - // crmApi, crmStatus, crmUiHelp -- These are services provided by civicrm-core. - // myContact -- The current contact, defined above in config(). - angular.module('msgtplui').controller('MsgtpluiWorkflow', function($scope, crmStatus, crmUiHelp, records) { - var ts = $scope.ts = CRM.ts('msgtplui'); - var hs = $scope.hs = crmUiHelp({file: 'CRM/msgtplui/Workflow'}); // See: templates/CRM/msgtplui/Workflow.hlp - var ctrl = this; - ctrl.records = records; - }); - })(angular, CRM.$, CRM._); -- 2.25.1
{{ts('Title')}} {{ts('Locale')}}{{ts('Current')}}{{ts('Draft')}}{{ts('Translate')}}
{{msgtpl.msg_title}}{{msgtpl['tx.language:label']}}
{{record.msg_title}}{{record['tx.language:label']}} - Current + + {{ts('Current')}} + + + {{ts('Current')}} + - Draft + + {{ts('Draft')}} + + + {{ts('Draft')}} + - Translate + + {{ts('Translate')}} +