diff --git a/demo/js/widget/date/demo.multidate_combo.js b/demo/js/widget/date/demo.multidate_combo.js index 604a4a4aee..61b20892cc 100644 --- a/demo/js/widget/date/demo.multidate_combo.js +++ b/demo/js/widget/date/demo.multidate_combo.js @@ -21,6 +21,7 @@ Demo.Date = BI.inherit(BI.Widget, { self.datecombo = this; }, width: 300, + // allowEdit: false, // format: "%Y-%X-%d", // yyyy-MM-dd // format: "%Y/%X/%d", // yyyy/MM/dd // format: "%Y-%x-%e", // yyyy-M-d @@ -51,6 +52,7 @@ Demo.Date = BI.inherit(BI.Widget, { self.datetimecombo = this; }, 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 %I:%M:%S", // yyyy-MM-dd hh:mm:ss diff --git a/src/widget/dynamicdate/dynamicdate.combo.js b/src/widget/dynamicdate/dynamicdate.combo.js index e53ad57c50..b93cd63946 100644 --- a/src/widget/dynamicdate/dynamicdate.combo.js +++ b/src/widget/dynamicdate/dynamicdate.combo.js @@ -11,7 +11,8 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { height: 22, minDate: "1900-01-01", maxDate: "2099-12-31", - format: "" + format: "", + allowEdit: true }, @@ -50,6 +51,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { min: opts.minDate, max: opts.maxDate, format: opts.format, + allowEdit: opts.allowEdit, height: opts.height, value: opts.value, ref: function () { diff --git a/src/widget/dynamicdate/dynamicdate.trigger.js b/src/widget/dynamicdate/dynamicdate.trigger.js index e2f6954574..d896c45390 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -13,7 +13,8 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24, - format: "" // 显示的日期格式化方式 + format: "", // 显示的日期格式化方式 + allowEdit: true // 是否允许编辑 }, _init: function () { @@ -47,25 +48,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { } return str; }, - title: function () { - 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()); - } - } + title: BI.bind(this._getTitle, this) }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); @@ -124,9 +107,43 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { 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); }, + _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) { var c = this._const; var result = [0, 1, 2]; diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js index 531e18f983..ee5e9429be 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.combo.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.combo.js @@ -11,7 +11,8 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { height: 22, minDate: "1900-01-01", maxDate: "2099-12-31", - format: "" + format: "", + allowEdit: true }, @@ -49,6 +50,7 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { type: "bi.dynamic_date_time_trigger", min: opts.minDate, max: opts.maxDate, + allowEdit: opts.allowEdit, format: opts.format, height: opts.height, value: opts.value, diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 228c8f0d4c..d73e65296f 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -13,7 +13,8 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24, - format: "" // 显示的日期格式化方式 + format: "", // 显示的日期格式化方式 + allowEdit: true // 是否允许编辑 }, _init: function () { @@ -47,25 +48,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { } return str; }, - title: function () { - 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()); - } - } + title: BI.bind(this._getTitle, this) }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); @@ -122,9 +105,44 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { 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); }, + _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) { var result = []; var hasSecond = false; diff --git a/src/widget/time/time.trigger.js b/src/widget/time/time.trigger.js index d8e99d368d..f61dfe7180 100644 --- a/src/widget/time/time.trigger.js +++ b/src/widget/time/time.trigger.js @@ -135,7 +135,8 @@ _getTitle: function () { 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 () {