Merge pull request #10152 from agh1/crm-20419
[civicrm-core.git] / ang / crmStatusPage / StatusPageCtrl.js
1 (function(angular, $, _) {
2
3 angular.module('statuspage').controller('statuspageStatusPage',
4 function($scope, crmApi, crmStatus, statusData) {
5 $scope.ts = CRM.ts();
6 $scope.help = CRM.help;
7 $scope.formatDate = CRM.utils.formatDate;
8 $scope.statuses = statusData.values;
9
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();
14 crmApi(apiCalls, true)
15 .then(function(result) {
16 $scope.statuses = result[result.length - 1].values;
17 $('#crm-status-list').unblock();
18 });
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 ]);
30 };
31
32 $scope.countVisible = function(visibility) {
33 return _.filter($scope.statuses, function(s) {
34 return s.is_visible == visibility && s.severity_id >= 2;
35 }).length;
36 };
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 };
60 });
61
62 })(angular, CRM.$, CRM._);