});
// Controller for the in-place msg-template management
- // Scope members:
- // - [input] mailing: object
crmMailing2.controller('MsgTemplateCtrl', function MsgTemplateCtrl($scope, crmMsgTemplates, dialogService, $parse) {
var ts = $scope.ts = CRM.ts('CiviMail');
$scope.crmMsgTemplates = crmMsgTemplates;
// @return Promise MessageTemplate (per APIv3)
- $scope.saveTemplate = function saveTemplate() {
+ $scope.saveTemplate = function saveTemplate(mailing) {
var model = {
- selected_id: $scope.mailing.msg_template_id,
+ selected_id: mailing.msg_template_id,
tpl: {
msg_title: '',
- msg_subject: $scope.mailing.subject,
- msg_text: $scope.mailing.body_text,
- msg_html: $scope.mailing.body_html
+ msg_subject: mailing.subject,
+ msg_text: mailing.body_text,
+ msg_html: mailing.body_html
}
};
var options = {
};
return dialogService.open('saveTemplateDialog', partialUrl('dialog/saveTemplate.html'), model, options)
.then(function (item) {
- $parse('mailing.msg_template_id').assign($scope, item.id);
+ mailing.msg_template_id = item.id;
return item;
});
};
// @param int id
// @return Promise
- $scope.loadTemplate = function loadTemplate(id) {
+ $scope.loadTemplate = function loadTemplate(mailing, id) {
return crmMsgTemplates.get(id).then(function (tpl) {
- $scope.mailing.subject = tpl.msg_subject;
- $scope.mailing.body_text = tpl.msg_text;
- $scope.mailing.body_html = tpl.msg_html;
+ mailing.subject = tpl.msg_subject;
+ mailing.body_text = tpl.msg_text;
+ mailing.body_html = tpl.msg_html;
});
};
});
name="msg_template_id"
crm-ui-select="{dropdownAutoWidth : true, allowClear: true, placeholder: ts('Message Template')}"
ng-model="mailing.msg_template_id"
- ng-change="loadTemplate(mailing.msg_template_id)"
+ ng-change="loadTemplate(mailing, mailing.msg_template_id)"
>
<option value=""></option>
<option ng-repeat="frm in crmMsgTemplates.getAll() | orderBy:'msg_title'" ng-value="frm.id">{{frm.msg_title}}</option>
</select>
- <a ng-click="saveTemplate()" class="crm-hover-button action-item" title="{{ts('Save As')}}"><span class="icon ui-icon-disk"></span></a>
+ <a ng-click="saveTemplate(mailing)" class="crm-hover-button action-item" title="{{ts('Save As')}}"><span class="icon ui-icon-disk"></span></a>
</div>
</div>
<div crm-ui-field="subform.fromAddress" crm-title="ts('From')">