629681f755933802e2261df2e19e8e787ee21da6
[civicrm-core.git] / ang / crmStatusPage / StatusPageCtrl.js
1 (function(angular, $, _) {
2
3 angular.module('statuspage').controller('statuspageStatusPage',
4 function($scope, crmApi, crmStatus, statusData, statuspageSeverityList) {
5
6 function preprocessStatuses(apiData) {
7 _.each(apiData.values, function(status) {
8 status.severity_id = status.severity;
9 status.severity = statuspageSeverityList[status.severity];
10 if (status.hidden_until) {
11 var date = $.datepicker.parseDate('yy-mm-dd', status.hidden_until);
12 status.hidden_until = $.datepicker.formatDate(CRM.config.dateInputFormat, date);
13 }
14 });
15 $scope.statuses = apiData.values;
16 }
17 preprocessStatuses(statusData);
18
19 $scope.ts = CRM.ts();
20 $scope.alert = CRM.alert;
21
22 // updates a status preference and refreshes status data
23 $scope.setPref = function(status, until, visible) {
24 // Use an array because it's important that one api call executes before the other
25 var apiCalls = [
26 ['StatusPreference', 'create', {
27 "name": status.name,
28 "ignore_severity": visible ? 0 : status.severity,
29 "hush_until": until
30 }],
31 ['System', 'check', {sequential: 1}]
32 ];
33 crmApi(apiCalls, true)
34 .then(function(result) {
35 preprocessStatuses(result[1]);
36 });
37 };
38
39 $scope.countVisible = function(visibility) {
40 return _.filter($scope.statuses, function(s) {
41 return s.is_visible == visibility && s.severity_id >= 3;
42 }).length;
43 };
44 });
45
46 })(angular, CRM.$, CRM._);