Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Set default format in date fields #511

Merged
merged 1 commit into from
Jun 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/javascripts/ng-admin/Crud/column/maDateColumn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global define*/

define(function (require) {
define(function () {
'use strict';

function maDateColumn() {
Expand All @@ -10,7 +10,14 @@ define(function (require) {
value: '&',
field: '&'
},
template: '<span>{{ value() | date:field().format() }}</span>'
link: function(scope) {
var field = scope.field();
scope.format = field.format();
if (!scope.format) {
scope.format = field.type() === 'date' ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss';
}
},
template: '<span>{{ value() | date:format }}</span>'
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/javascripts/ng-admin/Crud/field/maDateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ define(function (require) {
scope.value = field.parse()(rawValue);
});
scope.format = field.format();
if (!scope.format) {
scope.format = field.type() === 'date' ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss';
}

scope.v = field.validation();
scope.isOpen = false;
var input = element.find('input').eq(0);
Expand Down
12 changes: 9 additions & 3 deletions src/javascripts/ng-admin/Crud/misc/EntryFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ define(function () {

EntryFormatter.prototype.formatField = function formatField(field) {
var label = field.label() || field.name();
var type = field.type();

switch (field.type()) {
switch (type) {
case 'boolean':
case 'choice':
case 'choices':
Expand All @@ -33,9 +34,14 @@ define(function () {
value: entry.values[field.name()]
};
};
case 'datetime':
case 'date':
var formatDate = this.formatDate(field.format());
case 'datetime':
var format = field.format();
if (!format) {
format = type === 'date' ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss';
}

var formatDate = this.formatDate(format);
return function (entry) {
return {
name: label,
Expand Down