From 56861d4f895b4be43066d24a2425d264af0b2be0 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 15 Jun 2021 02:18:07 -0700 Subject: [PATCH] msgtplui - ListCtrl - Ensure that standard records are always listed Before: If you have a translation, then it would obscure the existence of the standard/baseline template. After: The records for the standard/baseline templates and translations are separate. --- ext/msgtplui/ang/msgtplui/ListCtrl.js | 4 ++-- ext/msgtplui/ang/msgtplui/User.js | 11 ++++++----- ext/msgtplui/ang/msgtplui/Workflow.html | 12 ++++++------ ext/msgtplui/ang/msgtplui/Workflow.js | 23 ++++++++++++++--------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/ext/msgtplui/ang/msgtplui/ListCtrl.js b/ext/msgtplui/ang/msgtplui/ListCtrl.js index e4b21b0a93..c2fa577de5 100644 --- a/ext/msgtplui/ang/msgtplui/ListCtrl.js +++ b/ext/msgtplui/ang/msgtplui/ListCtrl.js @@ -1,6 +1,6 @@ (function(angular, $, _) { - angular.module('msgtplui').controller('MsgtpluiListCtrl', function($scope, $route, crmApi4, crmStatus, crmUiAlert, crmUiHelp, records, $location) { + angular.module('msgtplui').controller('MsgtpluiListCtrl', function($scope, $route, crmApi4, crmStatus, crmUiAlert, crmUiHelp, prefetch, $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; @@ -16,7 +16,7 @@ }); var ctrl = this; - ctrl.records = records; + ctrl.records = [].concat(prefetch.records, prefetch.translations || []); /** * diff --git a/ext/msgtplui/ang/msgtplui/User.js b/ext/msgtplui/ang/msgtplui/User.js index 87200fa616..5d38a75b64 100644 --- a/ext/msgtplui/ang/msgtplui/User.js +++ b/ext/msgtplui/ang/msgtplui/User.js @@ -8,11 +8,12 @@ controllerAs: '$ctrl', templateUrl: '~/msgtplui/User.html', resolve: { - records: function(crmApi4, crmStatus) { - var q = crmApi4('MessageTemplate', 'get', { - select: ["id", "msg_title", "msg_subject", "is_active"], - where: [["workflow_name", "IS EMPTY"], ["is_reserved", "=", "0"]], - orderBy: {"msg_title":"ASC"}, + prefetch: function(crmApi4, crmStatus) { + var q = crmApi4({ + records: ['MessageTemplate', 'get', { + select: ["id", "msg_title", "msg_subject", "is_active"], + where: [["workflow_name", "IS EMPTY"], ["is_reserved", "=", "0"]] + }] }); return crmStatus({start: ts('Loading...'), success: ''}, q); } diff --git a/ext/msgtplui/ang/msgtplui/Workflow.html b/ext/msgtplui/ang/msgtplui/Workflow.html index fcc52a8f94..60f75dc554 100644 --- a/ext/msgtplui/ang/msgtplui/Workflow.html +++ b/ext/msgtplui/ang/msgtplui/Workflow.html @@ -19,22 +19,22 @@ - + {{record.msg_title}} - {{record['tx.language:label']}} + {{record['tx.language:label'] || ts('Standard')}} - + {{ts('Current')}} - + {{ts('Current')}} - + {{ts('Draft')}} - + {{ts('Draft')}} diff --git a/ext/msgtplui/ang/msgtplui/Workflow.js b/ext/msgtplui/ang/msgtplui/Workflow.js index b007c64122..4bd173b922 100644 --- a/ext/msgtplui/ang/msgtplui/Workflow.js +++ b/ext/msgtplui/ang/msgtplui/Workflow.js @@ -8,17 +8,22 @@ controllerAs: '$ctrl', templateUrl: '~/msgtplui/Workflow.html', resolve: { - records: function(crmApi4, crmStatus) { - var q= crmApi4('MessageTemplate', 'get', { - select: ["id", "msg_title", "tx.language:label", "tx.language", "is_default"], - join: [["Translation AS tx", "LEFT", null, ["tx.entity_table", "=", "'civicrm_msg_template'"], ["tx.entity_id", "=", "id"]]], - where: [["workflow_name", "IS NOT EMPTY"], ["is_reserved", "=", "0"]], - groupBy: ["id", "tx.language"], - 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"]} + prefetch: function(crmApi4, crmStatus) { + var q = crmApi4({ + records: ['MessageTemplate', 'get', { + select: ["id", "msg_title", "is_default", "is_active"], + where: [["workflow_name", "IS NOT EMPTY"], ["is_reserved", "=", "0"]] + }], + translations: ['MessageTemplate', 'get', { + select: ["id", "msg_title", "is_default", "is_active", "tx.language:label", "tx.language"], + join: [["Translation AS tx", "INNER", null, ["tx.entity_table", "=", "'civicrm_msg_template'"], ["tx.entity_id", "=", "id"]]], + where: [["workflow_name", "IS NOT EMPTY"], ["is_reserved", "=", "0"]], + groupBy: ["id", "tx.language"], + chain: {"tx.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"]} + }] }); return crmStatus({start: ts('Loading...'), success: ''}, q); - }, + } }, }); } -- 2.25.1