| 1 | (function(angular, $, _) { |
| 2 | |
| 3 | // Controller for the in-place msg-template management |
| 4 | angular.module('crmMailing').controller('MsgTemplateCtrl', function MsgTemplateCtrl($scope, crmMsgTemplates, dialogService) { |
| 5 | var ts = $scope.ts = CRM.ts(null); |
| 6 | $scope.crmMsgTemplates = crmMsgTemplates; |
| 7 | $scope.checkPerm = CRM.checkPerm; |
| 8 | // @return Promise MessageTemplate (per APIv3) |
| 9 | $scope.saveTemplate = function saveTemplate(mailing) { |
| 10 | var model = { |
| 11 | selected_id: mailing.msg_template_id, |
| 12 | tpl: { |
| 13 | msg_title: '', |
| 14 | msg_subject: mailing.subject, |
| 15 | msg_text: mailing.body_text, |
| 16 | msg_html: mailing.body_html |
| 17 | } |
| 18 | }; |
| 19 | var options = CRM.utils.adjustDialogDefaults({ |
| 20 | autoOpen: false, |
| 21 | height: 'auto', |
| 22 | width: '40%', |
| 23 | title: ts('Save Template') |
| 24 | }); |
| 25 | return dialogService.open('saveTemplateDialog', '~/crmMailing/SaveMsgTemplateDialogCtrl.html', model, options) |
| 26 | .then(function(item) { |
| 27 | mailing.msg_template_id = item.id; |
| 28 | return item; |
| 29 | }); |
| 30 | }; |
| 31 | |
| 32 | // @param int id |
| 33 | // @return Promise |
| 34 | $scope.loadTemplate = function loadTemplate(mailing, id) { |
| 35 | return crmMsgTemplates.get(id).then(function(tpl) { |
| 36 | mailing.msg_template_id = tpl.id; |
| 37 | mailing.subject = tpl.msg_subject; |
| 38 | mailing.body_text = tpl.msg_text; |
| 39 | mailing.body_html = tpl.msg_html; |
| 40 | }); |
| 41 | }; |
| 42 | }); |
| 43 | |
| 44 | })(angular, CRM.$, CRM._); |