{{status.title}}
<div statuspage-popup-menu class="hush-menu css_right"></div>
<div ng-if="!status.is_visible" class="hidden-until css_right">
- ({{status.hidden_until ? ts('Hidden until %1', {1: status.hidden_until}) : ts('Hidden permanently')}})
+ ({{status.hidden_until ? ts('Hidden until %1', {1: formatDate(status.hidden_until)}) : ts('Hidden permanently')}})
</div>
</h3>
<div class="crm-block crm-status-message-body">
angular.module('statuspage').controller('statuspageStatusPage',
function($scope, crmApi, crmStatus, statusData) {
-
- function preprocessStatuses(apiData) {
- _.each(apiData.values, function(status) {
- if (status.hidden_until) {
- var date = $.datepicker.parseDate('yy-mm-dd', status.hidden_until);
- status.hidden_until = $.datepicker.formatDate(CRM.config.dateInputFormat, date);
- }
- });
- $scope.statuses = apiData.values;
- }
- preprocessStatuses(statusData);
-
$scope.ts = CRM.ts();
$scope.alert = CRM.alert;
+ $scope.formatDate = CRM.utils.formatDate;
+ $scope.statuses = statusData.values;
// updates a status preference and refreshes status data
$scope.setPref = function(status, until, visible) {
];
crmApi(apiCalls, true)
.then(function(result) {
- preprocessStatuses(result[1]);
+ $scope.statuses = result[1].values;
});
};
var scale = Math.pow(10.0, len-digits);
return Math.round(n / scale) * scale;
};
+
+ // Format a date for output to the user
+ // Input may be a js Date object, a unix timestamp or a yyyy-mm-dd string
+ CRM.utils.formatDate = function(input, outputFormat) {
+ if (!input) {
+ return '';
+ }
+ switch (typeof input) {
+ case 'object':
+ // already a date object
+ break;
+
+ case 'string':
+ // convert iso format
+ input = $.datepicker.parseDate('yy-mm-dd', input.substr(0, 10));
+ break;
+
+ case 'number':
+ // convert unix timestamp
+ input = new Date(input*1000);
+ break;
+
+ default:
+ throw 'Invalid input passed to CRM.utils.formatDate';
+ }
+ return $.datepicker.formatDate(outputFormat || CRM.config.dateInputFormat, input);
+ }
})(jQuery, _);