Commit 4cf9188e authored by colemanw's avatar colemanw

Add CRM.utils.formatDate

parent d1fa280a
......@@ -18,7 +18,7 @@
{{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">
......
......@@ -2,20 +2,10 @@
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) {
......@@ -30,7 +20,7 @@
];
crmApi(apiCalls, true)
.then(function(result) {
preprocessStatuses(result[1]);
$scope.statuses = result[1].values;
});
};
......
......@@ -1481,4 +1481,31 @@ if (!CRM.vars) CRM.vars = {};
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, _);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment