Commit | Line | Data |
---|---|---|
4d8e3559 NM |
1 | (function(angular, $, _) { |
2 | ||
4d8e3559 | 3 | angular.module('statuspage').controller('statuspageStatusPage', |
d1fa280a | 4 | function($scope, crmApi, crmStatus, statusData) { |
5db0114d | 5 | $scope.ts = CRM.ts(); |
2a243675 | 6 | $scope.help = CRM.help; |
4cf9188e CW |
7 | $scope.formatDate = CRM.utils.formatDate; |
8 | $scope.statuses = statusData.values; | |
4d8e3559 | 9 | |
531b0c6c CW |
10 | // Refresh the list. Optionally execute api calls first. |
11 | function refresh(apiCalls) { | |
12 | apiCalls = (apiCalls || []).concat([['System', 'check', {sequential: 1}]]); | |
13 | $('#crm-status-list').block(); | |
5db0114d CW |
14 | crmApi(apiCalls, true) |
15 | .then(function(result) { | |
531b0c6c CW |
16 | $scope.statuses = result[result.length - 1].values; |
17 | $('#crm-status-list').unblock(); | |
28bd6c8d | 18 | }); |
531b0c6c CW |
19 | } |
20 | ||
21 | // updates a status preference and refreshes status data | |
22 | $scope.setPref = function(status, until, visible) { | |
23 | refresh([ | |
24 | ['StatusPreference', 'create', { | |
25 | name: status.name, | |
26 | ignore_severity: visible ? 0 : status.severity, | |
27 | hush_until: until | |
28 | }] | |
29 | ]); | |
28bd6c8d | 30 | }; |
826f5ace | 31 | |
4cb29687 CW |
32 | $scope.countVisible = function(visibility) { |
33 | return _.filter($scope.statuses, function(s) { | |
eb94a576 | 34 | return s.is_visible == visibility && s.severity_id >= 2; |
4cb29687 | 35 | }).length; |
826f5ace | 36 | }; |
531b0c6c CW |
37 | |
38 | $scope.doAction = function(action) { | |
39 | function run() { | |
40 | switch (action.type) { | |
41 | case 'href': | |
42 | window.location = CRM.url(action.params.path, action.params.query, action.params.mode); | |
43 | break; | |
44 | ||
45 | case 'api3': | |
46 | refresh([action.params]); | |
47 | break; | |
48 | } | |
49 | } | |
50 | ||
51 | if (action.confirm) { | |
52 | CRM.confirm({ | |
53 | title: action.title, | |
54 | message: action.confirm | |
55 | }).on('crmConfirm:yes', run); | |
56 | } else { | |
57 | run(); | |
58 | } | |
59 | }; | |
4d8e3559 | 60 | }); |
4d8e3559 NM |
61 | |
62 | })(angular, CRM.$, CRM._); |