mirror of
https://git.proxmox.com/git/proxmox-widget-toolkit
synced 2025-05-21 23:13:58 +00:00
DateTimeField: implement set{Max, Min}Value
this sets the max/min value for the underlying date and time fields, and allowing to only change the value respecting both current date and time fields e.g. if the new maxValue is 2020-10-10 12:00 and the current value is 2020-10-09 15:00 do not allow to set the date to 2020-10-10 and vice versa (if the new limit is on the same day, limit the time range) Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
dca21e597e
commit
731df80da0
@ -49,6 +49,84 @@ Ext.define('Proxmox.DateTimeField', {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
setMinValue: function(value) {
|
||||||
|
let me = this;
|
||||||
|
let current = me.getValue();
|
||||||
|
if (!value || !current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let minhours = value.getHours();
|
||||||
|
let minminutes = value.getMinutes();
|
||||||
|
|
||||||
|
let hours = current.getHours();
|
||||||
|
let minutes = current.getMinutes();
|
||||||
|
|
||||||
|
value.setHours(0);
|
||||||
|
value.setMinutes(0);
|
||||||
|
value.setSeconds(0);
|
||||||
|
current.setHours(0);
|
||||||
|
current.setMinutes(0);
|
||||||
|
current.setSeconds(0);
|
||||||
|
|
||||||
|
let time = new Date();
|
||||||
|
if (current-value > 0) {
|
||||||
|
time.setHours(0);
|
||||||
|
time.setMinutes(0);
|
||||||
|
time.setSeconds(0);
|
||||||
|
time.setMilliseconds(0);
|
||||||
|
} else {
|
||||||
|
time.setHours(minhours);
|
||||||
|
time.setMinutes(minminutes);
|
||||||
|
}
|
||||||
|
me.lookup('timeentry').setMinValue(time);
|
||||||
|
|
||||||
|
// current time is smaller than the time part of the new minimum
|
||||||
|
// so we have to add 1 to the day
|
||||||
|
if ((minhours*60+minminutes) > (hours*60+minutes)) {
|
||||||
|
value.setDate(value.getDate()+1);
|
||||||
|
}
|
||||||
|
me.lookup('dateentry').setMinValue(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
setMaxValue: function(value) {
|
||||||
|
let me = this;
|
||||||
|
let current = me.getValue();
|
||||||
|
if (!value || !current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let maxhours = value.getHours();
|
||||||
|
let maxminutes = value.getMinutes();
|
||||||
|
|
||||||
|
let hours = current.getHours();
|
||||||
|
let minutes = current.getMinutes();
|
||||||
|
|
||||||
|
value.setHours(0);
|
||||||
|
value.setMinutes(0);
|
||||||
|
current.setHours(0);
|
||||||
|
current.setMinutes(0);
|
||||||
|
|
||||||
|
let time = new Date();
|
||||||
|
if (value-current > 0) {
|
||||||
|
time.setHours(23);
|
||||||
|
time.setMinutes(59);
|
||||||
|
time.setSeconds(59);
|
||||||
|
} else {
|
||||||
|
time.setHours(maxhours);
|
||||||
|
time.setMinutes(maxminutes);
|
||||||
|
}
|
||||||
|
me.lookup('timeentry').setMaxValue(time);
|
||||||
|
|
||||||
|
// current time is biger than the time part of the new maximum
|
||||||
|
// so we have to subtract 1 to the day
|
||||||
|
if ((maxhours*60+maxminutes) < (hours*60+minutes)) {
|
||||||
|
value.setDate(value.getDate()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
me.lookup('dateentry').setMaxValue(value);
|
||||||
|
},
|
||||||
|
|
||||||
initComponent: function() {
|
initComponent: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
@ -59,6 +137,14 @@ Ext.define('Proxmox.DateTimeField', {
|
|||||||
me.lookupReference('dateentry').setValue(value);
|
me.lookupReference('dateentry').setValue(value);
|
||||||
me.lookupReference('timeentry').setValue(value);
|
me.lookupReference('timeentry').setValue(value);
|
||||||
|
|
||||||
|
if (me.minValue) {
|
||||||
|
me.setMinValue(me.minValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (me.maxValue) {
|
||||||
|
me.setMaxValue(me.maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
me.relayEvents(me.lookupReference('dateentry'), ['change']);
|
me.relayEvents(me.lookupReference('dateentry'), ['change']);
|
||||||
me.relayEvents(me.lookupReference('timeentry'), ['change']);
|
me.relayEvents(me.lookupReference('timeentry'), ['change']);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user