indent and title fix
[civicrm-core.git] / ang / crmStatusPage / StatusPageCtrl.js
index bec4df34f16136c0134d2b63e2f73b67274a6d23..f1d2966706f7705e927c2dcc1288321db9014e78 100644 (file)
@@ -1,77 +1,34 @@
 (function(angular, $, _) {
 
-  // controller
-
   angular.module('statuspage').controller('statuspageStatusPage',
-    function($scope, $location, crmApi, crmStatus, crmUiHelp, statuses, crmNavigator, preferences) {
-    // The ts() and hs() functions help load strings for this module.
-    var ts = $scope.ts = CRM.ts('statuspage');
-    // var hs = $scope.hs = crmUiHelp({file: 'CRM/statuspage/StatusPage'}); // See: templates/CRM/statuspage/StatusPage.hlp
-
-    $scope.path = $location.path();
-    $scope.navigator = crmNavigator;
-    $scope.statuses = statuses;
-    $scope.preferences = preferences;
-    $scope.alert = CRM.alert;
-
-    // will "hush" a status - gets the severity level of the status that is being hushed, and hushes all alerts for that check at and below the level of the current check
-    $scope.hush = function(name, severity) {
-      return  crmStatus(
-        { start: ts('Saving Status Preference...')      , success: ts('Preference Saved') },
-        crmApi('StatusPreference', 'create', {
-          "sequential": 1,
-          "name": name,
-          "ignore_severity": severity,
-          "hush_until":  ""
-        })
-        .then(function(){rmStatus($scope, name);})
-      );
-    };
-
-    // will reset ignore_severity to 0 to unhush the status alert.
-    $scope.unhush = function(name, severity) {
-      return  crmStatus(
-        { start: ts('Saving Status Preference...')      , success: ts('Preference Saved') },
-        crmApi('StatusPreference', 'create', {
-          "sequential": 1,
-          "name": name,
-          "ignore_severity": 0,
-          "hush_until": ""
-        })
-        .then(function(){rmStatus($scope, name);})
-      );
-    };
-
-    // will 'snooze' a status - will not show alerts at that level for that check + alerts below that level for that check until the specified date
-    $scope.snooze = function(status) {
-      $scope.showSnoozeOptions(status);
-      return crmStatus(
-        { status: ts('Saving Status Preference...')   , success: ts('Preference Saved') },
-          crmApi('StatusPreference', 'create', {
-            "sequential": 1,
-            "name": status.name,
-            "ignore_severity": status.snoozeOptions.severity,
-            "hush_until": status.snoozeOptions.until
-          })        .then(function(){rmStatus($scope, status.name);})
-      );
-    };
-    $scope.showSnoozeOptions = function(status) {
-      status.snoozeOptions.show = !status.snoozeOptions.show;
-    };
-  });
-
-
-  /**
-   * remove a status after it has been hushed/snoozed
-   * @param {type} $scope
-   * @param {type} statusName
-   * @returns void
-   */
-   function rmStatus($scope, statusName) {
-    $scope.statuses.values =  _.reject($scope.statuses.values,
-      function(status) {
-        return status.name === statusName;
+    function($scope, crmApi, crmStatus, statusData) {
+      $scope.ts = CRM.ts();
+      $scope.help = CRM.help;
+      $scope.formatDate = CRM.utils.formatDate;
+      $scope.statuses = statusData.values;
+
+      // updates a status preference and refreshes status data
+      $scope.setPref = function(status, until, visible) {
+        // Use an array because it's important that one api call executes before the other
+        var apiCalls = [
+          ['StatusPreference', 'create', {
+              "name": status.name,
+              "ignore_severity": visible ? 0 : status.severity,
+              "hush_until": until
+            }],
+          ['System', 'check', {sequential: 1}]
+        ];
+        crmApi(apiCalls, true)
+          .then(function(result) {
+            $scope.statuses = result[1].values;
+          });
+      };
+      
+      $scope.countVisible = function(visibility) {
+        return _.filter($scope.statuses, function(s) {
+          return s.is_visible == visibility && s.severity_id >= 2;
+        }).length;
+      };
     });
-  }
 
 })(angular, CRM.$, CRM._);