Browse Source

Pull request #3402: KERNEL-14100 refactor: widget/yearquarter、yearquarterinterval es6化

Merge in VISUAL/fineui from ~JOKER.WANG/fineui:es6 to es6

* commit '176b402e0ba76e43385dd5060573bd466fceaef5':
  KERNEL-14100 refactor: widget/yearquarter、yearquarterinterval es6化
es6
Joker.Wang-王顺 2 years ago
parent
commit
fba4fa6212
  1. 9
      src/widget/index.js
  2. 293
      src/widget/yearquarter/card.dynamic.yearquarter.js
  3. 260
      src/widget/yearquarter/card.static.yearquarter.js
  4. 345
      src/widget/yearquarter/combo.yearquarter.js
  5. 6
      src/widget/yearquarter/index.js
  6. 437
      src/widget/yearquarter/popup.yearquarter.js
  7. 461
      src/widget/yearquarter/trigger.yearquarter.js
  8. 315
      src/widget/yearquarterinterval/yearquarterinterval.js

9
src/widget/index.js

@ -10,6 +10,7 @@ import * as editor from "./editor";
import * as downList from "./downlist";
import * as singleSliderItem from "./singleslider";
import * as intervalSliderItem from "./intervalslider";
import * as yearQuarter from "./yearquarter";
import { SelectTreeCombo } from "./selecttree/selecttree.combo";
import { SingleTreeCombo } from "./singletree/singletree.combo";
import { MultiTreeCombo } from "./multitree/multi.tree.combo";
@ -17,6 +18,7 @@ import { MultiTreeInsertCombo } from "./multitree/multi.tree.insert.combo";
import { MultiTreeListCombo } from "./multitree/multi.tree.list.combo";
import { NumberEditor } from "./numbereditor/number.editor";
import { NumberInterval } from "./numberinterval/numberinterval";
import { YearQuarterInterval } from "./yearquarterinterval/yearquarterinterval";
import * as multiselect from "./multiselect";
import * as multiselectlist from "./multiselectlist";
import * as multilayerselectree from "./multilayerselecttree";
@ -41,6 +43,7 @@ Object.assign(BI, {
...downList,
...singleSliderItem,
...intervalSliderItem,
...yearQuarter,
SelectTreeCombo,
SingleTreeCombo,
MultiTreeCombo,
@ -49,6 +52,7 @@ Object.assign(BI, {
NumberEditor,
NumberInterval,
YearInterval,
YearQuarterInterval,
...multiselect,
...multiselectlist,
...multilayerselectree,
@ -77,7 +81,7 @@ export * from "./multilayerselecttree";
export * from "./searchmultitextvaluecombo";
export * from "./singleselect";
export * from "./multilayerdownlist";
export * from "./multilayersingletree";
export * from "./yearquarter";
export {
Collapse,
@ -88,5 +92,6 @@ export {
MultiTreeCombo,
MultiTreeInsertCombo,
MultiTreeListCombo,
YearInterval
YearInterval,
YearQuarterInterval
};

293
src/widget/yearquarter/card.dynamic.yearquarter.js

@ -1,166 +1,213 @@
/**
* 年季度展示面板
*
* Created by GUY on 2015/9/2.
* @class BI.YearCard
* @extends BI.Trigger
*/
BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, {
props: {
baseCls: "bi-year-quarter-card"
},
render: function () {
var self = this;
import {
shortcut,
Widget,
i18nText,
bind,
VerticalLayout,
parseDateTime,
extend,
checkDateVoid,
isNotEmptyString,
getQuarter
} from "@/core";
import { DynamicDateCard, DynamicDateParamItem, DynamicDateHelper } from "../dynamicdate";
import { Label, Bubbles } from "@/base";
@shortcut()
export class DynamicYearQuarterCard extends Widget {
static xtype = "bi.dynamic_year_quarter_card";
props = { baseCls: "bi-year-quarter-card" };
static EVENT_CHANGE = "EVENT_CHANGE";
render() {
return {
type: "bi.vertical",
items: [{
type: "bi.label",
text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"),
textAlign: "left",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}, {
type: "bi.vertical",
ref: function (_ref) {
self.wrapper = _ref;
type: VerticalLayout.xtype,
items: [
{
type: Label.xtype,
text: i18nText("BI-Multi_Date_Relative_Current_Time"),
textAlign: "left",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
},
items: [{
el: {
type: "bi.dynamic_date_param_item",
validationChecker: BI.bind(self._checkDate, self),
ref: function () {
self.year = this;
},
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
self.fireEvent("EVENT_CHANGE");
}
}, {
eventName: "EVENT_INPUT_CHANGE",
action: function () {
BI.Bubbles.hide("dynamic-year-quarter-error");
}
}]
},
bgap: 10
}, {
type: "bi.dynamic_date_param_item",
dateType: BI.DynamicDateCard.TYPE.QUARTER,
ref: function () {
self.quarter = this;
{
type: VerticalLayout.xtype,
ref: _ref => {
this.wrapper = _ref;
},
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
self.fireEvent("EVENT_CHANGE");
}
}, {
eventName: "EVENT_INPUT_CHANGE",
action: function () {
BI.Bubbles.hide("dynamic-year-quarter-error");
items: [
{
el: {
type: DynamicDateParamItem.xtype,
validationChecker: bind(this._checkDate, this),
ref: _ref => {
this.year = _ref;
},
listeners: [
{
eventName: "EVENT_CHANGE",
action: () => {
this.fireEvent("EVENT_CHANGE");
},
},
{
eventName: "EVENT_INPUT_CHANGE",
action: () => {
Bubbles.hide(
"dynamic-year-quarter-error"
);
},
}
],
},
bgap: 10,
},
{
type: DynamicDateParamItem.xtype,
dateType: DynamicDateCard.TYPE.QUARTER,
ref: _ref => {
this.quarter = _ref;
},
listeners: [
{
eventName: "EVENT_CHANGE",
action: () => {
this.fireEvent("EVENT_CHANGE");
},
},
{
eventName: "EVENT_INPUT_CHANGE",
action: () => {
Bubbles.hide(
"dynamic-year-quarter-error"
);
},
}
],
}
}]
}]
}],
],
}
],
vgap: 10,
hgap: 10
hgap: 10,
};
},
}
_getErrorText: function () {
var o = this.options;
var start = BI.parseDateTime(o.min, "%Y-%X-%d");
var end = BI.parseDateTime(o.max, "%Y-%X-%d");
return BI.i18nText("BI-Basic_Year_Quarter_Range_Error",
_getErrorText() {
const o = this.options;
const start = parseDateTime(o.min, "%Y-%X-%d");
const end = parseDateTime(o.max, "%Y-%X-%d");
return i18nText(
"BI-Basic_Year_Quarter_Range_Error",
start.getFullYear(),
BI.getQuarter(start),
getQuarter(start),
end.getFullYear(),
BI.getQuarter(end)
getQuarter(end)
);
},
}
_checkDate: function (obj) {
var o = this.options;
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this._getValue(), this._digestDateTypeValue(obj)));
_checkDate(obj) {
const o = this.options;
const date = DynamicDateHelper.getCalculation(
extend(this._getValue(), this._digestDateTypeValue(obj))
);
return !BI.checkDateVoid(date.getFullYear(), date.getMonth() + 1, date.getDate(), o.min, o.max)[0];
},
return !checkDateVoid(
date.getFullYear(),
date.getMonth() + 1,
date.getDate(),
o.min,
o.max
)[0];
}
_digestDateTypeValue: function (value) {
var valueMap = {};
_digestDateTypeValue(value) {
const valueMap = {};
switch (value.dateType) {
case BI.DynamicDateCard.TYPE.YEAR:
valueMap.year = (value.offset === 0 ? -value.value : +value.value);
break;
case BI.DynamicDateCard.TYPE.QUARTER:
valueMap.quarter = (value.offset === 0 ? -value.value : +value.value);
break;
default:
break;
case DynamicDateCard.TYPE.YEAR:
valueMap.year =
value.offset === 0 ? -value.value : +value.value;
break;
case DynamicDateCard.TYPE.QUARTER:
valueMap.quarter =
value.offset === 0 ? -value.value : +value.value;
break;
default:
break;
}
return valueMap;
},
}
_createValue: function (type, v) {
_createValue(type, v) {
return {
dateType: type,
value: Math.abs(v),
offset: v > 0 ? 1 : 0
offset: v > 0 ? 1 : 0,
};
},
}
setMinDate: function(minDate) {
if (BI.isNotEmptyString(this.options.min)) {
setMinDate(minDate) {
if (isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
}
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
setMaxDate(maxDate) {
if (isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
}
setValue: function (v) {
v = v || {year: 0, quarter: 0};
this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year));
this.quarter.setValue(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter));
},
setValue(v) {
v = v || { year: 0, quarter: 0 };
this.year.setValue(
this._createValue(DynamicDateCard.TYPE.YEAR, v.year)
);
this.quarter.setValue(
this._createValue(DynamicDateCard.TYPE.QUARTER, v.quarter)
);
}
_getValue: function () {
var year = this.year.getValue();
var quarter = this.quarter.getValue();
_getValue() {
const year = this.year.getValue();
const quarter = this.quarter.getValue();
return {
year: (year.offset === 0 ? -year.value : year.value),
quarter: (quarter.offset === 0 ? -quarter.value : quarter.value)
year: year.offset === 0 ? -year.value : year.value,
quarter: quarter.offset === 0 ? -quarter.value : quarter.value,
};
},
}
getInputValue: function () {
getInputValue() {
return this._getValue();
},
}
getValue: function () {
getValue() {
return this.checkValidation() ? this._getValue() : {};
},
}
checkValidation: function (show) {
var errorText;
var yearInvalid = !this.year.checkValidation();
var quarterInvalid = !this.quarter.checkValidation();
var invalid = yearInvalid || quarterInvalid;
checkValidation(show) {
let errorText;
const yearInvalid = !this.year.checkValidation();
const quarterInvalid = !this.quarter.checkValidation();
let invalid = yearInvalid || quarterInvalid;
if (invalid) {
errorText = BI.i18nText("BI-Please_Input_Natural_Number");
errorText = i18nText("BI-Please_Input_Natural_Number");
} else {
invalid = !this._checkDate(this._getValue());
errorText = this._getErrorText();
}
invalid && show && BI.Bubbles.show("dynamic-year-quarter-error", errorText, this.wrapper);
invalid &&
show &&
Bubbles.show(
"dynamic-year-quarter-error",
errorText,
this.wrapper
);
return !invalid;
},
});
BI.DynamicYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.dynamic_year_quarter_card", BI.DynamicYearQuarterCard);
}
}

260
src/widget/yearquarter/card.static.yearquarter.js

@ -1,152 +1,190 @@
BI.StaticYearQuarterCard = BI.inherit(BI.Widget, {
import {
shortcut,
Widget,
map,
extend,
VerticalLayout,
parseDateTime,
parseInt,
each,
checkDateVoid,
getDate,
getQuarterName,
getQuarter
} from "@/core";
import { TextItem, ButtonGroup } from "@/base";
import { YearPicker } from "../date/calendar";
props: {
baseCls: "bi-static-year-quarter-card",
behaviors: {}
},
@shortcut()
export class StaticYearQuarterCard extends Widget {
static xtype = "bi.static_year_quarter_card";
_createQuarter: function () {
var self = this;
var items = [{
text: BI.getQuarterName(1),
value: 1
}, {
text: BI.getQuarterName(2),
value: 2
}, {
text: BI.getQuarterName(3),
value: 3
}, {
text: BI.getQuarterName(4),
value: 4
}];
return BI.map(items, function (j, item) {
return BI.extend(item, {
type: "bi.text_item",
cls: "bi-border-radius bi-list-item-select",
textAlign: "center",
whiteSpace: "nowrap",
once: false,
forceSelected: true,
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
ref: function (_ref) {
self.quarterMap[j + 1] = _ref;
}
});
});
},
props = { baseCls: "bi-static-year-quarter-card", behaviors: {} };
static EVENT_CHANGE = "EVENT_CHANGE";
_createQuarter() {
const items = [
{
text: getQuarterName(1),
value: 1,
},
{
text: getQuarterName(2),
value: 2,
},
{
text: getQuarterName(3),
value: 3,
},
{
text: getQuarterName(4),
value: 4,
}
];
return map(items, (j, item) => extend(item, {
type: TextItem.xtype,
cls: "bi-border-radius bi-list-item-select",
textAlign: "center",
whiteSpace: "nowrap",
once: false,
forceSelected: true,
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
ref: _ref => {
this.quarterMap[j + 1] = _ref;
},
}));
}
render: function () {
var self = this, o = this.options;
render() {
const o = this.options;
this.quarterMap = {};
return {
type: "bi.vertical",
items: [{
type: "bi.year_picker",
cls: "bi-split-bottom",
ref: function () {
self.yearPicker = this;
},
min: o.min,
max: o.max,
behaviors: o.behaviors,
height: 30,
listeners: [{
eventName: BI.YearPicker.EVENT_CHANGE,
action: function () {
var value = this.getValue();
self._checkQuarterStatus(value);
self.setValue({
year: value,
quarter: self.selectedQuarter
});
}
}]
}, {
el: {
type: "bi.button_group",
behaviors: o.behaviors,
ref: function () {
self.quarter = this;
type: VerticalLayout.xtype,
items: [
{
type: YearPicker.xtype,
cls: "bi-split-bottom",
ref: _ref => {
this.yearPicker = _ref;
},
items: this._createQuarter(),
layouts: [{
type: "bi.vertical",
vgap: 10,
hgap: 12,
}],
value: o.value,
listeners: [{
eventName: BI.ButtonGroup.EVENT_CHANGE,
action: function () {
self.selectedYear = self.yearPicker.getValue();
self.selectedQuarter = this.getValue()[0];
self.fireEvent(BI.StaticYearQuarterCard.EVENT_CHANGE);
min: o.min,
max: o.max,
behaviors: o.behaviors,
height: 30,
listeners: [
{
eventName: YearPicker.EVENT_CHANGE,
action: () => {
const value = this.yearPicker.getValue();
this._checkQuarterStatus(value);
this.setValue({
year: value,
quarter: this.selectedQuarter,
});
},
}
}]
],
},
vgap: 5
}]
{
el: {
type: ButtonGroup.xtype,
behaviors: o.behaviors,
ref: _ref => {
this.quarter = _ref;
},
items: this._createQuarter(),
layouts: [
{
type: VerticalLayout.xtype,
vgap: 10,
hgap: 12,
}
],
value: o.value,
listeners: [
{
eventName: ButtonGroup.EVENT_CHANGE,
action: () => {
this.selectedYear =
this.yearPicker.getValue();
this.selectedQuarter = this.quarter.getValue()[0];
this.fireEvent(
StaticYearQuarterCard.EVENT_CHANGE
);
},
}
],
},
vgap: 5,
}
],
};
},
}
_checkQuarterStatus: function (year) {
var o = this.options;
var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"), maxDate = BI.parseDateTime(o.max, "%Y-%X-%d");
var minYear = minDate.getFullYear(), maxYear = maxDate.getFullYear();
var minQuarter = 1; var maxQuarter = 4;
minYear === year && (minQuarter = BI.parseInt(BI.getQuarter(minDate)));
maxYear === year && (maxQuarter = BI.parseInt(BI.getQuarter(maxDate)));
var yearInvalid = year < minYear || year > maxYear;
BI.each(this.quarterMap, function (quarter, obj) {
var quarterInvalid = quarter < minQuarter || quarter > maxQuarter;
_checkQuarterStatus(year) {
const o = this.options;
const minDate = parseDateTime(o.min, "%Y-%X-%d"),
maxDate = parseDateTime(o.max, "%Y-%X-%d");
const minYear = minDate.getFullYear(),
maxYear = maxDate.getFullYear();
let minQuarter = 1;
let maxQuarter = 4;
minYear === year && (minQuarter = parseInt(getQuarter(minDate)));
maxYear === year && (maxQuarter = parseInt(getQuarter(maxDate)));
const yearInvalid = year < minYear || year > maxYear;
each(this.quarterMap, (quarter, obj) => {
const quarterInvalid = quarter < minQuarter || quarter > maxQuarter;
obj.setEnable(!yearInvalid && !quarterInvalid);
});
},
}
setMinDate: function (minDate) {
setMinDate(minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.yearPicker.setMinDate(minDate);
this._checkQuarterStatus(this.selectedYear);
}
},
}
setMaxDate: function (maxDate) {
setMaxDate(maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.yearPicker.setMaxDate(maxDate);
this._checkQuarterStatus(this.selectedYear);
}
},
}
getValue: function () {
getValue() {
return {
year: this.selectedYear,
quarter: this.selectedQuarter
quarter: this.selectedQuarter,
};
},
}
setValue: function (obj) {
var o = this.options;
var newObj = {};
setValue(obj) {
const o = this.options;
const newObj = {};
newObj.year = obj.year || 0;
newObj.quarter = obj.quarter || 0;
if (newObj.quarter === 0 || newObj.year === 0 || BI.checkDateVoid(newObj.year, newObj.quarter, 1, o.min, o.max)[0]) {
var year = newObj.year || BI.getDate().getFullYear();
if (
newObj.quarter === 0 ||
newObj.year === 0 ||
checkDateVoid(newObj.year, newObj.quarter, 1, o.min, o.max)[0]
) {
const year = newObj.year || getDate().getFullYear();
this.selectedYear = year;
this.selectedQuarter = "";
this.yearPicker.setValue(year);
this.quarter.setValue();
} else {
this.selectedYear = BI.parseInt(newObj.year);
this.selectedQuarter = BI.parseInt(newObj.quarter);
this.selectedYear = parseInt(newObj.year);
this.selectedQuarter = parseInt(newObj.quarter);
this.yearPicker.setValue(this.selectedYear);
this.quarter.setValue(this.selectedQuarter);
}
this._checkQuarterStatus(this.selectedYear);
}
});
BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);
}

345
src/widget/yearquarter/combo.yearquarter.js

@ -1,72 +1,102 @@
BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
import {
shortcut,
Widget,
createWidget,
toPix,
isEqual,
isNotEmptyString,
getDate,
AbsoluteLayout,
HorizontalFillLayout,
isNotNull,
isNotEmptyObject,
checkDateVoid,
getQuarter
} from "@/core";
import { DynamicYearQuarterTrigger } from "./trigger.yearquarter";
// TODO:需要等待yearmonth完成才能将BI.DynamicYearMonthTrigger替换
// import { DynamicYearMonthCombo } from "../yearmonth/combo.yearmonth";
import { DynamicYearQuarterPopup } from "./popup.yearquarter";
import { DynamicDateCombo } from "../dynamicdate";
import { Combo, IconButton } from "@/base";
_consts: {
iconWidth: 24
},
props: {
@shortcut()
export class DynamicYearQuarterCombo extends Widget {
static xtype = "bi.dynamic_year_quarter_combo";
_consts = { iconWidth: 24 };
props = {
baseCls: "bi-year-quarter-combo",
behaviors: {},
minDate: "1900-01-01", // 最小日期
maxDate: "2099-12-31", // 最大日期
minDate: "1900-01-01",
maxDate: "2099-12-31",
height: 24,
supportDynamic: true,
isNeedAdjustHeight: false,
isNeedAdjustWidth: false
},
isNeedAdjustWidth: false,
};
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
static EVENT_ERROR = "EVENT_ERROR";
static EVENT_VALID = "EVENT_VALID";
static EVENT_FOCUS = "EVENT_FOCUS";
static Static = 1;
static Dynamic = 2;
_init: function () {
var self = this, o = this.options;
BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments);
_init() {
const o = this.options;
super._init(...arguments);
this.storeValue = o.value;
var border = o.simple ? 1 : 2;
self.storeTriggerValue = "";
this.trigger = BI.createWidget({
const border = o.simple ? 1 : 2;
this.storeTriggerValue = "";
this.trigger = createWidget({
type: "bi.dynamic_year_quarter_trigger",
simple: o.simple,
min: o.minDate,
max: o.maxDate,
height: BI.toPix(o.height, border),
height: toPix(o.height, border),
value: o.value || "",
watermark: o.watermark,
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_KEY_DOWN, function () {
self.combo.isViewVisible() && self.combo.hideView();
this.trigger.on(DynamicYearQuarterTrigger.EVENT_KEY_DOWN, () => {
this.combo.isViewVisible() && this.combo.hideView();
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () {
self.combo.isViewVisible() && self.combo.hideView();
this.trigger.on(DynamicYearQuarterTrigger.EVENT_START, () => {
this.combo.isViewVisible() && this.combo.hideView();
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () {
self.combo.showView();
this.trigger.on(DynamicYearQuarterTrigger.EVENT_STOP, () => {
this.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(DynamicYearQuarterTrigger.EVENT_ERROR, () => {
this.combo.isViewVisible() && this.combo.hideView();
this.comboWrapper.element.addClass("error");
this.fireEvent(DynamicYearQuarterCombo.EVENT_ERROR);
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_VALID, function () {
self.comboWrapper.element.removeClass("error");
self.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID);
this.trigger.on(DynamicYearQuarterTrigger.EVENT_VALID, () => {
this.comboWrapper.element.removeClass("error");
this.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID);
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () {
var dateStore = self.storeTriggerValue;
var dateObj = self.trigger.getKey();
if (BI.isEqual(dateObj, dateStore)) {
this.trigger.on(DynamicYearQuarterTrigger.EVENT_CONFIRM, () => {
const dateStore = this.storeTriggerValue;
const dateObj = this.trigger.getKey();
if (isEqual(dateObj, dateStore)) {
return;
}
if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) {
self.storeValue = self.trigger.getValue();
self.setValue(self.trigger.getValue());
if (isNotEmptyString(dateObj) && !isEqual(dateObj, dateStore)) {
this.storeValue = this.trigger.getValue();
this.setValue(this.trigger.getValue());
}
self._checkDynamicValue(self.storeValue);
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM);
this._checkDynamicValue(this.storeValue);
this.fireEvent(DynamicYearQuarterCombo.EVENT_CONFIRM);
});
this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_FOCUS, function () {
self.storeTriggerValue = self.trigger.getKey();
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_FOCUS);
this.trigger.on(DynamicYearQuarterTrigger.EVENT_FOCUS, () => {
this.storeTriggerValue = this.trigger.getKey();
this.fireEvent(DynamicYearQuarterCombo.EVENT_FOCUS);
});
this.combo = BI.createWidget({
type: "bi.combo",
this.combo = createWidget({
type: Combo.xtype,
container: o.container,
isNeedAdjustHeight: o.isNeedAdjustHeight,
isNeedAdjustWidth: o.isNeedAdjustWidth,
@ -80,172 +110,185 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
type: "bi.dynamic_year_quarter_popup",
width: o.isNeedAdjustWidth ? o.width : undefined,
supportDynamic: o.supportDynamic,
ref: function () {
self.popup = this;
ref: _ref => {
this.popup = _ref;
},
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.comboWrapper.element.removeClass("error");
self.combo.hideView();
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM);
}
}, {
eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE,
action: function () {
var date = BI.getDate();
self.setValue({
eventName: DynamicYearQuarterPopup.EVENT_CHANGE,
action: () => {
this.setValue(this.popup.getValue());
this.combo.hideView();
this.fireEvent(
DynamicYearQuarterCombo.EVENT_CONFIRM
);
},
},
{
eventName:
DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE,
action: () => {
this.setValue();
this.comboWrapper.element.removeClass("error");
this.combo.hideView();
this.fireEvent(
DynamicYearQuarterCombo.EVENT_CONFIRM
);
},
},
{
eventName:
DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE,
action: () => {
const date = getDate();
this.setValue({
type: BI.DynamicYearMonthCombo.Static,
value: { year: date.getFullYear(), quarter: BI.getQuarter(date) }
value: {
year: date.getFullYear(),
quarter: getQuarter(date),
},
});
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);
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
},
{
eventName:
DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE,
action: () => {
const value = this.popup.getValue();
if (this._checkValue(value)) {
this.setValue(value);
}
self.combo.hideView();
self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM);
}
this.combo.hideView();
this.fireEvent(DynamicDateCombo.EVENT_CONFIRM);
},
}
],
behaviors: o.behaviors,
min: o.minDate,
max: o.maxDate
max: o.maxDate,
},
value: o.value || ""
}
value: o.value || "",
},
});
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () {
self.popup.setMinDate(o.minDate);
self.popup.setMaxDate(o.maxDate);
self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW);
this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => {
this.popup.setMinDate(o.minDate);
this.popup.setMaxDate(o.maxDate);
this.popup.setValue(this.storeValue);
this.fireEvent(DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW);
});
BI.createWidget({
type: "bi.absolute",
createWidget({
type: AbsoluteLayout.xtype,
element: this,
items: [
{
el: {
type: "bi.horizontal_fill",
type: HorizontalFillLayout.xtype,
columnSize: ["", "fill"],
cls: (o.simple ? "bi-border-bottom" : "bi-border bi-border-radius") + " bi-focus-shadow",
ref: function () {
self.comboWrapper = this;
cls:
`${o.simple
? "bi-border-bottom"
: "bi-border bi-border-radius"
} bi-focus-shadow`,
ref: _ref => {
this.comboWrapper = _ref;
},
items: [
{
el: {
type: "bi.icon_button",
type: IconButton.xtype,
cls: "bi-trigger-icon-button date-change-h-font",
width: this._consts.iconWidth,
height: BI.toPix(o.height, border),
ref: function () {
self.changeIcon = this;
}
}
}, this.combo
]
height: toPix(o.height, border),
ref: _ref => {
this.changeIcon = _ref;
},
},
},
this.combo
],
},
top: 0,
left: 0,
right: 0,
bottom: 0
bottom: 0,
}
]
],
});
this._checkDynamicValue(o.value);
},
}
_checkDynamicValue: function (v) {
var type = null;
if (BI.isNotNull(v)) {
_checkDynamicValue(v) {
let type = null;
if (isNotNull(v)) {
type = v.type;
}
switch (type) {
case BI.DynamicYearQuarterCombo.Dynamic:
this.changeIcon.setVisible(true);
break;
default:
this.changeIcon.setVisible(false);
break;
case DynamicYearQuarterCombo.Dynamic:
this.changeIcon.setVisible(true);
break;
default:
this.changeIcon.setVisible(false);
break;
}
},
}
_checkValue: function (v) {
var o = this.options;
_checkValue(v) {
const o = this.options;
let value;
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;
case DynamicDateCombo.Dynamic:
return isNotEmptyObject(v.value);
case DynamicDateCombo.Static:
value = v.value || {};
return !checkDateVoid(
value.year,
(value.quarter - 1) * 3 + 1,
1,
o.minDate,
o.maxDate
)[0];
default:
return true;
}
},
}
setMinDate: function (minDate) {
var o = this.options;
setMinDate(minDate) {
const o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
this.popup && this.popup.setMinDate(minDate);
},
}
setMaxDate: function (maxDate) {
var o = this.options;
setMaxDate(maxDate) {
const o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
this.popup && this.popup.setMaxDate(maxDate);
},
}
hideView: function () {
hideView() {
this.combo.hideView();
},
}
getKey: function () {
getKey() {
return this.trigger.getKey();
},
}
setValue: function (v) {
setValue(v) {
this.storeValue = v;
this.trigger.setValue(v);
this._checkDynamicValue(v);
},
}
getValue: function () {
getValue() {
return this.storeValue;
},
}
isStateValid: function () {
isStateValid() {
return this.trigger.isStateValid();
}
});
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";
BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo);
BI.extend(BI.DynamicYearQuarterCombo, {
Static: 1,
Dynamic: 2
});
}

6
src/widget/yearquarter/index.js

@ -0,0 +1,6 @@
export { DynamicYearQuarterCard } from "./card.dynamic.yearquarter";
export { StaticYearQuarterCard } from "./card.static.yearquarter";
export { DynamicYearQuarterCombo } from "./combo.yearquarter";
export { DynamicYearQuarterPopup } from "./popup.yearquarter";
export { DynamicYearQuarterTrigger } from "./trigger.yearquarter";

437
src/widget/yearquarter/popup.yearquarter.js

@ -1,235 +1,328 @@
BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, {
constants: {
tabHeight: 40,
buttonHeight: 24
},
import {
shortcut,
Widget,
toPix,
i18nText,
VerticalLayout,
GridLayout,
print,
getDate,
checkDateVoid,
createItems,
getQuarter
} from "@/core";
import { DynamicYearQuarterCombo } from "./combo.yearquarter";
import { TextButton, Tab } from "@/base";
import { DynamicDateCombo, DynamicDatePopup, DynamicDateHelper } from "../dynamicdate";
// TODO:需要等待year完成才能将BI.DynamicYearCard替换
// import { DynamicYearCard } from "../year/card.dynamic.year";
import { LinearSegment } from "@/case";
import { DynamicYearQuarterCard } from "./card.dynamic.yearquarter";
import { StaticYearQuarterCard } from "./card.static.yearquarter";
props: {
@shortcut()
export class DynamicYearQuarterPopup extends Widget {
static xtype = "bi.dynamic_year_quarter_popup";
constants = { tabHeight: 40, buttonHeight: 24 };
props = {
baseCls: "bi-year-quarter-popup",
behaviors: {},
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期,
min: "1900-01-01",
max: "2099-12-31",
width: 180,
supportDynamic: true,
},
};
static BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE";
static BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE";
static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE";
static EVENT_CHANGE = "EVENT_CHANGE";
render: function () {
var self = this, opts = this.options, c = this.constants;
this.storeValue = {type: BI.DynamicYearQuarterCombo.Static};
render() {
this.storeValue = { type: DynamicYearQuarterCombo.Static };
return {
type: "bi.vertical",
items: [{
el: this._getTabJson()
}, {
el: {
type: "bi.grid",
items: [[{
type: "bi.text_button",
cls: "bi-split-top bi-high-light",
shadow: true,
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
text: BI.i18nText("BI-Basic_Clear"),
listeners: [{
eventName: BI.TextButton.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE);
}
}]
}, {
type: "bi.text_button",
cls: "bi-split-left bi-split-right bi-high-light bi-split-top",
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
shadow: true,
text: BI.i18nText("BI-Basic_Current_Quarter"),
disabled: this._checkTodayValid(),
ref: function () {
self.textButton = this;
},
listeners: [{
eventName: BI.TextButton.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE);
}
}]
}, {
type: "bi.text_button",
cls: "bi-split-top bi-high-light",
shadow: true,
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1),
text: BI.i18nText("BI-Basic_OK"),
listeners: [{
eventName: BI.TextButton.EVENT_CHANGE,
action: function () {
var type = self.dateTab.getSelect();
if (type === BI.DynamicDateCombo.Dynamic) {
self.dynamicPane.checkValidation(true) && self.fireEvent(BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE);
} else {
self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE);
}
}
}]
}]],
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT
type: VerticalLayout.xtype,
items: [
{
el: this._getTabJson(),
},
}]
{
el: {
type: GridLayout.xtype,
items: [
[
{
type: TextButton.xtype,
cls: "bi-split-top bi-high-light",
shadow: true,
textHeight: toPix(
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
1
),
text: i18nText("BI-Basic_Clear"),
listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
this.fireEvent(
DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE
);
},
}
],
},
{
type: TextButton.xtype,
cls: "bi-split-left bi-split-right bi-high-light bi-split-top",
textHeight: toPix(
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
1
),
shadow: true,
text: i18nText("BI-Basic_Current_Quarter"),
disabled: this._checkTodayValid(),
ref: _ref => {
this.textButton = _ref;
},
listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
this.fireEvent(
DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE
);
},
}
],
},
{
type: TextButton.xtype,
cls: "bi-split-top bi-high-light",
shadow: true,
textHeight: toPix(
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
1
),
text: i18nText("BI-Basic_OK"),
listeners: [
{
eventName: TextButton.EVENT_CHANGE,
action: () => {
const type =
this.dateTab.getSelect();
if (
type ===
DynamicDateCombo.Dynamic
) {
this.dynamicPane.checkValidation(
true
) &&
this.fireEvent(
DynamicDatePopup.BUTTON_OK_EVENT_CHANGE
);
} else {
this.fireEvent(DynamicYearQuarterPopup
.BUTTON_OK_EVENT_CHANGE
);
}
},
}
],
}
]
],
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT,
},
}
],
};
},
}
_setInnerValue: function () {
if (this.dateTab.getSelect() === BI.DynamicYearQuarterCombo.Static) {
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter"));
_setInnerValue() {
if (this.dateTab.getSelect() === DynamicYearQuarterCombo.Static) {
this.textButton.setValue(i18nText("BI-Basic_Current_Quarter"));
this.textButton.setEnable(!this._checkTodayValid());
} else {
var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getInputValue());
date = BI.print(date, "%Y-%Q");
let date = DynamicDateHelper.getCalculation(
this.dynamicPane.getInputValue()
);
date = print(date, "%Y-%Q");
this.textButton.setValue(date);
this.textButton.setEnable(false);
}
},
}
_checkTodayValid: function () {
var o = this.options;
var today = BI.getDate();
return !!BI.checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0];
},
_checkTodayValid() {
const o = this.options;
const today = getDate();
return !!checkDateVoid(
today.getFullYear(),
today.getMonth() + 1,
today.getDate(),
o.min,
o.max
)[0];
}
_getTabJson: function () {
var self = this, o = this.options;
_getTabJson() {
const o = this.options;
return {
type: "bi.tab",
type: Tab.xtype,
logic: {
dynamic: true
dynamic: true,
},
ref: function () {
self.dateTab = this;
ref: _ref => {
this.dateTab = _ref;
},
tab: {
type: "bi.linear_segment",
type: LinearSegment.xtype,
cls: "bi-split-bottom",
invisible: !o.supportDynamic,
height: this.constants.tabHeight,
items: BI.createItems([{
text: BI.i18nText("BI-Basic_Year_Quarter"),
value: BI.DynamicYearQuarterCombo.Static
}, {
text: BI.i18nText("BI-Basic_Dynamic_Title"),
value: BI.DynamicYearQuarterCombo.Dynamic
}], {
textAlign: "center"
})
items: createItems(
[
{
text: i18nText("BI-Basic_Year_Quarter"),
value: DynamicYearQuarterCombo.Static,
},
{
text: i18nText("BI-Basic_Dynamic_Title"),
value: DynamicYearQuarterCombo.Dynamic,
}
],
{
textAlign: "center",
}
),
},
cardCreator: function (v) {
cardCreator: v => {
switch (v) {
case BI.DynamicYearQuarterCombo.Dynamic:
return {
type: "bi.dynamic_year_quarter_card",
cls: "dynamic-year-quarter-pane",
min: self.options.min,
max: self.options.max,
listeners: [{
case DynamicYearQuarterCombo.Dynamic:
return {
type: DynamicYearQuarterCard.xtype,
cls: "dynamic-year-quarter-pane",
min: this.options.min,
max: this.options.max,
listeners: [
{
eventName: "EVENT_CHANGE",
action: function () {
self._setInnerValue(self.year, v);
}
}],
ref: function () {
self.dynamicPane = this;
action: () => {
this._setInnerValue(this.year, v);
},
}
};
case BI.DynamicYearQuarterCombo.Static:
default:
return {
type: "bi.static_year_quarter_card",
behaviors: o.behaviors,
min: self.options.min,
max: self.options.max,
listeners: [{
],
ref: _ref => {
this.dynamicPane = _ref;
},
};
case DynamicYearQuarterCombo.Static:
default:
return {
type: StaticYearQuarterCard.xtype,
behaviors: o.behaviors,
min: this.options.min,
max: this.options.max,
listeners: [
{
eventName: BI.DynamicYearCard.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE);
}
}],
ref: function () {
self.year = this;
action: () => {
this.fireEvent(
DynamicYearQuarterPopup.EVENT_CHANGE
);
},
}
};
],
ref: _ref => {
this.year = _ref;
},
};
}
},
listeners: [{
eventName: BI.Tab.EVENT_CHANGE,
action: function () {
var v = self.dateTab.getSelect();
switch (v) {
case BI.DynamicYearQuarterCombo.Static:
var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue());
self.year.setValue({year: date.getFullYear(), quarter: BI.getQuarter(date)});
self._setInnerValue();
listeners: [
{
eventName: Tab.EVENT_CHANGE,
action: () => {
const v = this.dateTab.getSelect();
let date;
switch (v) {
case DynamicYearQuarterCombo.Static:
date = DynamicDateHelper.getCalculation(
this.dynamicPane.getValue()
);
this.year.setValue({
year: date.getFullYear(),
quarter: getQuarter(date),
});
this._setInnerValue();
break;
case BI.DynamicYearQuarterCombo.Dynamic:
case DynamicYearQuarterCombo.Dynamic:
default:
if(self.storeValue && self.storeValue.type === BI.DynamicYearQuarterCombo.Dynamic) {
self.dynamicPane.setValue(self.storeValue.value);
}else{
self.dynamicPane.setValue({
year: 0
if (
this.storeValue &&
this.storeValue.type ===
DynamicYearQuarterCombo.Dynamic
) {
this.dynamicPane.setValue(
this.storeValue.value
);
} else {
this.dynamicPane.setValue({
year: 0,
});
}
self._setInnerValue();
this._setInnerValue();
break;
}
}
},
}
}]
],
};
},
}
setMinDate: function (minDate) {
setMinDate(minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.year && this.year.setMinDate(minDate);
this.dynamicPane && this.dynamicPane.setMinDate(minDate);
}
},
}
setMaxDate: function (maxDate) {
setMaxDate(maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.year && this.year.setMaxDate(maxDate);
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate);
}
},
}
setValue: function (v) {
setValue(v) {
this.storeValue = v;
var self = this;
var type, value;
v = v || {};
type = v.type || BI.DynamicDateCombo.Static;
value = v.value || v;
const type = v.type || DynamicDateCombo.Static;
const value = v.value || v;
this.dateTab.setSelect(type);
switch (type) {
case BI.DynamicDateCombo.Dynamic:
this.dynamicPane.setValue(value);
self._setInnerValue();
break;
case BI.DynamicDateCombo.Static:
default:
this.year.setValue(value);
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter"));
this.textButton.setEnable(!this._checkTodayValid());
break;
case DynamicDateCombo.Dynamic:
this.dynamicPane.setValue(value);
this._setInnerValue();
break;
case DynamicDateCombo.Static:
default:
this.year.setValue(value);
this.textButton.setValue(i18nText("BI-Basic_Current_Quarter"));
this.textButton.setEnable(!this._checkTodayValid());
break;
}
},
}
getValue: function () {
getValue() {
return {
type: this.dateTab.getSelect(),
value: this.dateTab.getValue()
value: this.dateTab.getValue(),
};
}
});
BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE";
BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE";
BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE";
BI.DynamicYearQuarterPopup.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.dynamic_year_quarter_popup", BI.DynamicYearQuarterPopup);
}

461
src/widget/yearquarter/trigger.yearquarter.js

@ -1,277 +1,374 @@
BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, {
_const: {
hgap: 4,
vgap: 2,
iconWidth: 24
},
import {
shortcut,
i18nText,
createWidget,
HTapeLayout,
CenterLayout,
HorizontalFillLayout,
isEmptyString,
parseDateTime,
isPositiveInteger,
checkDateVoid,
isNotEmptyString,
isNotNull,
print,
checkDateLegal,
isNull,
parseInt,
getDate,
getQuarter
} from "@/core";
import { Trigger, TextButton } from "@/base";
import { TriggerIconButton, SignEditor } from "@/case";
import { DynamicDateHelper } from "../dynamicdate";
// TODO:需要等待yearmonth完成才能将BI.DynamicYearMonthTrigger替换
// import { DynamicYearMonthTrigger } from "../yearmonth/trigger.yearmonth";
import { DynamicYearQuarterCombo } from "./combo.yearquarter";
props: () => ({
extraCls: "bi-year-quarter-trigger",
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期
height: 24,
watermark: {
year: BI.i18nText("BI-Basic_Unrestricted"),
quarter: BI.i18nText("BI-Basic_Unrestricted"),
},
}),
@shortcut()
export class DynamicYearQuarterTrigger extends Trigger {
static xtype = "bi.dynamic_year_quarter_trigger";
_init: function () {
BI.DynamicYearQuarterTrigger.superclass._init.apply(this, arguments);
var o = this.options;
_const = { hgap: 4, vgap: 2, iconWidth: 24 };
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_ERROR = "EVENT_ERROR";
static EVENT_START = "EVENT_START";
static EVENT_CONFIRM = "EVENT_CONFIRM";
static EVENT_STOP = "EVENT_STOP";
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
static EVENT_VALID = "EVENT_VALID";
props() {
return {
extraCls: "bi-year-quarter-trigger",
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期
height: 24,
watermark: {
year: i18nText("BI-Basic_Unrestricted"),
quarter: i18nText("BI-Basic_Unrestricted"),
},
};
}
_init() {
super._init(...arguments);
const o = this.options;
this.yearEditor = this._createEditor(true);
this.quarterEditor = this._createEditor(false);
// 暂时的解决方法
var height = o.height + 2;
// const height = o.height + 2;
BI.createWidget({
createWidget({
element: this,
type: "bi.htape",
items: [{
type: "bi.center",
items: [{
type: "bi.horizontal_fill",
columnSize: ["fill", ""],
items: [this.yearEditor, {
el: {
type: "bi.text_button",
text: BI.i18nText("BI-Multi_Date_Year"),
},
}]
}, {
type: "bi.horizontal_fill",
columnSize: ["fill", ""],
items: [this.quarterEditor, {
el: {
type: "bi.text_button",
text: BI.i18nText("BI-Multi_Date_Quarter"),
type: HTapeLayout.xtype,
items: [
{
type: CenterLayout.xtype,
items: [
{
type: HorizontalFillLayout.xtype,
columnSize: ["fill", ""],
items: [
this.yearEditor,
{
el: {
type: TextButton.xtype,
text: i18nText("BI-Multi_Date_Year"),
},
}
],
},
}]
}]
}, {
el: {
type: "bi.trigger_icon_button",
width: this._const.iconWidth,
{
type: HorizontalFillLayout.xtype,
columnSize: ["fill", ""],
items: [
this.quarterEditor,
{
el: {
type: TextButton.xtype,
text: i18nText("BI-Multi_Date_Quarter"),
},
}
],
}
],
},
width: this._const.iconWidth,
}]
{
el: {
type: TriggerIconButton.xtype,
width: this._const.iconWidth,
},
width: this._const.iconWidth,
}
],
});
this.setValue(o.value);
},
}
_createEditor: function (isYear) {
var self = this, o = this.options, c = this._const;
var editor = BI.createWidget({
type: "bi.sign_editor",
_createEditor(isYear) {
const o = this.options,
c = this._const;
const editor = createWidget({
type: SignEditor.xtype,
simple: o.simple,
height: o.height,
validationChecker: function (v) {
if(isYear) {
var month = self.quarterEditor.getValue();
if(BI.isEmptyString(month)) {
month = parseInt(v, 10) === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear() ? BI.parseDateTime(o.min, "%Y-%X-%d").getMonth() + 1 : 1;
validationChecker: v => {
if (isYear) {
let month = this.quarterEditor.getValue();
if (isEmptyString(month)) {
month =
parseInt(v, 10) ===
parseDateTime(o.min, "%Y-%X-%d").getFullYear()
? parseDateTime(o.min, "%Y-%X-%d").getMonth() +
1
: 1;
} else {
month = (parseInt(month, 10) - 1) * 3 + 1;
}
return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, month, 1, o.min, o.max)[0]);
return (
v === "" ||
(isPositiveInteger(v) &&
!checkDateVoid(v, month, 1, o.min, o.max)[0])
);
}
var year = self.yearEditor.getValue();
const year = this.yearEditor.getValue();
return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 4) && (BI.isEmptyString(year) ? true : !BI.checkDateVoid(self.yearEditor.getValue(), (v - 1) * 3 + 1, 1, o.min, o.max)[0]));
},
quitChecker: function () {
return false;
return (
v === "" ||
(isPositiveInteger(v) &&
v >= 1 &&
v <= 4 &&
(isEmptyString(year)
? true
: !checkDateVoid(
this.yearEditor.getValue(),
(v - 1) * 3 + 1,
1,
o.min,
o.max
)[0]))
);
},
errorText: function (v) {
var year = isYear ? v : self.yearEditor.getValue();
var quarter = isYear ? self.quarterEditor.getValue() : v;
if (!BI.isPositiveInteger(year) || !BI.isPositiveInteger(quarter) || quarter > 4) {
return BI.i18nText("BI-Year_Trigger_Invalid_Text");
quitChecker: () => false,
errorText: v => {
const year = isYear ? v : this.yearEditor.getValue();
const quarter = isYear ? this.quarterEditor.getValue() : v;
if (
!isPositiveInteger(year) ||
!isPositiveInteger(quarter) ||
quarter > 4
) {
return i18nText("BI-Year_Trigger_Invalid_Text");
}
var start = BI.parseDateTime(o.min, "%Y-%X-%d");
var end = BI.parseDateTime(o.max, "%Y-%X-%d");
const start = parseDateTime(o.min, "%Y-%X-%d");
const end = parseDateTime(o.max, "%Y-%X-%d");
return BI.i18nText("BI-Basic_Year_Quarter_Range_Error",
return i18nText(
"BI-Basic_Year_Quarter_Range_Error",
start.getFullYear(),
BI.getQuarter(start),
getQuarter(start),
end.getFullYear(),
BI.getQuarter(end)
getQuarter(end)
);
},
watermark: isYear ? o.watermark?.year : o.watermark?.quarter,
hgap: c.hgap,
vgap: c.vgap,
allowBlank: true
allowBlank: true,
});
editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () {
self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_KEY_DOWN);
editor.on(SignEditor.EVENT_KEY_DOWN, () => {
this.fireEvent(DynamicYearQuarterTrigger.EVENT_KEY_DOWN);
});
editor.on(BI.SignEditor.EVENT_FOCUS, function () {
self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_FOCUS);
editor.on(SignEditor.EVENT_FOCUS, () => {
this.fireEvent(DynamicYearQuarterTrigger.EVENT_FOCUS);
});
editor.on(BI.SignEditor.EVENT_STOP, function () {
self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_STOP);
editor.on(SignEditor.EVENT_STOP, () => {
this.fireEvent(DynamicYearQuarterTrigger.EVENT_STOP);
});
editor.on(BI.SignEditor.EVENT_CONFIRM, function () {
self._doEditorConfirm(editor);
self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM);
editor.on(SignEditor.EVENT_CONFIRM, () => {
this._doEditorConfirm(editor);
this.fireEvent(DynamicYearQuarterTrigger.EVENT_CONFIRM);
});
editor.on(BI.SignEditor.EVENT_SPACE, function () {
editor.on(SignEditor.EVENT_SPACE, () => {
if (editor.isValid()) {
editor.blur();
}
});
editor.on(BI.SignEditor.EVENT_START, function () {
self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START);
editor.on(SignEditor.EVENT_START, () => {
this.fireEvent(DynamicYearQuarterTrigger.EVENT_START);
});
editor.on(BI.SignEditor.EVENT_ERROR, function () {
self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR);
editor.on(SignEditor.EVENT_ERROR, () => {
this.fireEvent(DynamicYearQuarterTrigger.EVENT_ERROR);
});
editor.on(BI.SignEditor.EVENT_VALID, function () {
var year = self.yearEditor.getValue();
var quarter = self.quarterEditor.getValue();
if(BI.isNotEmptyString(year) && BI.isNotEmptyString(quarter)) {
if(BI.isPositiveInteger(year) && quarter >= 1 && quarter <= 4 && !BI.checkDateVoid(year, (quarter - 1) * 3 + 1, 1, o.min, o.max)[0]) {
self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_VALID);
editor.on(SignEditor.EVENT_VALID, () => {
const year = this.yearEditor.getValue();
const quarter = this.quarterEditor.getValue();
if (isNotEmptyString(year) && isNotEmptyString(quarter)) {
if (
isPositiveInteger(year) &&
quarter >= 1 &&
quarter <= 4 &&
!checkDateVoid(
year,
(quarter - 1) * 3 + 1,
1,
o.min,
o.max
)[0]
) {
this.fireEvent(BI.DynamicYearMonthTrigger.EVENT_VALID);
}
}
});
editor.on(BI.SignEditor.EVENT_CHANGE, function () {
if(isYear) {
self._autoSwitch(editor);
editor.on(SignEditor.EVENT_CHANGE, () => {
if (isYear) {
this._autoSwitch(editor);
}
});
return editor;
},
}
_doEditorConfirm: function (editor) {
var value = editor.getValue();
if (BI.isNotNull(value)) {
_doEditorConfirm(editor) {
const value = editor.getValue();
if (isNotNull(value)) {
editor.setValue(value);
}
var quarterValue = this.quarterEditor.getValue();
const quarterValue = this.quarterEditor.getValue();
this.storeValue = {
type: BI.DynamicYearQuarterCombo.Static,
type: DynamicYearQuarterCombo.Static,
value: {
year: this.yearEditor.getValue(),
quarter: BI.isEmptyString(this.quarterEditor.getValue()) ? "" : quarterValue
}
quarter: isEmptyString(this.quarterEditor.getValue())
? ""
: quarterValue,
},
};
this.setTitle(this._getStaticTitle(this.storeValue.value));
},
}
_yearCheck: function (v) {
var date = BI.print(BI.parseDateTime(v, "%Y-%X-%d"), "%Y-%X-%d");
return BI.print(BI.parseDateTime(v, "%Y"), "%Y") === v && date >= this.options.min && date <= this.options.max;
},
_yearCheck(v) {
const date = print(parseDateTime(v, "%Y-%X-%d"), "%Y-%X-%d");
return (
print(parseDateTime(v, "%Y"), "%Y") === v &&
date >= this.options.min &&
date <= this.options.max
);
}
_autoSwitch: function (editor) {
var v = editor.getValue();
if (BI.isNotEmptyString(v) && BI.checkDateLegal(v)) {
_autoSwitch(editor) {
const v = editor.getValue();
if (isNotEmptyString(v) && checkDateLegal(v)) {
if (v.length === 4 && this._yearCheck(v)) {
this._doEditorConfirm(editor);
this.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM);
this.fireEvent(DynamicYearQuarterTrigger.EVENT_CONFIRM);
this.quarterEditor.focus();
}
}
},
}
_getStaticTitle: function (value) {
_getStaticTitle(value) {
value = value || {};
var hasYear = !(BI.isNull(value.year) || BI.isEmptyString(value.year));
var hasMonth = !(BI.isNull(value.quarter) || BI.isEmptyString(value.quarter));
const hasYear = !(isNull(value.year) || isEmptyString(value.year));
const hasMonth = !(isNull(value.quarter) || isEmptyString(value.quarter));
switch ((hasYear << 1) | hasMonth) {
// !hasYear && !hasMonth
case 0:
return "";
// !hasYear && !hasMonth
case 0:
return "";
// !hasYear && hasMonth
case 1:
return value.quarter;
case 1:
return value.quarter;
// hasYear && !hasMonth
case 2:
return value.year;
case 2:
return value.year;
// hasYear && hasMonth
case 3:
default:
return value.year + "-" + value.quarter;
case 3:
default:
return `${value.year}-${value.quarter}`;
}
},
}
_getText: function (obj) {
var value = "";
if(BI.isNotNull(obj.year) && BI.parseInt(obj.year) !== 0) {
value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind"));
_getText(obj) {
let value = "";
if (isNotNull(obj.year) && parseInt(obj.year) !== 0) {
value +=
Math.abs(obj.year) +
i18nText("BI-Basic_Year") +
(obj.year < 0
? i18nText("BI-Basic_Front")
: i18nText("BI-Basic_Behind"));
}
if(BI.isNotNull(obj.quarter) && BI.parseInt(obj.quarter) !== 0) {
value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Single_Quarter") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind"));
if (isNotNull(obj.quarter) && parseInt(obj.quarter) !== 0) {
value +=
Math.abs(obj.quarter) +
i18nText("BI-Basic_Single_Quarter") +
(obj.quarter < 0
? i18nText("BI-Basic_Front")
: i18nText("BI-Basic_Behind"));
}
return value;
},
}
_setInnerValue: function (date, text) {
var dateStr = BI.print(date, "%Y-%Q");
_setInnerValue(date, text) {
const dateStr = print(date, "%Y-%Q");
this.yearEditor.setValue(date.getFullYear());
this.quarterEditor.setValue(BI.getQuarter(date));
this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr));
},
this.quarterEditor.setValue(getQuarter(date));
this.setTitle(isEmptyString(text) ? dateStr : `${text}:${dateStr}`);
}
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
setMinDate(minDate) {
if (isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
}
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
setMaxDate(maxDate) {
if (isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
}
setValue: function (v) {
var type, value;
var date = BI.getDate();
setValue(v) {
let type, value, text, quarter;
let date = getDate();
this.storeValue = v;
if (BI.isNotNull(v)) {
type = v.type || BI.DynamicYearQuarterCombo.Static;
if (isNotNull(v)) {
type = v.type || DynamicYearQuarterCombo.Static;
value = v.value || v;
}
switch (type) {
case BI.DynamicYearQuarterCombo.Dynamic:
var text = this._getText(value);
date = BI.DynamicDateHelper.getCalculation(value);
this._setInnerValue(date, text);
break;
case BI.DynamicYearQuarterCombo.Static:
default:
value = value || {};
var quarter = BI.isNull(value.quarter) ? null : value.quarter;
this.yearEditor.setValue(value.year);
this.quarterEditor.setValue(quarter);
this.setTitle(this._getStaticTitle(value));
break;
case DynamicYearQuarterCombo.Dynamic:
text = this._getText(value);
date = DynamicDateHelper.getCalculation(value);
this._setInnerValue(date, text);
break;
case DynamicYearQuarterCombo.Static:
default:
value = value || {};
quarter = isNull(value.quarter) ? null : value.quarter;
this.yearEditor.setValue(value.year);
this.quarterEditor.setValue(quarter);
this.setTitle(this._getStaticTitle(value));
break;
}
},
}
getValue: function () {
getValue() {
return this.storeValue;
},
}
getKey: function () {
return this.yearEditor.getValue() + "-" + this.quarterEditor.getValue();
},
getKey() {
return `${this.yearEditor.getValue()}-${this.quarterEditor.getValue()}`;
}
isStateValid: function () {
isStateValid() {
return this.yearEditor.isValid() && this.quarterEditor.isValid();
}
});
BI.DynamicYearQuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS";
BI.DynamicYearQuarterTrigger.EVENT_ERROR = "EVENT_ERROR";
BI.DynamicYearQuarterTrigger.EVENT_START = "EVENT_START";
BI.DynamicYearQuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.DynamicYearQuarterTrigger.EVENT_STOP = "EVENT_STOP";
BI.DynamicYearQuarterTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
BI.DynamicYearQuarterTrigger.EVENT_VALID = "EVENT_VALID";
BI.shortcut("bi.dynamic_year_quarter_trigger", BI.DynamicYearQuarterTrigger);
}

315
src/widget/yearquarterinterval/yearquarterinterval.js

@ -1,193 +1,248 @@
/**
* @author windy
* @version 2.0
* Created by windy on 2021/1/25
*/
BI.YearQuarterInterval = BI.inherit(BI.Single, {
constants: {
import {
shortcut,
HorizontalFillLayout,
createWidget,
i18nText,
print,
parseDateTime,
checkDateVoid,
isNotNull,
checkDateLegal
} from "@/core";
import { Single, Label, Bubbles } from "@/base";
import { DynamicYearQuarterCombo } from "../yearquarter";
@shortcut()
export class YearQuarterInterval extends Single {
static xtype = "bi.year_quarter_interval";
constants = {
height: 24,
width: 25,
lgap: 15,
offset: -15,
timeErrorCls: "time-error"
},
props: {
timeErrorCls: "time-error",
};
props = {
extraCls: "bi-year-quarter-interval",
minDate: "1900-01-01",
maxDate: "2099-12-31",
supportDynamic: true,
},
};
static EVENT_VALID = "EVENT_VALID";
static EVENT_ERROR = "EVENT_ERROR";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
render: function () {
var self = this, o = this.options;
render() {
const o = this.options;
o.value = o.value || {};
this.left = this._createCombo(o.value.start, o.watermark?.start);
this.right = this._createCombo(o.value.end, o.watermark?.end);
return {
type: "bi.horizontal_fill",
type: HorizontalFillLayout.xtype,
columnSize: ["fill", "", "fill"],
items: [{
el: self.left
}, {
el: {
type: "bi.label",
height: o.height,
hgap: 5,
text: "-",
ref: function (_ref) {
self.label = _ref;
}
items: [
{
el: this.left,
},
{
el: {
type: Label.xtype,
height: o.height,
hgap: 5,
text: "-",
ref: _ref => {
this.label = _ref;
},
},
},
{
el: this.right,
}
}, {
el: self.right
}]
],
};
},
}
_createCombo: function (v, watermark) {
var self = this, o = this.options;
var combo = BI.createWidget({
type: "bi.dynamic_year_quarter_combo",
_createCombo(v, watermark) {
const o = this.options;
const combo = createWidget({
type: DynamicYearQuarterCombo.xtype,
supportDynamic: o.supportDynamic,
minDate: o.minDate,
maxDate: o.maxDate,
behaviors: o.behaviors,
value: v,
height: o.height,
watermark: watermark,
listeners: [{
eventName: BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW,
action: function () {
self.fireEvent(BI.YearQuarterInterval.EVENT_BEFORE_POPUPVIEW);
watermark,
listeners: [
{
eventName: DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW,
action: () => {
this.fireEvent(
YearQuarterInterval.EVENT_BEFORE_POPUPVIEW
);
},
}
}]
],
});
combo.on(BI.DynamicYearQuarterCombo.EVENT_ERROR, function () {
self._clearTitle();
BI.Bubbles.hide("error");
self.element.removeClass(self.constants.timeErrorCls);
self.fireEvent(BI.YearQuarterInterval.EVENT_ERROR);
combo.on(DynamicYearQuarterCombo.EVENT_ERROR, () => {
this._clearTitle();
Bubbles.hide("error");
this.element.removeClass(this.constants.timeErrorCls);
this.fireEvent(YearQuarterInterval.EVENT_ERROR);
});
combo.on(BI.DynamicYearQuarterCombo.EVENT_VALID, function () {
self._checkValid();
combo.on(DynamicYearQuarterCombo.EVENT_VALID, () => {
this._checkValid();
});
combo.on(BI.DynamicYearQuarterCombo.EVENT_FOCUS, function () {
self._checkValid();
combo.on(DynamicYearQuarterCombo.EVENT_FOCUS, () => {
this._checkValid();
});
combo.on(BI.DynamicYearQuarterCombo.EVENT_CONFIRM, function () {
BI.Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey();
if (self.left.isStateValid() && self.right.isStateValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) {
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text"));
self.element.addClass(self.constants.timeErrorCls);
self.fireEvent(BI.YearQuarterInterval.EVENT_ERROR);
}else{
self._clearTitle();
self.element.removeClass(self.constants.timeErrorCls);
self.fireEvent(BI.YearQuarterInterval.EVENT_CHANGE);
combo.on(DynamicYearQuarterCombo.EVENT_CONFIRM, () => {
Bubbles.hide("error");
const smallDate = this.left.getKey(),
bigDate = this.right.getKey();
if (
this.left.isStateValid() &&
this.right.isStateValid() &&
this._check(smallDate, bigDate) &&
this._compare(smallDate, bigDate)
) {
this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
this.element.addClass(this.constants.timeErrorCls);
this.fireEvent(YearQuarterInterval.EVENT_ERROR);
} else {
this._clearTitle();
this.element.removeClass(this.constants.timeErrorCls);
this.fireEvent(YearQuarterInterval.EVENT_CHANGE);
}
});
return combo;
},
_dateCheck: function (date) {
return BI.print(BI.parseDateTime(date, "%Y-%Q"), "%Y-%Q") === date || BI.print(BI.parseDateTime(date, "%Y-%q"), "%Y-%q") === date;
},
}
_dateCheck(date) {
return (
print(parseDateTime(date, "%Y-%Q"), "%Y-%Q") === date ||
print(parseDateTime(date, "%Y-%q"), "%Y-%q") === date
);
}
// 判是否在最大最小之间
_checkVoid: function (obj) {
var o = this.options;
return !BI.checkDateVoid(obj.year, (obj.quarter - 1) * 3 + 1, 1, o.minDate, o.maxDate)[0];
},
_checkVoid(obj) {
const o = this.options;
return !checkDateVoid(
obj.year,
(obj.quarter - 1) * 3 + 1,
1,
o.minDate,
o.maxDate
)[0];
}
// 判格式合法
_check: function (smallDate, bigDate) {
var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g);
_check(smallDate, bigDate) {
const smallObj = smallDate.match(/\d+/g),
bigObj = bigDate.match(/\d+/g);
var smallDate4Check = "";
if (BI.isNotNull(smallObj)) {
smallDate4Check = (smallObj[0] || "") + "-" + (smallObj[1] || 1);
let smallDate4Check = "";
if (isNotNull(smallObj)) {
smallDate4Check = `${smallObj[0] || ""}-${smallObj[1] || 1}`;
}
var bigDate4Check = "";
if (BI.isNotNull(bigObj)) {
bigDate4Check = (bigObj[0] || "") + "-" + (bigObj[1] || 1);
let bigDate4Check = "";
if (isNotNull(bigObj)) {
bigDate4Check = `${bigObj[0] || ""}-${bigObj[1] || 1}`;
}
return this._dateCheck(smallDate4Check) && BI.checkDateLegal(smallDate4Check) && this._checkVoid({
year: smallObj[0],
quarter: smallObj[1] || 1
}) && this._dateCheck(bigDate4Check) && BI.checkDateLegal(bigDate4Check) && this._checkVoid({
year: bigObj[0],
quarter: bigObj[1] || 1
});
},
_compare: function (smallDate, bigDate) {
smallDate = BI.print(BI.parseDateTime(smallDate, "%Y-%Q"), "%Y-%Q");
bigDate = BI.print(BI.parseDateTime(bigDate, "%Y-%Q"), "%Y-%Q");
return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate;
},
_setTitle: function (v) {
return (
this._dateCheck(smallDate4Check) &&
checkDateLegal(smallDate4Check) &&
this._checkVoid({
year: smallObj[0],
quarter: smallObj[1] || 1,
}) &&
this._dateCheck(bigDate4Check) &&
checkDateLegal(bigDate4Check) &&
this._checkVoid({
year: bigObj[0],
quarter: bigObj[1] || 1,
})
);
}
_compare(smallDate, bigDate) {
smallDate = print(parseDateTime(smallDate, "%Y-%Q"), "%Y-%Q");
bigDate = print(parseDateTime(bigDate, "%Y-%Q"), "%Y-%Q");
return (
isNotNull(smallDate) && isNotNull(bigDate) && smallDate > bigDate
);
}
_setTitle(v) {
this.setTitle(v);
},
_clearTitle: function () {
}
_clearTitle() {
this.setTitle("");
},
_checkValid: function () {
var self = this;
BI.Bubbles.hide("error");
var smallDate = self.left.getKey(), bigDate = self.right.getKey();
if (self.left.isValid() && self.right.isValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) {
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text"));
self.element.addClass(self.constants.timeErrorCls);
BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, {
offsetStyle: "center"
});
self.fireEvent(BI.YearQuarterInterval.EVENT_ERROR);
}
_checkValid() {
Bubbles.hide("error");
const smallDate = this.left.getKey(),
bigDate = this.right.getKey();
if (
this.left.isValid() &&
this.right.isValid() &&
this._check(smallDate, bigDate) &&
this._compare(smallDate, bigDate)
) {
this._setTitle(i18nText("BI-Time_Interval_Error_Text"));
this.element.addClass(this.constants.timeErrorCls);
Bubbles.show(
"error",
i18nText("BI-Time_Interval_Error_Text"),
this,
{
offsetStyle: "center",
}
);
this.fireEvent(YearQuarterInterval.EVENT_ERROR);
} else {
self._clearTitle();
self.element.removeClass(self.constants.timeErrorCls);
this._clearTitle();
this.element.removeClass(this.constants.timeErrorCls);
}
},
}
setMinDate: function (minDate) {
var o = this.options;
setMinDate(minDate) {
const o = this.options;
o.minDate = minDate;
this.left.setMinDate(minDate);
this.right.setMinDate(minDate);
},
}
setMaxDate: function (maxDate) {
var o = this.options;
setMaxDate(maxDate) {
const o = this.options;
o.maxDate = maxDate;
this.left.setMaxDate(maxDate);
this.right.setMaxDate(maxDate);
},
}
setValue: function (date) {
setValue(date) {
date = date || {};
this.left.setValue(date.start);
this.right.setValue(date.end);
this._checkValid();
},
getValue: function () {
return {start: this.left.getValue(), end: this.right.getValue()};
}
});
BI.YearQuarterInterval.EVENT_VALID = "EVENT_VALID";
BI.YearQuarterInterval.EVENT_ERROR = "EVENT_ERROR";
BI.YearQuarterInterval.EVENT_CHANGE = "EVENT_CHANGE";
BI.YearQuarterInterval.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.shortcut("bi.year_quarter_interval", BI.YearQuarterInterval);
getValue() {
return { start: this.left.getValue(), end: this.right.getValue() };
}
}

Loading…
Cancel
Save