Browse Source

KERNEL-2278 && BI-56459: 日期系列新增setMinDate和setMaxDate接口

master
windy 5 years ago
parent
commit
ff42bd22db
  1. 80
      src/case/calendar/calendar.js
  2. 91
      src/case/calendar/calendar.year.js
  3. 8
      src/widget/date/calendar/combo.year.date.js
  4. 6
      src/widget/date/calendar/picker.date.js
  5. 13
      src/widget/date/calendar/picker.year.js
  6. 30
      src/widget/date/calendar/popup.calendar.date.js
  7. 42
      src/widget/date/calendar/popup.year.js
  8. 14
      src/widget/dynamicdate/dynamicdate.combo.js
  9. 14
      src/widget/dynamicdate/dynamicdate.popup.js
  10. 12
      src/widget/dynamicdate/dynamicdate.trigger.js
  11. 12
      src/widget/dynamicdatetime/dynamicdatetime.combo.js
  12. 14
      src/widget/dynamicdatetime/dynamicdatetime.popup.js
  13. 12
      src/widget/dynamicdatetime/dynamicdatetime.trigger.js
  14. 16
      src/widget/yearmonth/card.static.yearmonth.js
  15. 14
      src/widget/yearmonth/popup.yearmonth.js

80
src/case/calendar/calendar.js

