0fd79df29f4b3b6c4f8f47061fe90dd647739fd8
1 (function(angular
, $, _
) {
3 angular
.module('crmStatusPage').controller('crmStatusPageCtrl',
4 function($scope
, crmApi
, crmStatus
, statusData
) {
6 $scope
.help
= CRM
.help
;
7 $scope
.formatDate
= CRM
.utils
.formatDate
;
8 $scope
.statuses
= statusData
.values
;
10 // Refresh the list. Optionally execute api calls first.
11 function refresh(apiCalls
, title
) {
12 title
= title
|| 'Untitled operation';
13 apiCalls
= (apiCalls
|| []).concat([['System', 'check', {sequential
: 1, options
: {limit
: 0}}]]);
14 $('#crm-status-list').block();
15 crmApi(apiCalls
, true)
16 .then(function(results
) {
17 $scope
.statuses
= results
[results
.length
- 1].values
;
18 results
.forEach(function(result
) {
19 if (result
.is_error
) {
20 var error_message
= ts(result
.error_message
);
21 if (typeof(result
.debug_information
) !== 'undefined') {
22 error_message
+= '<div class="status-debug-information">' +
23 '<b>' + ts('Debug information') + ':</b><br>' +
24 result
.debug_information
+ '</div>';
26 CRM
.alert(error_message
, ts('Operation failed: ' + title
), 'error');
29 $('#crm-status-list').unblock();
33 // updates a status preference and refreshes status data
34 $scope
.setPref = function(status
, until
, visible
) {
36 ['StatusPreference', 'create', {
38 ignore_severity
: visible
? 0 : status
.severity
,
44 $scope
.countVisible = function(visibility
) {
45 return _
.filter($scope
.statuses
, function(s
) {
46 return s
.is_visible
== visibility
&& s
.severity_id
>= 2;
50 $scope
.doAction = function(action
) {
52 switch (action
.type
) {
54 window
.location
= CRM
.url(action
.params
.path
, action
.params
.query
, action
.params
.mode
);
58 refresh([action
.params
], action
.title
);
66 message
: action
.confirm
67 }).on('crmConfirm:yes', run
);
74 })(angular
, CRM
.$, CRM
._
);