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