@ -94,37 +94,10 @@ BI.Calendar = BI.inherit(BI.Widget, {
vgap: 10 vgap: 10
}] }]
}); });
var days = this._dateCreator(o.year, o.month - 1, o.day);
items = [];
items.push(days.slice(0, 7));
items.push(days.slice(7, 14));
items.push(days.slice(14, 21));
items.push(days.slice(21, 28));
items.push(days.slice(28, 35));
items.push(days.slice(35, 42));
items = BI.map(items, function (i, item) {
return BI.map(item, function (j, td) {
var month = td.lastMonth ? o.month - 1 : (td.nextMonth ? o.month + 1 : o.month);
return BI.extend(td, {
type: "bi.calendar_date_item",
textAlign: "center",
whiteSpace: "normal",
once: false,
forceSelected: true,
height: 24,
value: o.year + "-" + month + "-" + td.text,
disabled: td.lastMonth || td.nextMonth || td.disabled,
lgap: 5,
rgap: 5
// selected: td.currentDay
});
});
});
this.days = BI.createWidget({ this.days = BI.createWidget({
type: "bi.button_group", type: "bi.button_group",
items: BI.createItems(items, {}), items: BI.createItems(this._getItems(), {}),
layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, { layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, {
columns: 7, columns: 7,
rows: 6, rows: 6,
@ -168,6 +141,57 @@ BI.Calendar = BI.inherit(BI.Widget, {
return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0]; return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0];
}, },
_getItems: function () {
var o = this.options;
var days = this._dateCreator(o.year, o.month - 1, o.day);
var items = [];
items.push(days.slice(0, 7));
items.push(days.slice(7, 14));
items.push(days.slice(14, 21));
items.push(days.slice(21, 28));
items.push(days.slice(28, 35));
items.push(days.slice(35, 42));
return BI.map(items, function (i, item) {
return BI.map(item, function (j, td) {
var month = td.lastMonth ? o.month - 1 : (td.nextMonth ? o.month + 1 : o.month);
return BI.extend(td, {
type: "bi.calendar_date_item",
textAlign: "center",
whiteSpace: "normal",
once: false,
forceSelected: true,
height: 24,
value: o.year + "-" + month + "-" + td.text,
disabled: td.lastMonth || td.nextMonth || td.disabled,
lgap: 5,
rgap: 5
// selected: td.currentDay
});
});
});
},
_populate: function() {
this.days.populate(this._getItems());
},
setMinDate: function (minDate) {
var o = this.options;
if (BI.isNotEmptyString(o.min)) {
o.min = minDate;
this._populate();
}
},
setMaxDate: function (maxDate) {
var o = this.options;
if (BI.isNotEmptyString(o.max)) {
o.max = maxDate;
this._populate();
}
},
setValue: function (ob) { setValue: function (ob) {
this.days.setValue([ob.year + "-" + ob.month + "-" + ob.day]); this.days.setValue([ob.year + "-" + ob.month + "-" + ob.day]);
}, },

91
src/case/calendar/calendar.year.js

@ -42,43 +42,11 @@ BI.YearCalendar = BI.inherit(BI.Widget, {
BI.YearCalendar.superclass._init.apply(this, arguments); BI.YearCalendar.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.currentYear = BI.getDate().getFullYear(); this.currentYear = BI.getDate().getFullYear();
var years = this._yearCreator(o.year || this.currentYear);
// 纵向排列年
var len = years.length, tyears = BI.makeArray(len, "");
var map = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11];
BI.each(years, function (i, y) {
tyears[i] = years[map[i]];
});
var items = [];
items.push(tyears.slice(0, 2));
items.push(tyears.slice(2, 4));
items.push(tyears.slice(4, 6));
items.push(tyears.slice(6, 8));
items.push(tyears.slice(8, 10));
items.push(tyears.slice(10, 12));
items = BI.map(items, function (i, item) {
return BI.map(item, function (j, td) {
return BI.extend(td, {
type: "bi.text_item",
cls: "bi-list-item-select",
textAlign: "center",
whiteSpace: "normal",
once: false,
forceSelected: true,
height: 24,
width: 45,
value: td.text,
disabled: td.disabled
});
});
});
this.years = BI.createWidget({ this.years = BI.createWidget({
type: "bi.button_group", type: "bi.button_group",
behaviors: o.behaviors, behaviors: o.behaviors,
items: BI.createItems(items, {}), items: BI.createItems(this._getItems(), {}),
layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, { layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, {
columns: 2, columns: 2,
rows: 6, rows: 6,
@ -114,6 +82,63 @@ BI.YearCalendar = BI.inherit(BI.Widget, {
return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0]; return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0];
}, },
_getItems: function () {
var o = this.options;
var years = this._yearCreator(o.year || this.currentYear);
// 纵向排列年
var len = years.length, tyears = BI.makeArray(len, "");
var map = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11];
BI.each(years, function (i, y) {
tyears[i] = years[map[i]];
});
var items = [];
items.push(tyears.slice(0, 2));
items.push(tyears.slice(2, 4));
items.push(tyears.slice(4, 6));
items.push(tyears.slice(6, 8));
items.push(tyears.slice(8, 10));
items.push(tyears.slice(10, 12));
return BI.map(items, function (i, item) {
return BI.map(item, function (j, td) {
return BI.extend(td, {
type: "bi.text_item",
cls: "bi-list-item-select",
textAlign: "center",
whiteSpace: "normal",
once: false,
forceSelected: true,
height: 24,
width: 45,
value: td.text,
disabled: td.disabled
});
});
});
},
_populate: function () {
this.years.populate(this._getItems());
},
setMinDate: function (minDate) {
var o = this.options;
if (BI.isNotEmptyString(o.min)) {
o.min = minDate;
this._populate();
}
},
setMaxDate: function (maxDate) {
var o = this.options;
if (BI.isNotEmptyString(this.options.max)) {
o.max = maxDate;
this._populate();
}
},
setValue: function (val) { setValue: function (val) {
this.years.setValue([val]); this.years.setValue([val]);
}, },

8
src/widget/date/calendar/combo.year.date.js

@ -61,6 +61,14 @@ BI.YearDateCombo = BI.inherit(BI.Trigger, {
}); });
}, },
setMinDate: function (minDate) {
this.popup.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
this.popup.setMaxDate(maxDate);
},
setValue: function (v) { setValue: function (v) {
this.trigger.setValue(v); this.trigger.setValue(v);
this.popup.setValue(v); this.popup.setValue(v);

6
src/widget/date/calendar/picker.date.js

@ -141,7 +141,13 @@ BI.DatePicker = BI.inherit(BI.Widget, {
return valid; return valid;
}, },
setMinDate: function (minDate) {
this.year.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
this.year.setMaxDate(maxDate);
},
setValue: function (ob) { setValue: function (ob) {
this._year = BI.parseInt(ob.year); this._year = BI.parseInt(ob.year);

13
src/widget/date/calendar/picker.year.js

@ -104,6 +104,19 @@ BI.YearPicker = BI.inherit(BI.Widget, {
return valid; return valid;
}, },
setMinDate: function (minDate) {
this.options.min = minDate;
this.year.setMinDate(minDate);
this._checkLeftValid();
this._checkRightValid();
},
setMaxDate: function (maxDate) {
this.options.max = maxDate;
this.year.setMaxDate(maxDate);
this._checkLeftValid();
this._checkRightValid();
},
setValue: function (v) { setValue: function (v) {

30
src/widget/date/calendar/popup.calendar.date.js

@ -102,6 +102,36 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, {
}); });
}, },
_checkMin: function () {
var calendar = this.calendar.getSelectedCard();
if (BI.isNotNull(calendar)) {
calendar.setMinDate(this.options.min);
}
},
_checkMax: function () {
var calendar = this.calendar.getSelectedCard();
if (BI.isNotNull(calendar)) {
calendar.setMaxDate(this.options.max);
}
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this.datePicker.setMinDate(minDate);
this._checkMin();
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this.datePicker.setMaxDate(maxDate);
this._checkMax();
}
},
setValue: function (timeOb) { setValue: function (timeOb) {
this.datePicker.setValue(timeOb); this.datePicker.setValue(timeOb);
this.calendar.setSelect(BI.Calendar.getPageByDateJSON(timeOb)); this.calendar.setSelect(BI.Calendar.getPageByDateJSON(timeOb));

42
src/widget/date/calendar/popup.year.js

@ -39,7 +39,7 @@ BI.YearPopup = BI.inherit(BI.Widget, {
this.selectedYear = this._year = BI.getDate().getFullYear(); this.selectedYear = this._year = BI.getDate().getFullYear();
var backBtn = BI.createWidget({ this.backBtn = BI.createWidget({
type: "bi.icon_button", type: "bi.icon_button",
cls: "pre-page-h-font", cls: "pre-page-h-font",
width: 24, width: 24,
@ -47,7 +47,7 @@ BI.YearPopup = BI.inherit(BI.Widget, {
value: -1 value: -1
}); });
var preBtn = BI.createWidget({ this.preBtn = BI.createWidget({
type: "bi.icon_button", type: "bi.icon_button",
cls: "next-page-h-font", cls: "next-page-h-font",
width: 24, width: 24,
@ -65,15 +65,15 @@ BI.YearPopup = BI.inherit(BI.Widget, {
tab: { tab: {
cls: "year-popup-navigation bi-high-light bi-split-top", cls: "year-popup-navigation bi-high-light bi-split-top",
height: 24, height: 24,
items: [backBtn, preBtn] items: [this.backBtn, this.preBtn]
}, },
cardCreator: BI.bind(this._createYearCalendar, this), cardCreator: BI.bind(this._createYearCalendar, this),
afterCardShow: function () { afterCardShow: function () {
this.setValue(self.selectedYear); this.setValue(self.selectedYear);
var calendar = this.getSelectedCard(); var calendar = this.getSelectedCard();
backBtn.setEnable(!calendar.isFrontYear()); calendar && self.backBtn.setEnable(!calendar.isFrontYear());
preBtn.setEnable(!calendar.isFinalYear()); calendar && self.preBtn.setEnable(!calendar.isFinalYear());
} }
}); });
@ -88,6 +88,38 @@ BI.YearPopup = BI.inherit(BI.Widget, {
} }
}, },
_checkMin: function () {
var calendar = this.navigation.getSelectedCard();
if (BI.isNotNull(calendar)) {
calendar.setMinDate(this.options.min);
this.backBtn.setEnable(!calendar.isFrontYear());
this.preBtn.setEnable(!calendar.isFinalYear());
}
},
_checkMax: function () {
var calendar = this.navigation.getSelectedCard();
if (BI.isNotNull(calendar)) {
calendar.setMaxDate(this.options.max);
this.backBtn.setEnable(!calendar.isFrontYear());
this.preBtn.setEnable(!calendar.isFinalYear());
}
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this._checkMin();
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this._checkMax();
}
},
getValue: function () { getValue: function () {
return this.selectedYear; return this.selectedYear;
}, },

14
src/widget/dynamicdate/dynamicdate.combo.js

@ -190,6 +190,8 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, {
listeners: [{ listeners: [{
eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW,
action: function () { action: function () {
self.popup.setMinDate(opts.minDate);
self.popup.setMaxDate(opts.maxDate);
self.popup.setValue(self.storeValue); self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW); self.fireEvent(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW);
} }
@ -267,6 +269,18 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, {
}, },
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
},
setValue: function (v) { setValue: function (v) {
this.storeValue = v; this.storeValue = v;
this.trigger.setValue(v); this.trigger.setValue(v);

14
src/widget/dynamicdate/dynamicdate.popup.js

@ -171,6 +171,20 @@ BI.DynamicDatePopup = BI.inherit(BI.Widget, {
return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value);
}, },
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.ymd.setMinDate(minDate);
}
this.options.min = minDate;
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.ymd.setMaxDate(maxDate);
}
this.options.max = maxDate;
},
setValue: function (v) { setValue: function (v) {
this.storeValue = v; this.storeValue = v;
var self = this; var self = this;

12
src/widget/dynamicdate/dynamicdate.trigger.js

@ -318,6 +318,18 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, {
} }
}, },
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
getKey: function () { getKey: function () {
return this.editor.getValue(); return this.editor.getValue();
}, },

12
src/widget/dynamicdatetime/dynamicdatetime.combo.js

@ -271,6 +271,18 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
} }
}, },
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
},
setValue: function (v) { setValue: function (v) {
this.storeValue = v; this.storeValue = v;
this.trigger.setValue(v); this.trigger.setValue(v);

14
src/widget/dynamicdatetime/dynamicdatetime.popup.js

@ -178,6 +178,20 @@ BI.DynamicDateTimePopup = BI.inherit(BI.Widget, {
return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value);
}, },
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.ymd.setMinDate(minDate);
}
this.options.min = minDate;
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.ymd.setMaxDate(maxDate);
}
this.options.max = maxDate;
},
setValue: function (v) { setValue: function (v) {
this.storeValue = v; this.storeValue = v;
var self = this; var self = this;

12
src/widget/dynamicdatetime/dynamicdatetime.trigger.js

@ -310,6 +310,18 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, {
} }
}, },
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) { setValue: function (v) {
var type, value, self = this; var type, value, self = this;
var date = BI.getDate(); var date = BI.getDate();

16
src/widget/yearmonth/card.static.yearmonth.js

@ -113,6 +113,22 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
}); });
}, },
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.yearPicker.setMinDate(minDate);
this._checkMonthStatus(this.selectedYear);
}
this.options.min = minDate;
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.yearPicker.setMaxDate(maxDate);
this._checkMonthStatus(this.selectedYear);
}
this.options.max = maxDate;
},
getValue: function () { getValue: function () {
return { return {
year: this.selectedYear, year: this.selectedYear,

14
src/widget/yearmonth/popup.yearmonth.js

@ -170,6 +170,20 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, {
}; };
}, },
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.year.setMinDate(minDate);
}
this.options.min = minDate;
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.year.setMaxDate(maxDate);
}
this.options.max = maxDate;
},
setValue: function (v) { setValue: function (v) {
this.storeValue = v; this.storeValue = v;
var self = this; var self = this;

Loading…
Cancel
Save