1 (function(angular
, $, _
) {
3 // Controller for the "Save Message Template" dialog
5 // - [input] "model": Object
6 // - "selected_id": int
8 // - "msg_subject": string
9 // - "msg_text": string
10 // - "msg_html": string
11 angular
.module('crmMailing').controller('SaveMsgTemplateDialogCtrl', function SaveMsgTemplateDialogCtrl($scope
, crmMsgTemplates
, dialogService
) {
12 var ts
= $scope
.ts
= CRM
.ts(null);
13 $scope
.saveOpt
= {mode
: '', newTitle
: ''};
14 $scope
.selected
= null;
16 $scope
.save
= function save() {
17 var tpl
= _
.extend({}, $scope
.model
.tpl
);
18 switch ($scope
.saveOpt
.mode
) {
20 tpl
.msg_title
= $scope
.saveOpt
.newTitle
;
23 tpl
.id
= $scope
.selected
.id
;
24 tpl
.msg_title
= $scope
.selected
.msg_title
;
27 throw 'SaveMsgTemplateDialogCtrl: Unrecognized mode: ' + $scope
.saveOpt
.mode
;
29 return crmMsgTemplates
.save(tpl
)
30 .then(function (item
) {
31 CRM
.status(ts('Saved'));
36 function scopeApply(f
) {
39 $scope
.$apply(function () {
46 crmMsgTemplates
.get($scope
.model
.selected_id
).then(
48 $scope
.saveOpt
.mode
= 'update';
49 $scope
.selected
= tpl
;
52 $scope
.saveOpt
.mode
= 'add';
53 $scope
.selected
= null;
56 // When using dialogService with a button bar, the major button actions
57 // need to be registered with the dialog widget (and not embedded in
58 // the body of the dialog).
62 icons
: {primary
: 'fa-check'},
64 $scope
.save().then(function (item
) {
65 dialogService
.close('saveTemplateDialog', item
);
71 icons
: {primary
: 'fa-times'},
73 dialogService
.cancel('saveTemplateDialog');
77 dialogService
.setButtons('saveTemplateDialog', buttons
);
80 setTimeout(scopeApply(init
), 0);
83 })(angular
, CRM
.$, CRM
._
);