Browse Source
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
8 changed files with 1255 additions and 871 deletions
@ -1,166 +1,213 @@ |
|||||||
/** |
import { |
||||||
* 年季度展示面板 |
shortcut, |
||||||
* |
Widget, |
||||||
* Created by GUY on 2015/9/2. |
i18nText, |
||||||
* @class BI.YearCard |
bind, |
||||||
* @extends BI.Trigger |
VerticalLayout, |
||||||
*/ |
parseDateTime, |
||||||
BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { |
extend, |
||||||
|
checkDateVoid, |
||||||
props: { |
isNotEmptyString, |
||||||
baseCls: "bi-year-quarter-card" |
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: function () { |
render() { |
||||||
var self = this; |
|
||||||
return { |
return { |
||||||
type: "bi.vertical", |
type: VerticalLayout.xtype, |
||||||
items: [{ |
items: [ |
||||||
type: "bi.label", |
{ |
||||||
text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), |
type: Label.xtype, |
||||||
|
text: i18nText("BI-Multi_Date_Relative_Current_Time"), |
||||||
textAlign: "left", |
textAlign: "left", |
||||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
||||||
}, { |
|
||||||
type: "bi.vertical", |
|
||||||
ref: function (_ref) { |
|
||||||
self.wrapper = _ref; |
|
||||||
}, |
}, |
||||||
items: [{ |
{ |
||||||
|
type: VerticalLayout.xtype, |
||||||
|
ref: _ref => { |
||||||
|
this.wrapper = _ref; |
||||||
|
}, |
||||||
|
items: [ |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.dynamic_date_param_item", |
type: DynamicDateParamItem.xtype, |
||||||
validationChecker: BI.bind(self._checkDate, self), |
validationChecker: bind(this._checkDate, this), |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.year = this; |
this.year = _ref; |
||||||
}, |
}, |
||||||
listeners: [{ |
listeners: [ |
||||||
|
{ |
||||||
eventName: "EVENT_CHANGE", |
eventName: "EVENT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
self.fireEvent("EVENT_CHANGE"); |
this.fireEvent("EVENT_CHANGE"); |
||||||
} |
}, |
||||||
}, { |
}, |
||||||
|
{ |
||||||
eventName: "EVENT_INPUT_CHANGE", |
eventName: "EVENT_INPUT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
BI.Bubbles.hide("dynamic-year-quarter-error"); |
Bubbles.hide( |
||||||
|
"dynamic-year-quarter-error" |
||||||
|
); |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}, |
}, |
||||||
bgap: 10 |
bgap: 10, |
||||||
}, { |
|
||||||
type: "bi.dynamic_date_param_item", |
|
||||||
dateType: BI.DynamicDateCard.TYPE.QUARTER, |
|
||||||
ref: function () { |
|
||||||
self.quarter = this; |
|
||||||
}, |
}, |
||||||
listeners: [{ |
{ |
||||||
|
type: DynamicDateParamItem.xtype, |
||||||
|
dateType: DynamicDateCard.TYPE.QUARTER, |
||||||
|
ref: _ref => { |
||||||
|
this.quarter = _ref; |
||||||
|
}, |
||||||
|
listeners: [ |
||||||
|
{ |
||||||
eventName: "EVENT_CHANGE", |
eventName: "EVENT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
self.fireEvent("EVENT_CHANGE"); |
this.fireEvent("EVENT_CHANGE"); |
||||||
} |
}, |
||||||
}, { |
}, |
||||||
|
{ |
||||||
eventName: "EVENT_INPUT_CHANGE", |
eventName: "EVENT_INPUT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
BI.Bubbles.hide("dynamic-year-quarter-error"); |
Bubbles.hide( |
||||||
|
"dynamic-year-quarter-error" |
||||||
|
); |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}] |
} |
||||||
}], |
], |
||||||
|
} |
||||||
|
], |
||||||
vgap: 10, |
vgap: 10, |
||||||
hgap: 10 |
hgap: 10, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
|
_getErrorText() { |
||||||
|
const o = this.options; |
||||||
|
const start = parseDateTime(o.min, "%Y-%X-%d"); |
||||||
|
const end = parseDateTime(o.max, "%Y-%X-%d"); |
||||||
|
|
||||||
_getErrorText: function () { |
return i18nText( |
||||||
var o = this.options; |
"BI-Basic_Year_Quarter_Range_Error", |
||||||
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", |
|
||||||
start.getFullYear(), |
start.getFullYear(), |
||||||
BI.getQuarter(start), |
getQuarter(start), |
||||||
end.getFullYear(), |
end.getFullYear(), |
||||||
BI.getQuarter(end) |
getQuarter(end) |
||||||
); |
); |
||||||
}, |
} |
||||||
|
|
||||||
_checkDate: function (obj) { |
_checkDate(obj) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this._getValue(), this._digestDateTypeValue(obj))); |
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) { |
_digestDateTypeValue(value) { |
||||||
var valueMap = {}; |
const valueMap = {}; |
||||||
switch (value.dateType) { |
switch (value.dateType) { |
||||||
case BI.DynamicDateCard.TYPE.YEAR: |
case DynamicDateCard.TYPE.YEAR: |
||||||
valueMap.year = (value.offset === 0 ? -value.value : +value.value); |
valueMap.year = |
||||||
|
value.offset === 0 ? -value.value : +value.value; |
||||||
break; |
break; |
||||||
case BI.DynamicDateCard.TYPE.QUARTER: |
case DynamicDateCard.TYPE.QUARTER: |
||||||
valueMap.quarter = (value.offset === 0 ? -value.value : +value.value); |
valueMap.quarter = |
||||||
|
value.offset === 0 ? -value.value : +value.value; |
||||||
break; |
break; |
||||||
default: |
default: |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
return valueMap; |
return valueMap; |
||||||
}, |
} |
||||||
|
|
||||||
_createValue: function (type, v) { |
_createValue(type, v) { |
||||||
return { |
return { |
||||||
dateType: type, |
dateType: type, |
||||||
value: Math.abs(v), |
value: Math.abs(v), |
||||||
offset: v > 0 ? 1 : 0 |
offset: v > 0 ? 1 : 0, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
setMinDate: function(minDate) { |
setMinDate(minDate) { |
||||||
if (BI.isNotEmptyString(this.options.min)) { |
if (isNotEmptyString(this.options.min)) { |
||||||
this.options.min = minDate; |
this.options.min = minDate; |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
if (BI.isNotEmptyString(this.options.max)) { |
if (isNotEmptyString(this.options.max)) { |
||||||
this.options.max = maxDate; |
this.options.max = maxDate; |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (v) { |
setValue(v) { |
||||||
v = v || { year: 0, quarter: 0 }; |
v = v || { year: 0, quarter: 0 }; |
||||||
this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); |
this.year.setValue( |
||||||
this.quarter.setValue(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); |
this._createValue(DynamicDateCard.TYPE.YEAR, v.year) |
||||||
}, |
); |
||||||
|
this.quarter.setValue( |
||||||
|
this._createValue(DynamicDateCard.TYPE.QUARTER, v.quarter) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
_getValue() { |
||||||
|
const year = this.year.getValue(); |
||||||
|
const quarter = this.quarter.getValue(); |
||||||
|
|
||||||
_getValue: function () { |
|
||||||
var year = this.year.getValue(); |
|
||||||
var quarter = this.quarter.getValue(); |
|
||||||
return { |
return { |
||||||
year: (year.offset === 0 ? -year.value : year.value), |
year: year.offset === 0 ? -year.value : year.value, |
||||||
quarter: (quarter.offset === 0 ? -quarter.value : quarter.value) |
quarter: quarter.offset === 0 ? -quarter.value : quarter.value, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
getInputValue: function () { |
getInputValue() { |
||||||
return this._getValue(); |
return this._getValue(); |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return this.checkValidation() ? this._getValue() : {}; |
return this.checkValidation() ? this._getValue() : {}; |
||||||
}, |
} |
||||||
|
|
||||||
checkValidation: function (show) { |
checkValidation(show) { |
||||||
var errorText; |
let errorText; |
||||||
var yearInvalid = !this.year.checkValidation(); |
const yearInvalid = !this.year.checkValidation(); |
||||||
var quarterInvalid = !this.quarter.checkValidation(); |
const quarterInvalid = !this.quarter.checkValidation(); |
||||||
var invalid = yearInvalid || quarterInvalid; |
let invalid = yearInvalid || quarterInvalid; |
||||||
if (invalid) { |
if (invalid) { |
||||||
errorText = BI.i18nText("BI-Please_Input_Natural_Number"); |
errorText = i18nText("BI-Please_Input_Natural_Number"); |
||||||
} else { |
} else { |
||||||
invalid = !this._checkDate(this._getValue()); |
invalid = !this._checkDate(this._getValue()); |
||||||
errorText = this._getErrorText(); |
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; |
return !invalid; |
||||||
}, |
} |
||||||
}); |
} |
||||||
BI.DynamicYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; |
|
||||||
BI.shortcut("bi.dynamic_year_quarter_card", BI.DynamicYearQuarterCard); |
|
||||||
|
@ -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: { |
@shortcut() |
||||||
baseCls: "bi-static-year-quarter-card", |
export class StaticYearQuarterCard extends Widget { |
||||||
behaviors: {} |
static xtype = "bi.static_year_quarter_card"; |
||||||
|
|
||||||
|
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, |
||||||
|
} |
||||||
|
]; |
||||||
|
|
||||||
_createQuarter: function () { |
return map(items, (j, item) => extend(item, { |
||||||
var self = this; |
type: TextItem.xtype, |
||||||
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", |
cls: "bi-border-radius bi-list-item-select", |
||||||
textAlign: "center", |
textAlign: "center", |
||||||
whiteSpace: "nowrap", |
whiteSpace: "nowrap", |
||||||
once: false, |
once: false, |
||||||
forceSelected: true, |
forceSelected: true, |
||||||
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
ref: function (_ref) { |
ref: _ref => { |
||||||
self.quarterMap[j + 1] = _ref; |
this.quarterMap[j + 1] = _ref; |
||||||
} |
|
||||||
}); |
|
||||||
}); |
|
||||||
}, |
}, |
||||||
|
})); |
||||||
|
} |
||||||
|
|
||||||
render: function () { |
render() { |
||||||
var self = this, o = this.options; |
const o = this.options; |
||||||
this.quarterMap = {}; |
this.quarterMap = {}; |
||||||
|
|
||||||
return { |
return { |
||||||
type: "bi.vertical", |
type: VerticalLayout.xtype, |
||||||
items: [{ |
items: [ |
||||||
type: "bi.year_picker", |
{ |
||||||
|
type: YearPicker.xtype, |
||||||
cls: "bi-split-bottom", |
cls: "bi-split-bottom", |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.yearPicker = this; |
this.yearPicker = _ref; |
||||||
}, |
}, |
||||||
min: o.min, |
min: o.min, |
||||||
max: o.max, |
max: o.max, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
height: 30, |
height: 30, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.YearPicker.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: YearPicker.EVENT_CHANGE, |
||||||
var value = this.getValue(); |
action: () => { |
||||||
self._checkQuarterStatus(value); |
const value = this.yearPicker.getValue(); |
||||||
self.setValue({ |
this._checkQuarterStatus(value); |
||||||
|
this.setValue({ |
||||||
year: value, |
year: value, |
||||||
quarter: self.selectedQuarter |
quarter: this.selectedQuarter, |
||||||
}); |
}); |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}, { |
}, |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.button_group", |
type: ButtonGroup.xtype, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.quarter = this; |
this.quarter = _ref; |
||||||
}, |
}, |
||||||
items: this._createQuarter(), |
items: this._createQuarter(), |
||||||
layouts: [{ |
layouts: [ |
||||||
type: "bi.vertical", |
{ |
||||||
|
type: VerticalLayout.xtype, |
||||||
vgap: 10, |
vgap: 10, |
||||||
hgap: 12, |
hgap: 12, |
||||||
}], |
} |
||||||
|
], |
||||||
value: o.value, |
value: o.value, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.ButtonGroup.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: ButtonGroup.EVENT_CHANGE, |
||||||
self.selectedYear = self.yearPicker.getValue(); |
action: () => { |
||||||
self.selectedQuarter = this.getValue()[0]; |
this.selectedYear = |
||||||
self.fireEvent(BI.StaticYearQuarterCard.EVENT_CHANGE); |
this.yearPicker.getValue(); |
||||||
} |
this.selectedQuarter = this.quarter.getValue()[0]; |
||||||
}] |
this.fireEvent( |
||||||
|
StaticYearQuarterCard.EVENT_CHANGE |
||||||
|
); |
||||||
}, |
}, |
||||||
vgap: 5 |
} |
||||||
}] |
], |
||||||
}; |
|
||||||
}, |
}, |
||||||
|
vgap: 5, |
||||||
|
} |
||||||
|
], |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
_checkQuarterStatus: function (year) { |
_checkQuarterStatus(year) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"), maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); |
const minDate = parseDateTime(o.min, "%Y-%X-%d"), |
||||||
var minYear = minDate.getFullYear(), maxYear = maxDate.getFullYear(); |
maxDate = parseDateTime(o.max, "%Y-%X-%d"); |
||||||
var minQuarter = 1; var maxQuarter = 4; |
const minYear = minDate.getFullYear(), |
||||||
minYear === year && (minQuarter = BI.parseInt(BI.getQuarter(minDate))); |
maxYear = maxDate.getFullYear(); |
||||||
maxYear === year && (maxQuarter = BI.parseInt(BI.getQuarter(maxDate))); |
let minQuarter = 1; |
||||||
var yearInvalid = year < minYear || year > maxYear; |
let maxQuarter = 4; |
||||||
BI.each(this.quarterMap, function (quarter, obj) { |
minYear === year && (minQuarter = parseInt(getQuarter(minDate))); |
||||||
var quarterInvalid = quarter < minQuarter || quarter > maxQuarter; |
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); |
obj.setEnable(!yearInvalid && !quarterInvalid); |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
setMinDate: function (minDate) { |
setMinDate(minDate) { |
||||||
if (this.options.min !== minDate) { |
if (this.options.min !== minDate) { |
||||||
this.options.min = minDate; |
this.options.min = minDate; |
||||||
this.yearPicker.setMinDate(minDate); |
this.yearPicker.setMinDate(minDate); |
||||||
this._checkQuarterStatus(this.selectedYear); |
this._checkQuarterStatus(this.selectedYear); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
if (this.options.max !== maxDate) { |
if (this.options.max !== maxDate) { |
||||||
this.options.max = maxDate; |
this.options.max = maxDate; |
||||||
this.yearPicker.setMaxDate(maxDate); |
this.yearPicker.setMaxDate(maxDate); |
||||||
this._checkQuarterStatus(this.selectedYear); |
this._checkQuarterStatus(this.selectedYear); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return { |
return { |
||||||
year: this.selectedYear, |
year: this.selectedYear, |
||||||
quarter: this.selectedQuarter |
quarter: this.selectedQuarter, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (obj) { |
setValue(obj) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var newObj = {}; |
const newObj = {}; |
||||||
newObj.year = obj.year || 0; |
newObj.year = obj.year || 0; |
||||||
newObj.quarter = obj.quarter || 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]) { |
if ( |
||||||
var year = newObj.year || BI.getDate().getFullYear(); |
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.selectedYear = year; |
||||||
this.selectedQuarter = ""; |
this.selectedQuarter = ""; |
||||||
this.yearPicker.setValue(year); |
this.yearPicker.setValue(year); |
||||||
this.quarter.setValue(); |
this.quarter.setValue(); |
||||||
} else { |
} else { |
||||||
this.selectedYear = BI.parseInt(newObj.year); |
this.selectedYear = parseInt(newObj.year); |
||||||
this.selectedQuarter = BI.parseInt(newObj.quarter); |
this.selectedQuarter = parseInt(newObj.quarter); |
||||||
this.yearPicker.setValue(this.selectedYear); |
this.yearPicker.setValue(this.selectedYear); |
||||||
this.quarter.setValue(this.selectedQuarter); |
this.quarter.setValue(this.selectedQuarter); |
||||||
} |
} |
||||||
this._checkQuarterStatus(this.selectedYear); |
this._checkQuarterStatus(this.selectedYear); |
||||||
} |
} |
||||||
}); |
} |
||||||
BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; |
|
||||||
BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard); |
|
||||||
|
@ -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"; |
||||||
|
|
@ -1,235 +1,328 @@ |
|||||||
BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { |
import { |
||||||
constants: { |
shortcut, |
||||||
tabHeight: 40, |
Widget, |
||||||
buttonHeight: 24 |
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"; |
||||||
|
|
||||||
|
@shortcut() |
||||||
|
export class DynamicYearQuarterPopup extends Widget { |
||||||
|
static xtype = "bi.dynamic_year_quarter_popup"; |
||||||
|
|
||||||
props: { |
constants = { tabHeight: 40, buttonHeight: 24 }; |
||||||
|
props = { |
||||||
baseCls: "bi-year-quarter-popup", |
baseCls: "bi-year-quarter-popup", |
||||||
behaviors: {}, |
behaviors: {}, |
||||||
min: "1900-01-01", // 最小日期
|
min: "1900-01-01", |
||||||
max: "2099-12-31", // 最大日期,
|
max: "2099-12-31", |
||||||
width: 180, |
width: 180, |
||||||
supportDynamic: true, |
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() { |
||||||
|
this.storeValue = { type: DynamicYearQuarterCombo.Static }; |
||||||
|
|
||||||
render: function () { |
|
||||||
var self = this, opts = this.options, c = this.constants; |
|
||||||
this.storeValue = {type: BI.DynamicYearQuarterCombo.Static}; |
|
||||||
return { |
return { |
||||||
type: "bi.vertical", |
type: VerticalLayout.xtype, |
||||||
items: [{ |
items: [ |
||||||
el: this._getTabJson() |
{ |
||||||
}, { |
el: this._getTabJson(), |
||||||
|
}, |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.grid", |
type: GridLayout.xtype, |
||||||
items: [[{ |
items: [ |
||||||
type: "bi.text_button", |
[ |
||||||
|
{ |
||||||
|
type: TextButton.xtype, |
||||||
cls: "bi-split-top bi-high-light", |
cls: "bi-split-top bi-high-light", |
||||||
shadow: true, |
shadow: true, |
||||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
textHeight: toPix( |
||||||
text: BI.i18nText("BI-Basic_Clear"), |
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
listeners: [{ |
1 |
||||||
eventName: BI.TextButton.EVENT_CHANGE, |
), |
||||||
action: function () { |
text: i18nText("BI-Basic_Clear"), |
||||||
self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE); |
listeners: [ |
||||||
} |
{ |
||||||
}] |
eventName: TextButton.EVENT_CHANGE, |
||||||
}, { |
action: () => { |
||||||
type: "bi.text_button", |
this.fireEvent( |
||||||
|
DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE |
||||||
|
); |
||||||
|
}, |
||||||
|
} |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: TextButton.xtype, |
||||||
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
||||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
textHeight: toPix( |
||||||
|
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
|
1 |
||||||
|
), |
||||||
shadow: true, |
shadow: true, |
||||||
text: BI.i18nText("BI-Basic_Current_Quarter"), |
text: i18nText("BI-Basic_Current_Quarter"), |
||||||
disabled: this._checkTodayValid(), |
disabled: this._checkTodayValid(), |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.textButton = this; |
this.textButton = _ref; |
||||||
|
}, |
||||||
|
listeners: [ |
||||||
|
{ |
||||||
|
eventName: TextButton.EVENT_CHANGE, |
||||||
|
action: () => { |
||||||
|
this.fireEvent( |
||||||
|
DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE |
||||||
|
); |
||||||
}, |
}, |
||||||
listeners: [{ |
|
||||||
eventName: BI.TextButton.EVENT_CHANGE, |
|
||||||
action: function () { |
|
||||||
self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE); |
|
||||||
} |
} |
||||||
}] |
], |
||||||
}, { |
}, |
||||||
type: "bi.text_button", |
{ |
||||||
|
type: TextButton.xtype, |
||||||
cls: "bi-split-top bi-high-light", |
cls: "bi-split-top bi-high-light", |
||||||
shadow: true, |
shadow: true, |
||||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
textHeight: toPix( |
||||||
text: BI.i18nText("BI-Basic_OK"), |
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
listeners: [{ |
1 |
||||||
eventName: BI.TextButton.EVENT_CHANGE, |
), |
||||||
action: function () { |
text: i18nText("BI-Basic_OK"), |
||||||
var type = self.dateTab.getSelect(); |
listeners: [ |
||||||
if (type === BI.DynamicDateCombo.Dynamic) { |
{ |
||||||
self.dynamicPane.checkValidation(true) && self.fireEvent(BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE); |
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 { |
} else { |
||||||
self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE); |
this.fireEvent(DynamicYearQuarterPopup |
||||||
|
.BUTTON_OK_EVENT_CHANGE |
||||||
|
); |
||||||
} |
} |
||||||
|
}, |
||||||
|
} |
||||||
|
], |
||||||
} |
} |
||||||
}] |
] |
||||||
}]], |
], |
||||||
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT |
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
}, |
}, |
||||||
}] |
} |
||||||
|
], |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
_setInnerValue: function () { |
_setInnerValue() { |
||||||
if (this.dateTab.getSelect() === BI.DynamicYearQuarterCombo.Static) { |
if (this.dateTab.getSelect() === DynamicYearQuarterCombo.Static) { |
||||||
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); |
this.textButton.setValue(i18nText("BI-Basic_Current_Quarter")); |
||||||
this.textButton.setEnable(!this._checkTodayValid()); |
this.textButton.setEnable(!this._checkTodayValid()); |
||||||
} else { |
} else { |
||||||
var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getInputValue()); |
let date = DynamicDateHelper.getCalculation( |
||||||
date = BI.print(date, "%Y-%Q"); |
this.dynamicPane.getInputValue() |
||||||
|
); |
||||||
|
date = print(date, "%Y-%Q"); |
||||||
this.textButton.setValue(date); |
this.textButton.setValue(date); |
||||||
this.textButton.setEnable(false); |
this.textButton.setEnable(false); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
_checkTodayValid: function () { |
_checkTodayValid() { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var today = BI.getDate(); |
const today = getDate(); |
||||||
return !!BI.checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0]; |
|
||||||
}, |
return !!checkDateVoid( |
||||||
|
today.getFullYear(), |
||||||
|
today.getMonth() + 1, |
||||||
|
today.getDate(), |
||||||
|
o.min, |
||||||
|
o.max |
||||||
|
)[0]; |
||||||
|
} |
||||||
|
|
||||||
|
_getTabJson() { |
||||||
|
const o = this.options; |
||||||
|
|
||||||
_getTabJson: function () { |
|
||||||
var self = this, o = this.options; |
|
||||||
return { |
return { |
||||||
type: "bi.tab", |
type: Tab.xtype, |
||||||
logic: { |
logic: { |
||||||
dynamic: true |
dynamic: true, |
||||||
}, |
}, |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.dateTab = this; |
this.dateTab = _ref; |
||||||
}, |
}, |
||||||
tab: { |
tab: { |
||||||
type: "bi.linear_segment", |
type: LinearSegment.xtype, |
||||||
cls: "bi-split-bottom", |
cls: "bi-split-bottom", |
||||||
invisible: !o.supportDynamic, |
invisible: !o.supportDynamic, |
||||||
height: this.constants.tabHeight, |
height: this.constants.tabHeight, |
||||||
items: BI.createItems([{ |
items: createItems( |
||||||
text: BI.i18nText("BI-Basic_Year_Quarter"), |
[ |
||||||
value: BI.DynamicYearQuarterCombo.Static |
{ |
||||||
}, { |
text: i18nText("BI-Basic_Year_Quarter"), |
||||||
text: BI.i18nText("BI-Basic_Dynamic_Title"), |
value: DynamicYearQuarterCombo.Static, |
||||||
value: BI.DynamicYearQuarterCombo.Dynamic |
}, |
||||||
}], { |
{ |
||||||
textAlign: "center" |
text: i18nText("BI-Basic_Dynamic_Title"), |
||||||
}) |
value: DynamicYearQuarterCombo.Dynamic, |
||||||
}, |
} |
||||||
cardCreator: function (v) { |
], |
||||||
|
{ |
||||||
|
textAlign: "center", |
||||||
|
} |
||||||
|
), |
||||||
|
}, |
||||||
|
cardCreator: v => { |
||||||
switch (v) { |
switch (v) { |
||||||
case BI.DynamicYearQuarterCombo.Dynamic: |
case DynamicYearQuarterCombo.Dynamic: |
||||||
return { |
return { |
||||||
type: "bi.dynamic_year_quarter_card", |
type: DynamicYearQuarterCard.xtype, |
||||||
cls: "dynamic-year-quarter-pane", |
cls: "dynamic-year-quarter-pane", |
||||||
min: self.options.min, |
min: this.options.min, |
||||||
max: self.options.max, |
max: this.options.max, |
||||||
listeners: [{ |
listeners: [ |
||||||
|
{ |
||||||
eventName: "EVENT_CHANGE", |
eventName: "EVENT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
self._setInnerValue(self.year, v); |
this._setInnerValue(this.year, v); |
||||||
} |
}, |
||||||
}], |
|
||||||
ref: function () { |
|
||||||
self.dynamicPane = this; |
|
||||||
} |
} |
||||||
|
], |
||||||
|
ref: _ref => { |
||||||
|
this.dynamicPane = _ref; |
||||||
|
}, |
||||||
}; |
}; |
||||||
case BI.DynamicYearQuarterCombo.Static: |
case DynamicYearQuarterCombo.Static: |
||||||
default: |
default: |
||||||
return { |
return { |
||||||
type: "bi.static_year_quarter_card", |
type: StaticYearQuarterCard.xtype, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
min: self.options.min, |
min: this.options.min, |
||||||
max: self.options.max, |
max: this.options.max, |
||||||
listeners: [{ |
listeners: [ |
||||||
|
{ |
||||||
eventName: BI.DynamicYearCard.EVENT_CHANGE, |
eventName: BI.DynamicYearCard.EVENT_CHANGE, |
||||||
action: function () { |
action: () => { |
||||||
self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE); |
this.fireEvent( |
||||||
} |
DynamicYearQuarterPopup.EVENT_CHANGE |
||||||
}], |
); |
||||||
ref: function () { |
}, |
||||||
self.year = this; |
|
||||||
} |
} |
||||||
|
], |
||||||
|
ref: _ref => { |
||||||
|
this.year = _ref; |
||||||
|
}, |
||||||
}; |
}; |
||||||
} |
} |
||||||
}, |
}, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.Tab.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: Tab.EVENT_CHANGE, |
||||||
var v = self.dateTab.getSelect(); |
action: () => { |
||||||
|
const v = this.dateTab.getSelect(); |
||||||
|
let date; |
||||||
switch (v) { |
switch (v) { |
||||||
case BI.DynamicYearQuarterCombo.Static: |
case DynamicYearQuarterCombo.Static: |
||||||
var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); |
date = DynamicDateHelper.getCalculation( |
||||||
self.year.setValue({year: date.getFullYear(), quarter: BI.getQuarter(date)}); |
this.dynamicPane.getValue() |
||||||
self._setInnerValue(); |
); |
||||||
|
this.year.setValue({ |
||||||
|
year: date.getFullYear(), |
||||||
|
quarter: getQuarter(date), |
||||||
|
}); |
||||||
|
this._setInnerValue(); |
||||||
break; |
break; |
||||||
case BI.DynamicYearQuarterCombo.Dynamic: |
case DynamicYearQuarterCombo.Dynamic: |
||||||
default: |
default: |
||||||
if(self.storeValue && self.storeValue.type === BI.DynamicYearQuarterCombo.Dynamic) { |
if ( |
||||||
self.dynamicPane.setValue(self.storeValue.value); |
this.storeValue && |
||||||
|
this.storeValue.type === |
||||||
|
DynamicYearQuarterCombo.Dynamic |
||||||
|
) { |
||||||
|
this.dynamicPane.setValue( |
||||||
|
this.storeValue.value |
||||||
|
); |
||||||
} else { |
} else { |
||||||
self.dynamicPane.setValue({ |
this.dynamicPane.setValue({ |
||||||
year: 0 |
year: 0, |
||||||
}); |
}); |
||||||
} |
} |
||||||
self._setInnerValue(); |
this._setInnerValue(); |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
setMinDate: function (minDate) { |
setMinDate(minDate) { |
||||||
if (this.options.min !== minDate) { |
if (this.options.min !== minDate) { |
||||||
this.options.min = minDate; |
this.options.min = minDate; |
||||||
this.year && this.year.setMinDate(minDate); |
this.year && this.year.setMinDate(minDate); |
||||||
this.dynamicPane && this.dynamicPane.setMinDate(minDate); |
this.dynamicPane && this.dynamicPane.setMinDate(minDate); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
if (this.options.max !== maxDate) { |
if (this.options.max !== maxDate) { |
||||||
this.options.max = maxDate; |
this.options.max = maxDate; |
||||||
this.year && this.year.setMaxDate(maxDate); |
this.year && this.year.setMaxDate(maxDate); |
||||||
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate); |
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (v) { |
setValue(v) { |
||||||
this.storeValue = v; |
this.storeValue = v; |
||||||
var self = this; |
|
||||||
var type, value; |
|
||||||
v = v || {}; |
v = v || {}; |
||||||
type = v.type || BI.DynamicDateCombo.Static; |
const type = v.type || DynamicDateCombo.Static; |
||||||
value = v.value || v; |
const value = v.value || v; |
||||||
this.dateTab.setSelect(type); |
this.dateTab.setSelect(type); |
||||||
switch (type) { |
switch (type) { |
||||||
case BI.DynamicDateCombo.Dynamic: |
case DynamicDateCombo.Dynamic: |
||||||
this.dynamicPane.setValue(value); |
this.dynamicPane.setValue(value); |
||||||
self._setInnerValue(); |
this._setInnerValue(); |
||||||
break; |
break; |
||||||
case BI.DynamicDateCombo.Static: |
case DynamicDateCombo.Static: |
||||||
default: |
default: |
||||||
this.year.setValue(value); |
this.year.setValue(value); |
||||||
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); |
this.textButton.setValue(i18nText("BI-Basic_Current_Quarter")); |
||||||
this.textButton.setEnable(!this._checkTodayValid()); |
this.textButton.setEnable(!this._checkTodayValid()); |
||||||
break; |
break; |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return { |
return { |
||||||
type: this.dateTab.getSelect(), |
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); |
|
||||||
|
@ -1,193 +1,248 @@ |
|||||||
/** |
import { |
||||||
* @author windy |
shortcut, |
||||||
* @version 2.0 |
HorizontalFillLayout, |
||||||
* Created by windy on 2021/1/25 |
createWidget, |
||||||
*/ |
i18nText, |
||||||
BI.YearQuarterInterval = BI.inherit(BI.Single, { |
print, |
||||||
constants: { |
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, |
height: 24, |
||||||
width: 25, |
width: 25, |
||||||
lgap: 15, |
lgap: 15, |
||||||
offset: -15, |
offset: -15, |
||||||
timeErrorCls: "time-error" |
timeErrorCls: "time-error", |
||||||
}, |
}; |
||||||
|
props = { |
||||||
props: { |
|
||||||
extraCls: "bi-year-quarter-interval", |
extraCls: "bi-year-quarter-interval", |
||||||
minDate: "1900-01-01", |
minDate: "1900-01-01", |
||||||
maxDate: "2099-12-31", |
maxDate: "2099-12-31", |
||||||
supportDynamic: true, |
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 () { |
render() { |
||||||
var self = this, o = this.options; |
const o = this.options; |
||||||
|
|
||||||
o.value = o.value || {}; |
o.value = o.value || {}; |
||||||
this.left = this._createCombo(o.value.start, o.watermark?.start); |
this.left = this._createCombo(o.value.start, o.watermark?.start); |
||||||
this.right = this._createCombo(o.value.end, o.watermark?.end); |
this.right = this._createCombo(o.value.end, o.watermark?.end); |
||||||
|
|
||||||
|
|
||||||
return { |
return { |
||||||
type: "bi.horizontal_fill", |
type: HorizontalFillLayout.xtype, |
||||||
columnSize: ["fill", "", "fill"], |
columnSize: ["fill", "", "fill"], |
||||||
items: [{ |
items: [ |
||||||
el: self.left |
{ |
||||||
}, { |
el: this.left, |
||||||
|
}, |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.label", |
type: Label.xtype, |
||||||
height: o.height, |
height: o.height, |
||||||
hgap: 5, |
hgap: 5, |
||||||
text: "-", |
text: "-", |
||||||
ref: function (_ref) { |
ref: _ref => { |
||||||
self.label = _ref; |
this.label = _ref; |
||||||
} |
}, |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
el: this.right, |
||||||
} |
} |
||||||
}, { |
], |
||||||
el: self.right |
|
||||||
}] |
|
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
_createCombo: function (v, watermark) { |
_createCombo(v, watermark) { |
||||||
var self = this, o = this.options; |
const o = this.options; |
||||||
var combo = BI.createWidget({ |
const combo = createWidget({ |
||||||
type: "bi.dynamic_year_quarter_combo", |
type: DynamicYearQuarterCombo.xtype, |
||||||
supportDynamic: o.supportDynamic, |
supportDynamic: o.supportDynamic, |
||||||
minDate: o.minDate, |
minDate: o.minDate, |
||||||
maxDate: o.maxDate, |
maxDate: o.maxDate, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
value: v, |
value: v, |
||||||
height: o.height, |
height: o.height, |
||||||
watermark: watermark, |
watermark, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW, |
{ |
||||||
action: function () { |
eventName: DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW, |
||||||
self.fireEvent(BI.YearQuarterInterval.EVENT_BEFORE_POPUPVIEW); |
action: () => { |
||||||
|
this.fireEvent( |
||||||
|
YearQuarterInterval.EVENT_BEFORE_POPUPVIEW |
||||||
|
); |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}); |
}); |
||||||
combo.on(BI.DynamicYearQuarterCombo.EVENT_ERROR, function () { |
combo.on(DynamicYearQuarterCombo.EVENT_ERROR, () => { |
||||||
self._clearTitle(); |
this._clearTitle(); |
||||||
BI.Bubbles.hide("error"); |
Bubbles.hide("error"); |
||||||
self.element.removeClass(self.constants.timeErrorCls); |
this.element.removeClass(this.constants.timeErrorCls); |
||||||
self.fireEvent(BI.YearQuarterInterval.EVENT_ERROR); |
this.fireEvent(YearQuarterInterval.EVENT_ERROR); |
||||||
}); |
}); |
||||||
|
|
||||||
combo.on(BI.DynamicYearQuarterCombo.EVENT_VALID, function () { |
combo.on(DynamicYearQuarterCombo.EVENT_VALID, () => { |
||||||
self._checkValid(); |
this._checkValid(); |
||||||
}); |
}); |
||||||
|
|
||||||
combo.on(BI.DynamicYearQuarterCombo.EVENT_FOCUS, function () { |
combo.on(DynamicYearQuarterCombo.EVENT_FOCUS, () => { |
||||||
self._checkValid(); |
this._checkValid(); |
||||||
}); |
}); |
||||||
|
|
||||||
combo.on(BI.DynamicYearQuarterCombo.EVENT_CONFIRM, function () { |
combo.on(DynamicYearQuarterCombo.EVENT_CONFIRM, () => { |
||||||
BI.Bubbles.hide("error"); |
Bubbles.hide("error"); |
||||||
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); |
const smallDate = this.left.getKey(), |
||||||
if (self.left.isStateValid() && self.right.isStateValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { |
bigDate = this.right.getKey(); |
||||||
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); |
if ( |
||||||
self.element.addClass(self.constants.timeErrorCls); |
this.left.isStateValid() && |
||||||
self.fireEvent(BI.YearQuarterInterval.EVENT_ERROR); |
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 { |
} else { |
||||||
self._clearTitle(); |
this._clearTitle(); |
||||||
self.element.removeClass(self.constants.timeErrorCls); |
this.element.removeClass(this.constants.timeErrorCls); |
||||||
self.fireEvent(BI.YearQuarterInterval.EVENT_CHANGE); |
this.fireEvent(YearQuarterInterval.EVENT_CHANGE); |
||||||
} |
} |
||||||
}); |
}); |
||||||
return combo; |
|
||||||
}, |
|
||||||
|
|
||||||
|
return combo; |
||||||
|
} |
||||||
|
|
||||||
_dateCheck: function (date) { |
_dateCheck(date) { |
||||||
return BI.print(BI.parseDateTime(date, "%Y-%Q"), "%Y-%Q") === date || BI.print(BI.parseDateTime(date, "%Y-%q"), "%Y-%q") === date; |
return ( |
||||||
}, |
print(parseDateTime(date, "%Y-%Q"), "%Y-%Q") === date || |
||||||
|
print(parseDateTime(date, "%Y-%q"), "%Y-%q") === date |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
_checkVoid(obj) { |
||||||
|
const o = this.options; |
||||||
|
|
||||||
// 判是否在最大最小之间
|
return !checkDateVoid( |
||||||
_checkVoid: function (obj) { |
obj.year, |
||||||
var o = this.options; |
(obj.quarter - 1) * 3 + 1, |
||||||
return !BI.checkDateVoid(obj.year, (obj.quarter - 1) * 3 + 1, 1, o.minDate, o.maxDate)[0]; |
1, |
||||||
}, |
o.minDate, |
||||||
|
o.maxDate |
||||||
|
)[0]; |
||||||
|
} |
||||||
|
|
||||||
// 判格式合法
|
_check(smallDate, bigDate) { |
||||||
_check: function (smallDate, bigDate) { |
const smallObj = smallDate.match(/\d+/g), |
||||||
var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); |
bigObj = bigDate.match(/\d+/g); |
||||||
|
|
||||||
var smallDate4Check = ""; |
let smallDate4Check = ""; |
||||||
if (BI.isNotNull(smallObj)) { |
if (isNotNull(smallObj)) { |
||||||
smallDate4Check = (smallObj[0] || "") + "-" + (smallObj[1] || 1); |
smallDate4Check = `${smallObj[0] || ""}-${smallObj[1] || 1}`; |
||||||
} |
} |
||||||
|
|
||||||
var bigDate4Check = ""; |
let bigDate4Check = ""; |
||||||
if (BI.isNotNull(bigObj)) { |
if (isNotNull(bigObj)) { |
||||||
bigDate4Check = (bigObj[0] || "") + "-" + (bigObj[1] || 1); |
bigDate4Check = `${bigObj[0] || ""}-${bigObj[1] || 1}`; |
||||||
} |
} |
||||||
|
|
||||||
return this._dateCheck(smallDate4Check) && BI.checkDateLegal(smallDate4Check) && this._checkVoid({ |
return ( |
||||||
|
this._dateCheck(smallDate4Check) && |
||||||
|
checkDateLegal(smallDate4Check) && |
||||||
|
this._checkVoid({ |
||||||
year: smallObj[0], |
year: smallObj[0], |
||||||
quarter: smallObj[1] || 1 |
quarter: smallObj[1] || 1, |
||||||
}) && this._dateCheck(bigDate4Check) && BI.checkDateLegal(bigDate4Check) && this._checkVoid({ |
}) && |
||||||
|
this._dateCheck(bigDate4Check) && |
||||||
|
checkDateLegal(bigDate4Check) && |
||||||
|
this._checkVoid({ |
||||||
year: bigObj[0], |
year: bigObj[0], |
||||||
quarter: bigObj[1] || 1 |
quarter: bigObj[1] || 1, |
||||||
}); |
}) |
||||||
}, |
); |
||||||
|
} |
||||||
|
|
||||||
_compare: function (smallDate, bigDate) { |
_compare(smallDate, bigDate) { |
||||||
smallDate = BI.print(BI.parseDateTime(smallDate, "%Y-%Q"), "%Y-%Q"); |
smallDate = print(parseDateTime(smallDate, "%Y-%Q"), "%Y-%Q"); |
||||||
bigDate = BI.print(BI.parseDateTime(bigDate, "%Y-%Q"), "%Y-%Q"); |
bigDate = print(parseDateTime(bigDate, "%Y-%Q"), "%Y-%Q"); |
||||||
return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; |
|
||||||
}, |
return ( |
||||||
_setTitle: function (v) { |
isNotNull(smallDate) && isNotNull(bigDate) && smallDate > bigDate |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
_setTitle(v) { |
||||||
this.setTitle(v); |
this.setTitle(v); |
||||||
}, |
} |
||||||
_clearTitle: function () { |
|
||||||
|
_clearTitle() { |
||||||
this.setTitle(""); |
this.setTitle(""); |
||||||
}, |
} |
||||||
_checkValid: function () { |
|
||||||
var self = this; |
_checkValid() { |
||||||
|
Bubbles.hide("error"); |
||||||
BI.Bubbles.hide("error"); |
const smallDate = this.left.getKey(), |
||||||
var smallDate = self.left.getKey(), bigDate = self.right.getKey(); |
bigDate = this.right.getKey(); |
||||||
if (self.left.isValid() && self.right.isValid() && self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { |
if ( |
||||||
self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); |
this.left.isValid() && |
||||||
self.element.addClass(self.constants.timeErrorCls); |
this.right.isValid() && |
||||||
BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { |
this._check(smallDate, bigDate) && |
||||||
offsetStyle: "center" |
this._compare(smallDate, bigDate) |
||||||
}); |
) { |
||||||
self.fireEvent(BI.YearQuarterInterval.EVENT_ERROR); |
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 { |
} else { |
||||||
self._clearTitle(); |
this._clearTitle(); |
||||||
self.element.removeClass(self.constants.timeErrorCls); |
this.element.removeClass(this.constants.timeErrorCls); |
||||||
|
} |
||||||
} |
} |
||||||
}, |
|
||||||
|
|
||||||
setMinDate: function (minDate) { |
setMinDate(minDate) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
o.minDate = minDate; |
o.minDate = minDate; |
||||||
this.left.setMinDate(minDate); |
this.left.setMinDate(minDate); |
||||||
this.right.setMinDate(minDate); |
this.right.setMinDate(minDate); |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
o.maxDate = maxDate; |
o.maxDate = maxDate; |
||||||
this.left.setMaxDate(maxDate); |
this.left.setMaxDate(maxDate); |
||||||
this.right.setMaxDate(maxDate); |
this.right.setMaxDate(maxDate); |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (date) { |
setValue(date) { |
||||||
date = date || {}; |
date = date || {}; |
||||||
this.left.setValue(date.start); |
this.left.setValue(date.start); |
||||||
this.right.setValue(date.end); |
this.right.setValue(date.end); |
||||||
|
|
||||||
this._checkValid(); |
this._checkValid(); |
||||||
}, |
} |
||||||
getValue: function () { |
|
||||||
|
getValue() { |
||||||
return { start: this.left.getValue(), end: this.right.getValue() }; |
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); |
|
||||||
|
Loading…
Reference in new issue