CRM-15705 - Add button icons to angular popup
[civicrm-core.git] / js / angular-crmMailing.js
index d62443a12d2efb74a2bca7c6394534f0585377b3..8881051f6d3111cd57f16396bfc35e6d95b97187 100644 (file)
           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();
             }
           }
         });
     $location.replace();
   });
 
-  angular.module('crmMailing').controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmStatus, CrmAttachments, crmMailingPreviewMgr, crmBlocker) {
+  angular.module('crmMailing').controller('EditMailingCtrl', function EditMailingCtrl($scope, selectedMail, $location, crmMailingMgr, crmStatus, attachments, crmMailingPreviewMgr, crmBlocker) {
     $scope.mailing = selectedMail;
-    $scope.attachments = new CrmAttachments(function () {
-      return {entity_table: 'civicrm_mailing', entity_id: $scope.mailing.id};
-    });
-    $scope.attachments.load();
+    $scope.attachments = attachments;
     $scope.crmMailingConst = CRM.crmMailing;
 
     var ts = $scope.ts = CRM.ts(null);
 
     // @return Promise
     $scope.submit = function submit() {
+      if (block.check() || $scope.crmMailing.$invalid) {
+        return;
+      }
+
       var promise = crmMailingMgr.save($scope.mailing)
           .then(function () {
             // pre-condition: the mailing exists *before* saving attachments to it
             return crmMailingMgr.submit($scope.mailing);
           })
           .then(function () {
-            leave('scheduled');
+            $scope.leave('scheduled');
           })
         ;
       return block(crmStatus({start: ts('Submitting...'), success: ts('Submitted')}, promise));
       return block(crmStatus({start: ts('Deleting...'), success: ts('Deleted')},
         crmMailingMgr.delete($scope.mailing)
           .then(function () {
-            leave('unscheduled');
+            $scope.leave('unscheduled');
           })
       ));
     };
 
     // @param string listingScreen 'archive', 'scheduled', 'unscheduled'
-    function leave(listingScreen) {
+    $scope.leave = function leave(listingScreen) {
       switch (listingScreen) {
         case 'archive':
           window.location = CRM.url('civicrm/mailing/browse/archived', {
             scheduled: 'false'
           });
       }
-    }
+    };
   });
 
   // Controller for the edit-recipients fields (
       // When using dialogService with a button bar, the major button actions
       // need to be registered with the dialog widget (and not embedded in
       // the body of the dialog).
-      var buttons = {};
-      buttons[ts('Save')] = function () {
-        $scope.save().then(function (item) {
-          dialogService.close('saveTemplateDialog', item);
-        });
-      };
-      buttons[ts('Cancel')] = function () {
-        dialogService.cancel('saveTemplateDialog');
-      };
+      var buttons = [
+        {
+          text: ts('Save'),
+          icons: {primary: 'ui-icon-check'},
+          click: function () {
+            $scope.save().then(function (item) {
+              dialogService.close('saveTemplateDialog', item);
+            });
+          }
+        },
+        {
+          text: ts('Cancel'),
+          icons: {primary: 'ui-icon-close'},
+          click: function () {
+            dialogService.cancel('saveTemplateDialog');
+          }
+        }
+      ];
       dialogService.setButtons('saveTemplateDialog', buttons);
     }