[IMP] Improved dates widgets

bzr revid: fme@openerp.com-20110630121008-qt4yr12z6sk70yua
This commit is contained in:
Fabien Meghazi 2011-06-30 14:10:08 +02:00
parent 0c3109c29d
commit f84f7f5729
2 changed files with 23 additions and 8 deletions

View File

@ -773,13 +773,14 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
position: relative;
vertical-align: top;
}
.openerp input.field_date, .openerp input.field_datetime {
background: #fff url('../img/ui/field_calendar.png') no-repeat right center;
background-origin: content-box;
-moz-background-origin: content;
-moz-background-origin: content-box;
-webkit-background-origin: content-box;
.openerp img.ui-datepicker-trigger, .openerp img.ui-datepicker-trigger {
margin-left: -20px;
vertical-align: middle;
cursor: pointer;
position: relative;
top: -1px;
}
/* http://www.quirksmode.org/dom/inputfile.html
* http://stackoverflow.com/questions/2855589/replace-input-type-file-by-an-image
*/

View File

@ -879,12 +879,17 @@ openerp.base.form.FieldDatetime = openerp.base.form.Field.extend({
this._super(view, node);
this.template = "FieldDate";
this.jqueryui_object = 'datetimepicker';
this.validation_regex = /^\d+-\d+-\d+( \d+:\d+(:\d+)?)?$/;
},
start: function() {
this._super.apply(this, arguments);
this.$element.find('input').change(this.on_ui_change)[this.jqueryui_object]({
dateFormat: 'yy-mm-dd',
timeFormat: 'hh:mm:ss'
timeFormat: 'hh:mm:ss',
showOn: 'button',
buttonImage: '/base/static/src/img/ui/field_calendar.png',
buttonImageOnly: true,
constrainInput: false
});
},
set_value: function(value) {
@ -909,7 +914,15 @@ openerp.base.form.FieldDatetime = openerp.base.form.Field.extend({
this.$element.find('input').attr('disabled', this.readonly);
},
validate: function() {
this.invalid = this.required && !this.$element.find('input')[this.jqueryui_object]('getDate');
this.invalid = false;
var value = this.$element.find('input').val();
if (value === "") {
this.invalid = this.required;
} else if (this.validation_regex) {
this.invalid = !this.validation_regex.test(value);
} else {
this.invalid = !this.$element.find('input')[this.jqueryui_object]('getDate');
}
},
focus: function() {
this.$element.find('input').focus();
@ -922,6 +935,7 @@ openerp.base.form.FieldDate = openerp.base.form.FieldDatetime.extend({
init: function(view, node) {
this._super(view, node);
this.jqueryui_object = 'datepicker';
this.validation_regex = /^\d+-\d+-\d+$/;
},
parse: openerp.base.parse_date,
format: openerp.base.format_date