Browse Source

KERNEL-552 feat: 日期类型控件允许配置是否可以输入

master
windy 6 years ago
parent
commit
7fa489476e
  1. 2
      demo/js/widget/date/demo.multidate_combo.js
  2. 4
      src/widget/dynamicdate/dynamicdate.combo.js
  3. 57
      src/widget/dynamicdate/dynamicdate.trigger.js
  4. 4
      src/widget/dynamicdatetime/dynamicdatetime.combo.js
  5. 58
      src/widget/dynamicdatetime/dynamicdatetime.trigger.js
  6. 3
      src/widget/time/time.trigger.js

2
demo/js/widget/date/demo.multidate_combo.js

@ -21,6 +21,7 @@ Demo.Date = BI.inherit(BI.Widget, {
self.datecombo = this; self.datecombo = this;
}, },
width: 300, width: 300,
// allowEdit: false,
// format: "%Y-%X-%d", // yyyy-MM-dd // format: "%Y-%X-%d", // yyyy-MM-dd
// format: "%Y/%X/%d", // yyyy/MM/dd // format: "%Y/%X/%d", // yyyy/MM/dd
// format: "%Y-%x-%e", // yyyy-M-d // format: "%Y-%x-%e", // yyyy-M-d
@ -51,6 +52,7 @@ Demo.Date = BI.inherit(BI.Widget, {
self.datetimecombo = this; self.datetimecombo = this;
}, },
width: 300, width: 300,
// allowEdit: false,
// format: "%Y-%X-%d %H:%M:%S", // yyyy-MM-dd HH:mm:ss // format: "%Y-%X-%d %H:%M:%S", // yyyy-MM-dd HH:mm:ss
// format: "%Y/%X/%d %H:%M:%S", // yyyy/MM/dd HH:mm:ss // format: "%Y/%X/%d %H:%M:%S", // yyyy/MM/dd HH:mm:ss
// format: "%Y-%X-%d %I:%M:%S", // yyyy-MM-dd hh:mm:ss // format: "%Y-%X-%d %I:%M:%S", // yyyy-MM-dd hh:mm:ss

4
src/widget/dynamicdate/dynamicdate.combo.js

@ -11,7 +11,8 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, {
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31", maxDate: "2099-12-31",
format: "" format: "",
allowEdit: true
}, },
@ -50,6 +51,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, {
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
format: opts.format, format: opts.format,
allowEdit: opts.allowEdit,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,
ref: function () { ref: function () {

57
src/widget/dynamicdate/dynamicdate.trigger.js

@ -13,7 +13,8 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24, height: 24,
format: "" // 显示的日期格式化方式 format: "", // 显示的日期格式化方式
allowEdit: true // 是否允许编辑
}, },
_init: function () { _init: function () {
@ -47,25 +48,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
} }
return str; return str;
}, },
title: function () { title: BI.bind(this._getTitle, this)
var storeValue = self.storeValue || {};
var type = storeValue.type || BI.DynamicDateCombo.Static;
var value = storeValue.value;
switch (type) {
case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value);
var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static:
default:
if (BI.isNull(value) || BI.isNull(value.day)) {
return "";
}
return BI.print(BI.getDate(value.year, (value.month - 1), value.day), self._getFormatString());
}
}
}); });
this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () {
self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN);
@ -124,9 +107,43 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
width: 24 width: 24
}] }]
}); });
!o.allowEdit && BI.createWidget({
type: "bi.absolute",
element: this,
items: [{
el: {
type: "bi.text",
title: BI.bind(this._getTitle, this)
},
left: 0,
right: 24,
top: 0,
bottom: 0
}]
});
this.setValue(o.value); this.setValue(o.value);
}, },
_getTitle: function () {
var storeValue = this.storeValue || {};
var type = storeValue.type || BI.DynamicDateCombo.Static;
var value = storeValue.value;
switch (type) {
case BI.DynamicDateCombo.Dynamic:
var text = this._getText(value);
var date = BI.getDate();
date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, this._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static:
default:
if (BI.isNull(value) || BI.isNull(value.day)) {
return "";
}
return BI.print(BI.getDate(value.year, (value.month - 1), value.day), this._getFormatString());
}
},
_getStandardDateStr: function (v) { _getStandardDateStr: function (v) {
var c = this._const; var c = this._const;
var result = [0, 1, 2]; var result = [0, 1, 2];

4
src/widget/dynamicdatetime/dynamicdatetime.combo.js

@ -11,7 +11,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
height: 22, height: 22,
minDate: "1900-01-01", minDate: "1900-01-01",
maxDate: "2099-12-31", maxDate: "2099-12-31",
format: "" format: "",
allowEdit: true
}, },
@ -49,6 +50,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
type: "bi.dynamic_date_time_trigger", type: "bi.dynamic_date_time_trigger",
min: opts.minDate, min: opts.minDate,
max: opts.maxDate, max: opts.maxDate,
allowEdit: opts.allowEdit,
format: opts.format, format: opts.format,
height: opts.height, height: opts.height,
value: opts.value, value: opts.value,

58
src/widget/dynamicdatetime/dynamicdatetime.trigger.js

@ -13,7 +13,8 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
height: 24, height: 24,
format: "" // 显示的日期格式化方式 format: "", // 显示的日期格式化方式
allowEdit: true // 是否允许编辑
}, },
_init: function () { _init: function () {
@ -47,25 +48,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
} }
return str; return str;
}, },
title: function () { title: BI.bind(this._getTitle, this)
var storeValue = self.storeValue || {};
var type = storeValue.type || BI.DynamicDateCombo.Static;
var value = storeValue.value;
switch (type) {
case BI.DynamicDateCombo.Dynamic:
var text = self._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, self._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static:
default:
if (BI.isNull(value) || BI.isNull(value.day)) {
return "";
}
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0,
value.second || 0), self._getFormatString());
}
}
}); });
this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () {
self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN);
@ -122,9 +105,44 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
width: 24 width: 24
}] }]
}); });
!o.allowEdit && BI.createWidget({
type: "bi.absolute",
element: this,
items: [{
el: {
type: "bi.text",
title: BI.bind(this._getTitle, this)
},
left: 0,
right: 24,
top: 0,
bottom: 0
}]
});
this.setValue(o.value); this.setValue(o.value);
}, },
_getTitle: function () {
var storeValue = this.storeValue || {};
var type = storeValue.type || BI.DynamicDateCombo.Static;
var value = storeValue.value;
switch (type) {
case BI.DynamicDateCombo.Dynamic:
var text = this._getText(value);
var date = BI.DynamicDateHelper.getCalculation(value);
var dateStr = BI.print(date, this._getFormatString());
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr);
case BI.DynamicDateCombo.Static:
default:
if (BI.isNull(value) || BI.isNull(value.day)) {
return "";
}
return BI.print(BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0,
value.second || 0), this._getFormatString());
}
},
_getStandardDateStr: function (v) { _getStandardDateStr: function (v) {
var result = []; var result = [];
var hasSecond = false; var hasSecond = false;

3
src/widget/time/time.trigger.js

@ -135,7 +135,8 @@
_getTitle: function () { _getTitle: function () {
var storeValue = this.storeValue || {}; var storeValue = this.storeValue || {};
return BI.print(BI.getDate(storeValue.year, (storeValue.month - 1), storeValue.day), this._getFormatString()); var date = BI.getDate();
return BI.print(BI.getDate(date.getFullYear(), 0, 1, storeValue.hour, storeValue.minute, storeValue.second), this._getFormatString());
}, },
_getFormatString: function () { _getFormatString: function () {

Loading…
Cancel
Save