- var editorPaths = {
- '': '~/crmMailing/edit.html',
- '/unified': '~/crmMailing/edit-unified.html',
- '/unified2': '~/crmMailing/edit-unified2.html',
- '/wizard': '~/crmMailing/edit-wizard.html'
- };
- angular.forEach(editorPaths, function(editTemplate, pathSuffix) {
- if (CRM && CRM.crmMailing && CRM.crmMailing.workflowEnabled) {
- editTemplate = '~/crmMailing/edit-workflow.html'; // override
- }
- $routeProvider.when('/mailing/new' + pathSuffix, {
- template: '<p>' + ts('Initializing...') + '</p>',
- controller: 'CreateMailingCtrl',
- resolve: {
- selectedMail: function(crmMailingMgr) {
- var m = crmMailingMgr.create();
- return crmMailingMgr.save(m);
- }
- }
- });
- $routeProvider.when('/mailing/:id' + pathSuffix, {
- templateUrl: editTemplate,
- controller: 'EditMailingCtrl',
- resolve: {
- selectedMail: function($route, crmMailingMgr) {
- return crmMailingMgr.get($route.current.params.id);
- },
- attachments: function($route, CrmAttachments) {
- var attachments = new CrmAttachments(function () {
- return {entity_table: 'civicrm_mailing', entity_id: $route.current.params.id};
- });
- return attachments.load();
- }
- }
- });
- });
- }
- ]);
-
- angular.module('crmMailing').controller('ListMailingsCtrl', ['crmLegacy', 'crmNavigator', function ListMailingsCtrl(crmLegacy, crmNavigator) {
- // We haven't implemented this in Angular, but some users may get clever
- // about typing URLs, so we'll provide a redirect.
- var new_url = crmLegacy.url('civicrm/mailing/browse/unscheduled', {reset: 1, scheduled: 'false'});
- crmNavigator.redirect(new_url);
- }]);
-
- angular.module('crmMailing').controller('CreateMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location) {
- // Transition URL "/mailing/new/foo" => "/mailing/123/foo"
- var parts = $location.path().split('/'); // e.g. "/mailing/new" or "/mailing/123/wizard"
- parts[2] = selectedMail.id;
- $location.path(parts.join('/'));
- $location.replace();
- });
-
- angular.module('crmMailing').controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmStatus, attachments, crmMailingPreviewMgr, crmBlocker, CrmAutosaveCtrl, $timeout, crmUiHelp) {
- $scope.mailing = selectedMail;
- $scope.attachments = attachments;
- $scope.crmMailingConst = CRM.crmMailing;
- $scope.checkPerm = CRM.checkPerm;
-
- var ts = $scope.ts = CRM.ts(null);
- $scope.hs = crmUiHelp({file: 'CRM/Mailing/MailingUI'});
- var block = $scope.block = crmBlocker();
- var myAutosave = null;
-
- $scope.isSubmitted = function isSubmitted() {
- return _.size($scope.mailing.jobs) > 0;
- };
-
- // usage: approve('Approved')
- $scope.approve = function approve(status, options) {
- $scope.mailing.approval_status_id = APPROVAL_STATUSES[status];
- return myAutosave.suspend($scope.submit(options));
- };
-
- // @return Promise
- $scope.previewMailing = function previewMailing(mailing, mode) {
- return crmMailingPreviewMgr.preview(mailing, mode);
- };
-
- // @return Promise
- $scope.sendTest = function sendTest(mailing, attachments, recipient) {
- var savePromise = crmMailingMgr.save(mailing)
- .then(function () {
- return attachments.save();
- });
- return block(crmStatus({start: ts('Saving...'), success: ''}, savePromise)
- .then(function () {
- crmMailingPreviewMgr.sendTest(mailing, recipient);
- }));
- };
-
- // @return Promise
- $scope.submit = function submit(options) {
- options = options || {};
- if (block.check() || $scope.crmMailing.$invalid) {