From 97e6b7ecbc40c4c4645150d3c4d1c44a6b61c6b4 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 14 Jul 2021 14:02:14 -0700 Subject: [PATCH] msgtplui - WIP Load real list of examples --- ext/msgtplui/ang/msgtplui/Edit.js | 45 ++++++++++++++++++-------- ext/msgtplui/ang/msgtplui/Preview.html | 2 +- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/ext/msgtplui/ang/msgtplui/Edit.js b/ext/msgtplui/ang/msgtplui/Edit.js index 7544c89d0a..5b3d4c74db 100644 --- a/ext/msgtplui/ang/msgtplui/Edit.js +++ b/ext/msgtplui/ang/msgtplui/Edit.js @@ -245,11 +245,11 @@ // Ex: $rootScope.$emit('previewMsgTpl', {revisionName: 'txDraft', formatName: 'msg_text'}) function onPreview(event, args) { var defaults = { - exampleName: 'fix-this-example', - examples: [ - {id: 0, name: 'fix-this-example', label: ts('Fix this example')}, - {id: 1, name: 'another-example', label: ts('Another example')} - ], + // exampleName: 'fix-this-example', + // examples: [ + // {id: 0, name: 'fix-this-example', title: ts('Fix this example')}, + // {id: 1, name: 'another-example', title: ts('Another example')} + // ], formatName: 'msg_html', formats: [ {id: 0, name: 'msg_html', label: ts('HTML')}, @@ -264,16 +264,33 @@ }, []), title: ts('Preview') }; - var model = angular.extend({}, defaults, args); - var options = CRM.utils.adjustDialogDefaults({ - dialogClass: 'msgtplui-dialog', - autoOpen: false, - height: '90%', - width: '90%' + + crmApi4('WorkflowMessageExample', 'get', { + // FIXME: workflow name + where: [["tags", "CONTAINS", "preview"], ["workflow", "=", "case_activity"]], + limit: 25 + }).then(function(workflowMessageExamples) { + defaults.exampleName = workflowMessageExamples.length > 0 ? workflowMessageExamples[0].name : null; + var i = 0; + angular.forEach(workflowMessageExamples, function(ex) { + ex.id = i++; + }); + defaults.examples = workflowMessageExamples; + + var model = angular.extend({}, defaults, args); + var options = CRM.utils.adjustDialogDefaults({ + dialogClass: 'msgtplui-dialog', + autoOpen: false, + height: '90%', + width: '90%' + }); + return dialogService.open('previewMsgDlg', '~/msgtplui/Preview.html', model, options) + // Nothing to do but hide warnings. The field was edited live. + .then(function(){}, function(){}); + }, function(failure) { + // handle failure }); - return dialogService.open('previewMsgDlg', '~/msgtplui/Preview.html', model, options) - // Nothing to do but hide warnings. The field was edited live. - .then(function(){}, function(){}); + } $rootScope.$on('previewMsgTpl', onPreview); $rootScope.$on('$destroy', function (){ diff --git a/ext/msgtplui/ang/msgtplui/Preview.html b/ext/msgtplui/ang/msgtplui/Preview.html index e0e66ea8ff..fe4a5b4396 100644 --- a/ext/msgtplui/ang/msgtplui/Preview.html +++ b/ext/msgtplui/ang/msgtplui/Preview.html @@ -35,7 +35,7 @@
- +
-- 2.25.1