Skip to content

Commit

Permalink
Set default format in date fields
Browse files Browse the repository at this point in the history
  • Loading branch information
manuquentin committed Jun 16, 2015
1 parent 724fd3b commit 4d51ad1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
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

0 comments on commit 4d51ad1

Please sign in to comment.