Merge pull request #19761 from MegaphoneJon/financial-169
[civicrm-core.git] / ang / crmStatusPage / StatusPageCtrl.js
index ff1e73527b9c30f4d7cce4e0a63ae903a8c4e75f..530d7ffdbe96ec974d6ebda604cd9a3a67daca88 100644 (file)
@@ -1,6 +1,6 @@
 (function(angular, $, _) {
 
-  angular.module('statuspage').controller('statuspageStatusPage',
+  angular.module('crmStatusPage').controller('crmStatusPageCtrl',
     function($scope, crmApi, crmStatus, statusData) {
       $scope.ts = CRM.ts();
       $scope.help = CRM.help;
@@ -8,12 +8,24 @@
       $scope.statuses = statusData.values;
 
       // Refresh the list. Optionally execute api calls first.
-      function refresh(apiCalls) {
+      function refresh(apiCalls, title) {
+        title = title || 'Untitled operation';
         apiCalls = (apiCalls || []).concat([['System', 'check', {sequential: 1}]]);
         $('#crm-status-list').block();
         crmApi(apiCalls, true)
-          .then(function(result) {
-            $scope.statuses = result[result.length - 1].values;
+          .then(function(results) {
+            $scope.statuses = results[results.length - 1].values;
+            results.forEach(function(result) {
+              if (result.is_error) {
+                var error_message = ts(result.error_message);
+                if (typeof(result.debug_information) !== 'undefined') {
+                  error_message += '<div class="status-debug-information">' +
+                      '<b>' + ts('Debug information') + ':</b><br>' +
+                      result.debug_information + '</div>';
+                }
+                CRM.alert(error_message, ts('Operation failed: ' + title), 'error');
+                }
+              });
             $('#crm-status-list').unblock();
           });
       }
@@ -26,9 +38,9 @@
             ignore_severity: visible ? 0 : status.severity,
             hush_until: until
           }]
-        ]);
+        ], 'Set preference');
       };
-      
+
       $scope.countVisible = function(visibility) {
         return _.filter($scope.statuses, function(s) {
           return s.is_visible == visibility && s.severity_id >= 2;
@@ -43,7 +55,7 @@
               break;
 
             case 'api3':
-              refresh([action.params]);
+              refresh([action.params], action.title);
               break;
           }
         }