fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
9.0 KiB

7 years ago
BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
props: {
baseCls: "bi-year-quarter-combo",
7 years ago
behaviors: {},
minDate: "1900-01-01", // 最小日期
maxDate: "2099-12-31", // 最大日期
height: 24,
supportDynamic: true,
isNeedAdjustHeight: false,
isNeedAdjustWidth: false
},
7 years ago
_init: function () {
var self = this, o = this.options;
BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments);
7 years ago
this.storeValue = o.value;
var border = o.simple ? 1 : 2;
self.storeTriggerValue = "";
7 years ago
this.trigger = BI.createWidget({
type: "bi.dynamic_year_quarter_trigger",
simple: o.simple,
min: o.minDate,
max: o.maxDate,
height: o.height - border,
7 years ago
value: o.value || ""
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_KEY_DOWN, function () {
self.combo.isViewVisible() && self.combo.hideView();
});
7 years ago
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () {
self.combo.isViewVisible() && self.combo.hideView();
});
7 years ago
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () {
self.combo.showView();
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () {
self.combo.isViewVisible() && self.combo.hideView();
self.comboWrapper.element.addClass("error");
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_ERROR);
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_VALID, function () {
self.comboWrapper.element.removeClass("error");
self.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID);
});
7 years ago
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () {
var dateStore = self.storeTriggerValue;
var dateObj = self.trigger.getKey();
if (BI.isEqual(dateObj, dateStore)) {
return;
}
if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) {
self.storeValue = self.trigger.getValue();
self.setValue(self.trigger.getValue());
}
7 years ago
self._checkDynamicValue(self.storeValue);
7 years ago
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM);
8 years ago
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_FOCUS, function () {
self.storeTriggerValue = self.trigger.getKey();
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_FOCUS);
});
7 years ago
this.combo = BI.createWidget({
type: "bi.combo",
7 years ago
container: o.container,
isNeedAdjustHeight: o.isNeedAdjustHeight,
isNeedAdjustWidth: o.isNeedAdjustWidth,
7 years ago
el: this.trigger,
destroyWhenHide: true,
adjustLength: 1,
7 years ago
popup: {
minWidth: 85,
stopPropagation: false,
el: {
type: "bi.dynamic_year_quarter_popup",
width: o.isNeedAdjustWidth ? o.width : undefined,
supportDynamic: o.supportDynamic,
7 years ago
ref: function () {
self.popup = this;
},
listeners: [{
eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE,
action: function () {
self.setValue(self.popup.getValue());
self.combo.hideView();
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE,
action: function () {
self.setValue();
self.combo.hideView();
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE,
action: function () {
var date = BI.getDate();
self.setValue({ type: BI.DynamicYearMonthCombo.Static, value: { year: date.getFullYear(), quarter: BI.getQuarter(date) } });
7 years ago
self.combo.hideView();
self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE,
action: function () {
var value = self.popup.getValue();
if (self._checkValue(value)) {
self.setValue(value);
}
7 years ago
self.combo.hideView();
self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM);
}
}],
behaviors: o.behaviors,
min: o.minDate,
max: o.maxDate
7 years ago
},
value: o.value || ""
}
});
7 years ago
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () {
self.popup.setMinDate(o.minDate);
self.popup.setMaxDate(o.maxDate);
7 years ago
self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW);
8 years ago
});
BI.createWidget({
type: "bi.absolute",
element: this,
7 years ago
items: [{
el: {
type: "bi.htape",
cls: (o.simple ? "bi-border-bottom" : "bi-border") + " bi-border-radius bi-focus-shadow",
7 years ago
ref: function () {
self.comboWrapper = this;
},
items: [{
el: {
type: "bi.icon_button",
cls: "bi-trigger-icon-button",
width: o.height - border,
height: o.height - border,
ref: function () {
self.changeIcon = this;
}
},
width: o.height - border
}, this.combo]
7 years ago
},
top: 0,
left: 0,
right: 0,
bottom: 0
}]
});
7 years ago
this._checkDynamicValue(o.value);
},
7 years ago
_checkDynamicValue: function (v) {
var type = null;
if (BI.isNotNull(v)) {
type = v.type;
}
switch (type) {
case BI.DynamicYearQuarterCombo.Dynamic:
this.changeIcon.setVisible(true);
this.comboWrapper.attr("items")[0].width = this.options.height - this.options.simple ? 1 : 2;
7 years ago
this.comboWrapper.resize();
break;
default:
this.comboWrapper.attr("items")[0].width = 0;
this.comboWrapper.resize();
this.changeIcon.setVisible(false);
break;
}
},
_checkValue: function (v) {
var o = this.options;
switch (v.type) {
case BI.DynamicDateCombo.Dynamic:
return BI.isNotEmptyObject(v.value);
case BI.DynamicDateCombo.Static:
var value = v.value || {};
return !BI.checkDateVoid(value.year, (value.quarter - 1) * 3 + 1, 1, o.minDate, o.maxDate)[0];
default:
return true;
}
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
this.popup && this.popup.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
this.popup && this.popup.setMaxDate(maxDate);
},
hideView: function () {
this.combo.hideView();
},
getKey: function () {
return this.trigger.getKey();
},
setValue: function (v) {
7 years ago
this.storeValue = v;
this.trigger.setValue(v);
this._checkDynamicValue(v);
},
getValue: function () {
7 years ago
return this.storeValue;
},
isStateValid: function () {
return this.trigger.isStateValid();
}
7 years ago
});
7 years ago
BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.DynamicYearQuarterCombo.EVENT_ERROR = "EVENT_ERROR";
BI.DynamicYearQuarterCombo.EVENT_VALID = "EVENT_VALID";
BI.DynamicYearQuarterCombo.EVENT_FOCUS = "EVENT_FOCUS";
7 years ago
BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo);
BI.extend(BI.DynamicYearQuarterCombo, {
Static: 1,
Dynamic: 2
});