Merge branch 'CRM-15202' of https://github.com/jmcclelland/civicrm-core into 4.7...
[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 // updates a status preference and refreshes status data
11 $scope.setPref = function(status, until, visible) {
12 // Use an array because it's important that one api call executes before the other
13 var apiCalls = [
14 ['StatusPreference', 'create', {
15 "name": status.name,
16 "ignore_severity": visible ? 0 : status.severity,
17 "hush_until": until
18 }],
19 ['System', 'check', {sequential: 1}]
20 ];
21 crmApi(apiCalls, true)
22 .then(function(result) {
23 $scope.statuses = result[1].values;
24 });
25 };
26
27 $scope.countVisible = function(visibility) {
28 return _.filter($scope.statuses, function(s) {
29 return s.is_visible == visibility && s.severity_id >= 2;
30 }).length;
31 };
32 });
33
34 })(angular, CRM.$, CRM._);