Merge pull request #10462 from civicrm/4.7.20-rc
[civicrm-core.git] / ang / crmStatusPage / StatusPageCtrl.js
CommitLineData
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 10 // Refresh the list. Optionally execute api calls first.
cca44a9b 11 function refresh(apiCalls, title) {
abb724f5 12 title = title || 'Untitled operation';
531b0c6c
CW
13 apiCalls = (apiCalls || []).concat([['System', 'check', {sequential: 1}]]);
14 $('#crm-status-list').block();
5db0114d 15 crmApi(apiCalls, true)
5ba324ab
CB
16 .then(function(results) {
17 $scope.statuses = results[results.length - 1].values;
18 results.forEach(function(result) {
19 if (result.is_error) {
cca44a9b 20 var error_message = ts(result.error_message);
5ba324ab
CB
21 if (typeof(result.debug_information) !== 'undefined') {
22 error_message += '<div class="status-debug-information">' +
fee76911 23 '<b>' + ts('Debug information') + ':</b><br>' +
5ba324ab
CB
24 result.debug_information + '</div>';
25 }
cca44a9b 26 CRM.alert(error_message, ts('Operation failed: ' + title), 'error');
5ba324ab
CB
27 }
28 });
531b0c6c 29 $('#crm-status-list').unblock();
28bd6c8d 30 });
531b0c6c
CW
31 }
32
33 // updates a status preference and refreshes status data
34 $scope.setPref = function(status, until, visible) {
35 refresh([
36 ['StatusPreference', 'create', {
37 name: status.name,
38 ignore_severity: visible ? 0 : status.severity,
39 hush_until: until
40 }]
cca44a9b 41 ], 'Set preference');
28bd6c8d 42 };
826f5ace 43
4cb29687
CW
44 $scope.countVisible = function(visibility) {
45 return _.filter($scope.statuses, function(s) {
eb94a576 46 return s.is_visible == visibility && s.severity_id >= 2;
4cb29687 47 }).length;
826f5ace 48 };
531b0c6c
CW
49
50 $scope.doAction = function(action) {
51 function run() {
52 switch (action.type) {
53 case 'href':
54 window.location = CRM.url(action.params.path, action.params.query, action.params.mode);
55 break;
56
57 case 'api3':
cca44a9b 58 refresh([action.params], action.title);
531b0c6c
CW
59 break;
60 }
61 }
62
63 if (action.confirm) {
64 CRM.confirm({
65 title: action.title,
66 message: action.confirm
67 }).on('crmConfirm:yes', run);
68 } else {
69 run();
70 }
71 };
4d8e3559 72 });
4d8e3559
NM
73
74})(angular, CRM.$, CRM._);