forked from fanruan/fineui
Treecat
2 years ago
43 changed files with 3433 additions and 2924 deletions
@ -0,0 +1,2 @@
|
||||
export { MultiLayerDownListCombo } from "./combo.downlist"; |
||||
export { MultiLayerDownListPopup } from "./popup.downlist"; |
@ -0,0 +1,7 @@
|
||||
export { MultiLayerSingleTreeCombo } from "./multilayersingletree.combo"; |
||||
export { MultiLayerSingleTreeInsertSearchPane } from "./multilayersingletree.insert.search.pane"; |
||||
export { MultiLayerSingleLevelTree } from "./multilayersingletree.leveltree"; |
||||
export { MultiLayerSingleTreePopup } from "./multilayersingletree.popup"; |
||||
export { MultiLayerSingleTreeTrigger } from "./multilayersingletree.trigger"; |
||||
export * from "./node"; |
||||
export * from "./treeitem"; |
@ -1,92 +1,110 @@
|
||||
/** |
||||
* Created by GUY on 2016/1/26. |
||||
* |
||||
* @class BI.MultiLayerSingleTreeInsertSearchPane |
||||
* @extends BI.Pane |
||||
*/ |
||||
import { |
||||
shortcut, |
||||
Widget, |
||||
i18nText, |
||||
emptyFn, |
||||
createWidget, |
||||
Controller, |
||||
VerticalLayout, |
||||
isEmptyArray, |
||||
isArray |
||||
} from "@/core"; |
||||
import { MultiLayerSelectLevelTree } from "../multilayerselecttree/multilayerselecttree.leveltree"; |
||||
import { TextButton } from "@/base"; |
||||
|
||||
BI.MultiLayerSingleTreeInsertSearchPane = BI.inherit(BI.Widget, { |
||||
@shortcut() |
||||
export class MultiLayerSingleTreeInsertSearchPane extends Widget { |
||||
static xtype = "bi.multilayer_single_tree_insert_search_pane"; |
||||
|
||||
props: function() { |
||||
static EVENT_ADD_ITEM = "EVENT_ADD_ITEM"; |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
props() { |
||||
return { |
||||
baseCls: "bi-multilayer-single-tree-popup", |
||||
tipText: BI.i18nText("BI-No_Selected_Item"), |
||||
tipText: i18nText("BI-No_Selected_Item"), |
||||
isDefaultInit: false, |
||||
itemsCreator: BI.emptyFn, |
||||
itemsCreator: emptyFn, |
||||
items: [], |
||||
value: "" |
||||
value: "", |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
render: function() { |
||||
var self = this, o = this.options; |
||||
this.tree = BI.createWidget({ |
||||
render() { |
||||
const o = this.options; |
||||
this.tree = createWidget({ |
||||
type: "bi.multilayer_single_level_tree", |
||||
isDefaultInit: o.isDefaultInit, |
||||
items: o.items, |
||||
itemsCreator: o.itemsCreator === BI.emptyFn ? BI.emptyFn : function (op, callback) { |
||||
o.itemsCreator(op, function (res) { |
||||
callback(res); |
||||
self.setKeyword(o.keywordGetter()); |
||||
}); |
||||
}, |
||||
itemsCreator: |
||||
o.itemsCreator === emptyFn |
||||
? emptyFn |
||||
: (op, callback) => { |
||||
o.itemsCreator(op, res => { |
||||
callback(res); |
||||
this.setKeyword(o.keywordGetter()); |
||||
}); |
||||
}, |
||||
keywordGetter: o.keywordGetter, |
||||
value: o.value, |
||||
scrollable: null, |
||||
listeners: [{ |
||||
eventName: BI.Controller.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
} |
||||
}, { |
||||
eventName: BI.MultiLayerSelectLevelTree.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE); |
||||
listeners: [ |
||||
{ |
||||
eventName: Controller.EVENT_CHANGE, |
||||
action: (...args) => { |
||||
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
||||
}, |
||||
}, |
||||
{ |
||||
eventName: MultiLayerSelectLevelTree.EVENT_CHANGE, |
||||
action: () => { |
||||
this.fireEvent(MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE); |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}); |
||||
|
||||
return { |
||||
type: "bi.vertical", |
||||
type: VerticalLayout.xtype, |
||||
scrolly: false, |
||||
scrollable: true, |
||||
vgap: 5, |
||||
items: [{ |
||||
type: "bi.text_button", |
||||
invisible: true, |
||||
text: BI.i18nText("BI-Basic_Click_To_Add_Text", ""), |
||||
height: 24, |
||||
cls: "bi-high-light", |
||||
hgap: 5, |
||||
ref: function (_ref) { |
||||
self.addNotMatchTip = _ref; |
||||
items: [ |
||||
{ |
||||
type: TextButton.xtype, |
||||
invisible: true, |
||||
text: i18nText("BI-Basic_Click_To_Add_Text", ""), |
||||
height: 24, |
||||
cls: "bi-high-light", |
||||
hgap: 5, |
||||
ref: _ref => { |
||||
this.addNotMatchTip = _ref; |
||||
}, |
||||
handler: () => { |
||||
this.fireEvent(MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, o.keywordGetter()); |
||||
}, |
||||
}, |
||||
handler: function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, o.keywordGetter()); |
||||
} |
||||
}, this.tree] |
||||
this.tree |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
setKeyword: function (keyword) { |
||||
var showTip = BI.isEmptyArray(this.tree.getAllLeaves()); |
||||
setKeyword(keyword) { |
||||
const showTip = isEmptyArray(this.tree.getAllLeaves()); |
||||
this.addNotMatchTip.setVisible(showTip); |
||||
showTip && this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Click_To_Add_Text", keyword)); |
||||
}, |
||||
showTip && this.addNotMatchTip.setText(i18nText("BI-Basic_Click_To_Add_Text", keyword)); |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.tree.getValue(); |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
setValue(v) { |
||||
v = isArray(v) ? v : [v]; |
||||
this.tree.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
populate(items) { |
||||
this.tree.populate(items); |
||||
} |
||||
}); |
||||
|
||||
BI.MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM = "EVENT_ADD_ITEM"; |
||||
BI.MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.multilayer_single_tree_insert_search_pane", BI.MultiLayerSingleTreeInsertSearchPane); |
||||
} |
||||
|
@ -1,170 +1,202 @@
|
||||
/** |
||||
* guy |
||||
* 二级树 |
||||
* @class BI.MultiLayerSingleLevelTree |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.MultiLayerSingleLevelTree = BI.inherit(BI.Pane, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.MultiLayerSingleLevelTree.superclass._defaultConfig.apply(this, arguments), { |
||||
import { |
||||
shortcut, |
||||
extend, |
||||
emptyFn, |
||||
Selection, |
||||
each, |
||||
isKey, |
||||
UUID, |
||||
isNotEmptyArray, |
||||
defaults, |
||||
createWidget, |
||||
Tree, |
||||
nextTick, |
||||
Controller, |
||||
Events, |
||||
VerticalLayout, |
||||
AdaptiveLayout, |
||||
isNull, |
||||
isArray |
||||
} from "@/core"; |
||||
import { Pane, CustomTree, Loader, ButtonTree } from "@/base"; |
||||
import { BasicTreeNode, BasicTreeItem, TreeExpander } from "@/case"; |
||||
|
||||
@shortcut() |
||||
export class MultiLayerSingleLevelTree extends Pane { |
||||
static xtype = "bi.multilayer_single_level_tree"; |
||||
|
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-multilayer-single-level-tree", |
||||
isDefaultInit: false, |
||||
items: [], |
||||
itemsCreator: BI.emptyFn, |
||||
keywordGetter: BI.emptyFn, |
||||
chooseType: BI.Selection.Single, |
||||
scrollable: true |
||||
itemsCreator: emptyFn, |
||||
keywordGetter: emptyFn, |
||||
chooseType: Selection.Single, |
||||
scrollable: true, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
var o = this.options; |
||||
BI.MultiLayerSingleLevelTree.superclass._init.apply(this, arguments); |
||||
_init() { |
||||
const o = this.options; |
||||
super._init(...arguments); |
||||
|
||||
this.storeValue = o.value; |
||||
|
||||
this.initTree(this.options.items); |
||||
|
||||
this.check(); |
||||
}, |
||||
} |
||||
|
||||
_formatItems: function (nodes, layer, pNode) { |
||||
var self = this, o = this.options; |
||||
var keyword = o.keywordGetter(); |
||||
BI.each(nodes, function (i, node) { |
||||
var extend = { |
||||
_formatItems(nodes, layer, pNode) { |
||||
const self = this, |
||||
o = this.options; |
||||
const keyword = o.keywordGetter(); |
||||
each(nodes, (i, node) => { |
||||
const extend = { |
||||
isFirstNode: i === 0, |
||||
isLastNode: i === nodes.length - 1, |
||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT |
||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
||||
}; |
||||
node.layer = layer; |
||||
if (!BI.isKey(node.id)) { |
||||
node.id = BI.UUID(); |
||||
if (!isKey(node.id)) { |
||||
node.id = UUID(); |
||||
} |
||||
node.keyword = node.keyword || keyword; |
||||
extend.pNode = pNode; |
||||
if (node.isParent === true || node.parent === true || BI.isNotEmptyArray(node.children)) { |
||||
extend.type = "bi.tree_node"; |
||||
if (node.isParent === true || node.parent === true || isNotEmptyArray(node.children)) { |
||||
extend.type = BasicTreeNode.xtype; |
||||
extend.selectable = false; |
||||
BI.defaults(node, extend); |
||||
defaults(node, extend); |
||||
self._formatItems(node.children, layer + 1, node); |
||||
} else { |
||||
extend.type = "bi.tree_item"; |
||||
BI.defaults(node, extend); |
||||
extend.type = BasicTreeItem.xtype; |
||||
defaults(node, extend); |
||||
} |
||||
}); |
||||
|
||||
return nodes; |
||||
}, |
||||
} |
||||
|
||||
_assertId: function (sNodes) { |
||||
BI.each(sNodes, function (i, node) { |
||||
node.id = node.id || BI.UUID(); |
||||
_assertId(sNodes) { |
||||
each(sNodes, (i, node) => { |
||||
node.id = node.id || UUID(); |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
// 构造树结构,
|
||||
initTree: function (nodes) { |
||||
var self = this, o = this.options; |
||||
var hasNext = false; |
||||
initTree(nodes) { |
||||
const self = this, |
||||
o = this.options; |
||||
let hasNext = false; |
||||
this.empty(); |
||||
this._assertId(nodes); |
||||
this.tree = BI.createWidget({ |
||||
type: "bi.custom_tree", |
||||
this.tree = createWidget({ |
||||
type: CustomTree.xtype, |
||||
cls: "tree-view display-table", |
||||
expander: { |
||||
type: "bi.tree_expander", |
||||
type: TreeExpander.xtype, |
||||
isDefaultInit: o.isDefaultInit, |
||||
el: {}, |
||||
popup: { |
||||
type: "bi.custom_tree" |
||||
} |
||||
type: CustomTree.xtype, |
||||
}, |
||||
}, |
||||
|
||||
items: this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0), |
||||
items: this._formatItems(Tree.transformToTreeFormat(nodes), 0), |
||||
value: o.value, |
||||
itemsCreator: function (op, callback) { |
||||
(op.times === 1 && !op.node) && BI.nextTick(function () { |
||||
self.loading(); |
||||
}); |
||||
o.itemsCreator(op, function (ob) { |
||||
itemsCreator (op, callback) { |
||||
op.times === 1 && |
||||
!op.node && |
||||
nextTick(() => { |
||||
self.loading(); |
||||
}); |
||||
o.itemsCreator(op, ob => { |
||||
hasNext = ob.hasNext; |
||||
(op.times === 1 && !op.node) && self._populate(ob.items); |
||||
callback(self._formatItems(BI.Tree.transformToTreeFormat(ob.items), op.node ? op.node.layer + 1 : 0, op.node)); |
||||
op.times === 1 && !op.node && self._populate(ob.items); |
||||
callback( |
||||
self._formatItems( |
||||
Tree.transformToTreeFormat(ob.items), |
||||
op.node ? op.node.layer + 1 : 0, |
||||
op.node |
||||
) |
||||
); |
||||
self.setValue(self.storeValue); |
||||
(op.times === 1 && !op.node) && BI.nextTick(function () { |
||||
self.loaded(); |
||||
}); |
||||
op.times === 1 && |
||||
!op.node && |
||||
nextTick(() => { |
||||
self.loaded(); |
||||
}); |
||||
}); |
||||
}, |
||||
|
||||
el: { |
||||
type: "bi.loader", |
||||
isDefaultInit: o.itemsCreator !== BI.emptyFn, |
||||
type: Loader.xtype, |
||||
isDefaultInit: o.itemsCreator !== emptyFn, |
||||
el: { |
||||
type: "bi.button_tree", |
||||
chooseType: o.chooseType === BI.Selection.None ? BI.Selection.None : BI.Selection.Default, // 不使用buttontree内部getValue逻辑
|
||||
type: ButtonTree.xtype, |
||||
chooseType: o.chooseType === Selection.None ? Selection.None : Selection.Default, // 不使用buttontree内部getValue逻辑
|
||||
behaviors: o.behaviors, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
layouts: [ |
||||
{ |
||||
type: VerticalLayout.xtype, |
||||
} |
||||
], |
||||
}, |
||||
hasNext: function () { |
||||
hasNext () { |
||||
return hasNext; |
||||
} |
||||
} |
||||
}, |
||||
}, |
||||
}); |
||||
this.tree.on(BI.Controller.EVENT_CHANGE, function (type, v) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
this.tree.on(Controller.EVENT_CHANGE, function (type, v) { |
||||
self.fireEvent(Controller.EVENT_CHANGE, arguments); |
||||
if (type === Events.CLICK) { |
||||
self.setValue(v); |
||||
self.fireEvent(BI.MultiLayerSingleLevelTree.EVENT_CHANGE, v); |
||||
self.fireEvent(MultiLayerSingleLevelTree.EVENT_CHANGE, v); |
||||
} |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.adaptive", |
||||
createWidget({ |
||||
type: AdaptiveLayout.xtype, |
||||
element: this, |
||||
scrollable: o.scrollable, |
||||
items: [this.tree] |
||||
items: [this.tree], |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_populate: function () { |
||||
BI.MultiLayerSelectLevelTree.superclass.populate.apply(this, arguments); |
||||
}, |
||||
_populate() { |
||||
super.populate(...arguments); |
||||
} |
||||
|
||||
populate: function (nodes) { |
||||
populate(nodes) { |
||||
this._populate(nodes); |
||||
BI.isNull(nodes) ? this.tree.populate() : this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0)); |
||||
}, |
||||
isNull(nodes) |
||||
? this.tree.populate() |
||||
: this.tree.populate(this._formatItems(Tree.transformToTreeFormat(nodes), 0)); |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
// getValue依赖于storeValue, 那么不选的时候就不要更新storeValue了
|
||||
if (this.options.chooseType === BI.Selection.None) { |
||||
} else { |
||||
if (this.options.chooseType !== Selection.None) { |
||||
this.storeValue = v; |
||||
this.tree.setValue(v); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
return BI.isArray(this.storeValue) ? |
||||
this.storeValue : BI.isNull(this.storeValue) ? |
||||
[] : [this.storeValue]; |
||||
}, |
||||
getValue() { |
||||
return isArray(this.storeValue) ? this.storeValue : isNull(this.storeValue) ? [] : [this.storeValue]; |
||||
} |
||||
|
||||
getAllLeaves: function () { |
||||
getAllLeaves() { |
||||
return this.tree.getAllLeaves(); |
||||
}, |
||||
} |
||||
|
||||
getNodeById: function (id) { |
||||
getNodeById(id) { |
||||
return this.tree.getNodeById(id); |
||||
}, |
||||
} |
||||
|
||||
getNodeByValue: function (id) { |
||||
getNodeByValue(id) { |
||||
return this.tree.getNodeByValue(id); |
||||
} |
||||
}); |
||||
BI.MultiLayerSingleLevelTree.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
BI.shortcut("bi.multilayer_single_level_tree", BI.MultiLayerSingleLevelTree); |
||||
} |
||||
|
@ -1,76 +1,73 @@
|
||||
/** |
||||
* Created by GUY on 2016/1/26. |
||||
* |
||||
* @class BI.MultiLayerSingleTreePopup |
||||
* @extends BI.Pane |
||||
*/ |
||||
import { shortcut, Widget, extend, i18nText, emptyFn, createWidget, Controller, VerticalLayout, isArray, pixFormat } from "@/core"; |
||||
import { MultiLayerSingleLevelTree } from "./multilayersingletree.leveltree"; |
||||
|
||||
BI.MultiLayerSingleTreePopup = BI.inherit(BI.Widget, { |
||||
@shortcut() |
||||
export class MultiLayerSingleTreePopup extends Widget { |
||||
static xtype = "bi.multilayer_single_tree_popup"; |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.MultiLayerSingleTreePopup.superclass._defaultConfig.apply(this, arguments), { |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-multilayer-singletree-popup", |
||||
tipText: BI.i18nText("BI-No_Selected_Item"), |
||||
tipText: i18nText("BI-No_Selected_Item"), |
||||
isDefaultInit: false, |
||||
itemsCreator: BI.emptyFn, |
||||
itemsCreator: emptyFn, |
||||
items: [], |
||||
onLoaded: BI.emptyFn, |
||||
minHeight: 240 |
||||
onLoaded: emptyFn, |
||||
minHeight: 240, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.MultiLayerSingleTreePopup.superclass._init.apply(this, arguments); |
||||
_init() { |
||||
super._init(...arguments); |
||||
|
||||
var self = this, o = this.options; |
||||
const o = this.options; |
||||
|
||||
this.tree = BI.createWidget({ |
||||
type: "bi.multilayer_single_level_tree", |
||||
this.tree = createWidget({ |
||||
type: MultiLayerSingleLevelTree.xtype, |
||||
isDefaultInit: o.isDefaultInit, |
||||
items: o.items, |
||||
itemsCreator: o.itemsCreator, |
||||
keywordGetter: o.keywordGetter, |
||||
value: o.value, |
||||
scrollable: null, |
||||
onLoaded: function () { |
||||
self.tree.check(); |
||||
onLoaded: () => { |
||||
this.tree.check(); |
||||
o.onLoaded(); |
||||
} |
||||
}, |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
createWidget({ |
||||
type: VerticalLayout.xtype, |
||||
scrolly: false, |
||||
scrollable: true, |
||||
element: this, |
||||
vgap: 5, |
||||
items: [this.tree] |
||||
items: [this.tree], |
||||
}); |
||||
|
||||
this.tree.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
this.tree.on(Controller.EVENT_CHANGE, (...args) => { |
||||
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
||||
}); |
||||
|
||||
this.tree.on(BI.MultiLayerSingleLevelTree.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreePopup.EVENT_CHANGE); |
||||
this.tree.on(MultiLayerSingleLevelTree.EVENT_CHANGE, () => { |
||||
this.fireEvent(MultiLayerSingleTreePopup.EVENT_CHANGE); |
||||
}); |
||||
|
||||
this.tree.css("min-height", BI.pixFormat(o.minHeight - 10)); |
||||
}, |
||||
this.tree.css("min-height", pixFormat(o.minHeight - 10)); |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.tree.getValue(); |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
setValue(v) { |
||||
v = isArray(v) ? v : [v]; |
||||
this.tree.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
populate(items) { |
||||
this.tree.populate(items); |
||||
} |
||||
}); |
||||
|
||||
BI.MultiLayerSingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.multilayer_single_tree_popup", BI.MultiLayerSingleTreePopup); |
||||
} |
||||
|
@ -1,237 +1,282 @@
|
||||
/** |
||||
* Created by Windy on 2018/2/2. |
||||
*/ |
||||
BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { |
||||
import { |
||||
shortcut, |
||||
emptyFn, |
||||
i18nText, |
||||
bind, |
||||
isNotNull, |
||||
isKey, |
||||
HorizontalFillLayout, |
||||
Tree, |
||||
deepClone, |
||||
Func, |
||||
concat, |
||||
isNotEmptyArray, |
||||
each, |
||||
uniqBy, |
||||
map, |
||||
isFunction, |
||||
find |
||||
} from "@/core"; |
||||
import { Trigger, Searcher } from "@/base"; |
||||
import { StateEditor, DefaultTextEditor } from "@/case"; |
||||
import { MultiLayerSingleTreeInsertSearchPane } from "./multilayersingletree.insert.search.pane"; |
||||
import { MultiLayerSingleTreePopup } from "./multilayersingletree.popup"; |
||||
|
||||
props: function () { |
||||
@shortcut() |
||||
export class MultiLayerSingleTreeTrigger extends Trigger { |
||||
static xtype = "bi.multilayer_single_tree_trigger"; |
||||
|
||||
static EVENT_FOCUS = "EVENT_FOCUS"; |
||||
static EVENT_BLUR = "EVENT_BLUR"; |
||||
static EVENT_SEARCHING = "EVENT_SEARCHING"; |
||||
static EVENT_STOP = "EVENT_STOP"; |
||||
static EVENT_START = "EVENT_START"; |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
static EVENT_ADD_ITEM = "EVENT_ADD_ITEM"; |
||||
|
||||
props() { |
||||
return { |
||||
extraCls: "bi-multi-layer-single-tree-trigger", |
||||
height: 24, |
||||
itemsCreator: BI.emptyFn, |
||||
watermark: BI.i18nText("BI-Basic_Search"), |
||||
itemsCreator: emptyFn, |
||||
watermark: i18nText("BI-Basic_Search"), |
||||
allowSearchValue: false, |
||||
title: BI.bind(this._getShowText, this) |
||||
title: bind(this._getShowText, this), |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
if (o.itemsCreator === BI.emptyFn) { |
||||
render() { |
||||
const self = this, |
||||
o = this.options; |
||||
if (o.itemsCreator === emptyFn) { |
||||
this._initData(); |
||||
} |
||||
|
||||
return { |
||||
type: "bi.horizontal_fill", |
||||
type: HorizontalFillLayout.xtype, |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: "bi.searcher", |
||||
ref: function () { |
||||
type: Searcher.xtype, |
||||
ref () { |
||||
self.searcher = this; |
||||
}, |
||||
masker: BI.isNotNull(o.container) ? { |
||||
offset: {}, |
||||
container: o.container |
||||
} : { |
||||
offset: {} |
||||
}, |
||||
masker: isNotNull(o.container) |
||||
? { |
||||
offset: {}, |
||||
container: o.container, |
||||
} |
||||
: { |
||||
offset: {}, |
||||
}, |
||||
isAutoSearch: false, |
||||
el: { |
||||
type: "bi.default_text_editor", |
||||
ref: function () { |
||||
type: DefaultTextEditor.xtype, |
||||
ref () { |
||||
self.editor = this; |
||||
}, |
||||
defaultText: o.defaultText, |
||||
text: BI.isKey(o.value) ? this._digest(o.value) : o.text, |
||||
text: isKey(o.value) ? this._digest(o.value) : o.text, |
||||
value: o.value, |
||||
height: o.height, |
||||
tipText: "", |
||||
watermark: o.watermark, |
||||
listeners: [{ |
||||
eventName: BI.StateEditor.EVENT_FOCUS, |
||||
action: function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_FOCUS); |
||||
} |
||||
}, { |
||||
eventName: BI.StateEditor.EVENT_BLUR, |
||||
action: function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_BLUR); |
||||
listeners: [ |
||||
{ |
||||
eventName: StateEditor.EVENT_FOCUS, |
||||
action () { |
||||
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_FOCUS); |
||||
}, |
||||
}, |
||||
{ |
||||
eventName: StateEditor.EVENT_BLUR, |
||||
action () { |
||||
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_BLUR); |
||||
}, |
||||
}, |
||||
{ |
||||
eventName: StateEditor.EVENT_CHANGE, |
||||
action () { |
||||
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_SEARCHING); |
||||
}, |
||||
} |
||||
}, { |
||||
eventName: BI.StateEditor.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_SEARCHING); |
||||
} |
||||
}] |
||||
], |
||||
}, |
||||
popup: { |
||||
type: o.allowInsertValue ? "bi.multilayer_single_tree_insert_search_pane" : "bi.multilayer_single_tree_popup", |
||||
itemsCreator: o.itemsCreator === BI.emptyFn ? BI.emptyFn : function (op, callback) { |
||||
op.keyword = self.editor.getValue(); |
||||
o.itemsCreator(op, callback); |
||||
}, |
||||
keywordGetter: function () { |
||||
type: o.allowInsertValue |
||||
? MultiLayerSingleTreeInsertSearchPane.xtype |
||||
: MultiLayerSingleTreePopup.xtype, |
||||
itemsCreator: |
||||
o.itemsCreator === emptyFn |
||||
? emptyFn |
||||
: function (op, callback) { |
||||
op.keyword = self.editor.getValue(); |
||||
o.itemsCreator(op, callback); |
||||
}, |
||||
keywordGetter () { |
||||
return self.editor.getValue(); |
||||
}, |
||||
cls: "bi-card", |
||||
listeners: [{ |
||||
eventName: BI.MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, |
||||
action: function () { |
||||
self.options.text = self.getSearcher().getKeyword(); |
||||
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM); |
||||
listeners: [ |
||||
{ |
||||
eventName: MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, |
||||
action () { |
||||
self.options.text = self.getSearcher().getKeyword(); |
||||
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM); |
||||
}, |
||||
} |
||||
}], |
||||
ref: function (_ref) { |
||||
], |
||||
ref (_ref) { |
||||
self.popup = _ref; |
||||
} |
||||
}, |
||||
}, |
||||
onSearch: function (obj, callback) { |
||||
var keyword = obj.keyword; |
||||
if (o.itemsCreator === BI.emptyFn) { |
||||
onSearch (obj, callback) { |
||||
const keyword = obj.keyword; |
||||
if (o.itemsCreator === emptyFn) { |
||||
callback(self._getSearchItems(keyword)); |
||||
o.allowInsertValue && self.popup.setKeyword(keyword); |
||||
} else { |
||||
callback(); |
||||
} |
||||
}, |
||||
listeners: [{ |
||||
eventName: BI.Searcher.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_CHANGE); |
||||
listeners: [ |
||||
{ |
||||
eventName: Searcher.EVENT_CHANGE, |
||||
action () { |
||||
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_CHANGE); |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}, |
||||
width: "fill", |
||||
rgap: 24, |
||||
}, |
||||
] |
||||
} |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
_initData: function () { |
||||
var o = this.options; |
||||
this.tree = new BI.Tree(); |
||||
this.nodes = BI.Tree.treeFormat(BI.deepClone(o.items)); |
||||
_initData() { |
||||
const o = this.options; |
||||
this.tree = new Tree(); |
||||
this.nodes = Tree.treeFormat(deepClone(o.items)); |
||||
this.tree.initTree(this.nodes); |
||||
}, |
||||
} |
||||
|
||||
_getSearchItems: function (keyword) { |
||||
var self = this, o = this.options; |
||||
_getSearchItems(keyword) { |
||||
const self = this, |
||||
o = this.options; |
||||
// 把数组搜索换成用BI.tree搜索节点, 搜到了就不再往下搜索
|
||||
var items = []; |
||||
this.tree.traverse(function (node) { |
||||
var find = BI.Func.getSearchResult(self.tree.isRoot(node) ? [] : BI.concat([node.text], (o.allowSearchValue ? [node.value] : [])), keyword); |
||||
const items = []; |
||||
this.tree.traverse(node => { |
||||
const find = Func.getSearchResult( |
||||
self.tree.isRoot(node) ? [] : concat([node.text], o.allowSearchValue ? [node.value] : []), |
||||
keyword |
||||
); |
||||
if (find.find.length > 0 || find.match.length > 0) { |
||||
items.push(node); |
||||
|
||||
return true; |
||||
} |
||||
}); |
||||
|
||||
return this._fillTreeStructure4Search(items, "id"); |
||||
}, |
||||
} |
||||
|
||||
_createJson: function (node, open) { |
||||
_createJson(node, open) { |
||||
return { |
||||
id: node.id, |
||||
pId: node.pId, |
||||
text: node.text, |
||||
value: node.value, |
||||
isParent: BI.isNotEmptyArray(node.children), |
||||
open: open |
||||
isParent: isNotEmptyArray(node.children), |
||||
open, |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
_getChildren: function (node) { |
||||
var self = this; |
||||
_getChildren(node) { |
||||
const self = this; |
||||
node.children = node.children || []; |
||||
var nodes = []; |
||||
BI.each(node.children, function (idx, child) { |
||||
var children = self._getChildren(child); |
||||
let nodes = []; |
||||
each(node.children, (idx, child) => { |
||||
const children = self._getChildren(child); |
||||
nodes = nodes.concat(children); |
||||
}); |
||||
|
||||
return node.children.concat(nodes); |
||||
}, |
||||
|
||||
// 将搜索到的节点进行补充,构造成一棵完整的树
|
||||
_fillTreeStructure4Search: function (leaves) { |
||||
var self = this; |
||||
var result = []; |
||||
var queue = []; |
||||
BI.each(leaves, function (idx, node) { |
||||
} |
||||
|
||||
_fillTreeStructure4Search(leaves) { |
||||
const self = this; |
||||
let result = []; |
||||
const queue = []; |
||||
each(leaves, (idx, node) => { |
||||
queue.push({ pId: node.pId }); |
||||
result.push(node); |
||||
result = result.concat(self._getChildren(node)); |
||||
}); |
||||
queue.reverse(); |
||||
while (BI.isNotEmptyArray(queue)) { |
||||
var node = queue.pop(); |
||||
var pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); |
||||
while (isNotEmptyArray(queue)) { |
||||
const node = queue.pop(); |
||||
const pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); |
||||
if (pNode != null) { |
||||
pNode.open = true; |
||||
queue.push({ pId: pNode.pId }); |
||||
result.push(pNode); |
||||
} |
||||
} |
||||
return BI.uniqBy(BI.map(result, function (idx, node) { |
||||
return self._createJson(node, node.open); |
||||
}), "id"); |
||||
}, |
||||
|
||||
return uniqBy( |
||||
map(result, (idx, node) => self._createJson(node, node.open)), |
||||
"id" |
||||
); |
||||
} |
||||
|
||||
_digest: function (v) { |
||||
var o = this.options; |
||||
_digest(v) { |
||||
const o = this.options; |
||||
|
||||
if (BI.isFunction(o.valueFormatter)) { |
||||
if (isFunction(o.valueFormatter)) { |
||||
return o.valueFormatter(v); |
||||
} |
||||
|
||||
var result = BI.find(o.items, function (i, item) { |
||||
return item.value === v; |
||||
}); |
||||
const result = find(o.items, (i, item) => item.value === v); |
||||
|
||||
return BI.isNotNull(result) ? result.text : (o.text ?? v); |
||||
}, |
||||
return isNotNull(result) ? result.text : o.text ?? v; |
||||
} |
||||
|
||||
_getShowText: function () { |
||||
_getShowText() { |
||||
return this.editor.getText(); |
||||
}, |
||||
} |
||||
|
||||
stopEditing: function () { |
||||
stopEditing() { |
||||
this.searcher.stopSearch(); |
||||
}, |
||||
} |
||||
|
||||
getSearcher: function () { |
||||
getSearcher() { |
||||
return this.searcher; |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
populate(items) { |
||||
this.options.items = items; |
||||
this._initData(); |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
this.editor.setState(this._digest(v[0])); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.searcher.getValue(); |
||||
}, |
||||
} |
||||
|
||||
focus: function () { |
||||
focus() { |
||||
this.searcher.focus(); |
||||
}, |
||||
} |
||||
|
||||
blur: function () { |
||||
blur() { |
||||
this.searcher.blur(); |
||||
}, |
||||
} |
||||
|
||||
setWaterMark: function (v) { |
||||
setWaterMark(v) { |
||||
this.searcher.setWaterMark(v); |
||||
} |
||||
}); |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_STOP = "EVENT_STOP"; |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_START = "EVENT_START"; |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM = "EVENT_ADD_ITEM"; |
||||
BI.shortcut("bi.multilayer_single_tree_trigger", BI.MultiLayerSingleTreeTrigger); |
||||
} |
||||
|
@ -0,0 +1,4 @@
|
||||
export { MultiLayerSingleTreeFirstPlusGroupNode } from "./node.first.plus"; |
||||
export { MultiLayerSingleTreeLastPlusGroupNode } from "./node.last.plus"; |
||||
export { MultiLayerSingleTreeMidPlusGroupNode } from "./node.mid.plus"; |
||||
export { MultiLayerSingleTreePlusGroupNode } from "./node.plus"; |
@ -0,0 +1,3 @@
|
||||
export { MultiLayerSingleTreeFirstTreeLeafItem } from "./item.first.treeleaf"; |
||||
export { MultiLayerSingleTreeLastTreeLeafItem } from "./item.last.treeleaf"; |
||||
export { MultiLayerSingleTreeMidTreeLeafItem } from "./item.mid.treeleaf"; |
@ -0,0 +1,9 @@
|
||||
export { SingleSelectCombo } from "./singleselect.combo"; |
||||
export { SingleSelectInsertCombo } from "./singleselect.insert.combo"; |
||||
export { SingleSelectList } from "./singleselect.list"; |
||||
export { SingleSelectLoader } from "./singleselect.loader"; |
||||
export { SingleSelectPopupView } from "./singleselect.popup.view"; |
||||
export { SingleSelectTrigger } from "./singleselect.trigger"; |
||||
export { SingleSelectInsertList } from "./singleselectlist.insert"; |
||||
export * from "./trigger"; |
||||
export * from "./search"; |
@ -0,0 +1,3 @@
|
||||
export { SingleSelectSearchLoader } from "./singleselect.search.loader"; |
||||
export { SingleSelectSearchPane } from "./singleselect.search.pane"; |
||||
export { SingleSelectSearchInsertPane } from "./singleselect.search.pane.insert"; |
@ -1,96 +1,96 @@
|
||||
/** |
||||
* |
||||
* 在搜索框中输入文本弹出的面板 |
||||
* @class BI.SingleSelectSearchInsertPane |
||||
* @extends Widget |
||||
*/ |
||||
import { shortcut, Widget, extend, emptyFn, createWidget, i18nText, Controller, VerticalFillLayout, VerticalLayout } from "@/core"; |
||||
import { Label } from "@/base"; |
||||
import { SingleSelectSearchLoader } from "./singleselect.search.loader"; |
||||
|
||||
BI.SingleSelectSearchInsertPane = BI.inherit(BI.Widget, { |
||||
@shortcut() |
||||
export class SingleSelectSearchInsertPane extends Widget { |
||||
static xtype = "bi.single_select_search_insert_pane"; |
||||
|
||||
constants: { |
||||
height: 25, |
||||
lgap: 10, |
||||
tgap: 5 |
||||
}, |
||||
constants = { height: 25, lgap: 10, tgap: 5 }; |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectSearchInsertPane.superclass._defaultConfig.apply(this, arguments), { |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-single-select-search-pane-insert bi-card", |
||||
allowNoSelect: false, |
||||
itemsCreator: BI.emptyFn, |
||||
valueFormatter: BI.emptyFn, |
||||
keywordGetter: BI.emptyFn |
||||
itemsCreator: emptyFn, |
||||
valueFormatter: emptyFn, |
||||
keywordGetter: emptyFn, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SingleSelectSearchInsertPane.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
_init() { |
||||
super._init(...arguments); |
||||
const self = this, |
||||
o = this.options; |
||||
|
||||
this.addNotMatchTip = BI.createWidget({ |
||||
type: "bi.label", |
||||
text: BI.i18nText("BI-Basic_Press_Enter_To_Add_Text", ""), |
||||
this.addNotMatchTip = createWidget({ |
||||
type: Label.xtype, |
||||
text: i18nText("BI-Basic_Press_Enter_To_Add_Text", ""), |
||||
height: this.constants.height, |
||||
cls: "bi-keyword-red-mark", |
||||
hgap: 5, |
||||
}); |
||||
|
||||
this.loader = BI.createWidget({ |
||||
type: "bi.single_select_search_loader", |
||||
this.loader = createWidget({ |
||||
type: SingleSelectSearchLoader.xtype, |
||||
allowNoSelect: o.allowNoSelect, |
||||
keywordGetter: o.keywordGetter, |
||||
valueFormatter: o.valueFormatter, |
||||
itemsCreator: function (op, callback) { |
||||
o.itemsCreator.apply(self, [op, function (res) { |
||||
callback(res); |
||||
self.setKeyword(o.keywordGetter()); |
||||
}]); |
||||
itemsCreator (op, callback) { |
||||
o.itemsCreator.apply(self, [ |
||||
op, |
||||
function (res) { |
||||
callback(res); |
||||
self.setKeyword(o.keywordGetter()); |
||||
} |
||||
]); |
||||
}, |
||||
value: o.value |
||||
value: o.value, |
||||
}); |
||||
this.loader.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
this.loader.on(Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
|
||||
this.resizer = BI.createWidget({ |
||||
type: "bi.vertical_fill", |
||||
this.resizer = createWidget({ |
||||
type: VerticalFillLayout.xtype, |
||||
rowSize: ["", "fill"], |
||||
element: this, |
||||
items: [{ |
||||
type: "bi.vertical", |
||||
items: [this.addNotMatchTip], |
||||
height: this.constants.height |
||||
}, { |
||||
el: this.loader |
||||
}] |
||||
items: [ |
||||
{ |
||||
type: VerticalLayout.xtype, |
||||
items: [this.addNotMatchTip], |
||||
height: this.constants.height, |
||||
}, |
||||
{ |
||||
el: this.loader, |
||||
} |
||||
], |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
setKeyword: function (keyword) { |
||||
this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Press_Enter_To_Add_Text", keyword)); |
||||
}, |
||||
setKeyword(keyword) { |
||||
this.addNotMatchTip.setText(i18nText("BI-Basic_Press_Enter_To_Add_Text", keyword)); |
||||
} |
||||
|
||||
hasMatched: function () { |
||||
hasMatched() { |
||||
return false; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
this.loader.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.loader.getValue(); |
||||
}, |
||||
} |
||||
|
||||
empty: function () { |
||||
empty() { |
||||
this.loader.empty(); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.loader.populate.apply(this.loader, arguments); |
||||
} |
||||
}); |
||||
|
||||
BI.SingleSelectSearchInsertPane.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
BI.shortcut("bi.single_select_search_insert_pane", BI.SingleSelectSearchInsertPane); |
||||
populate(items) { |
||||
this.loader.populate(...arguments); |
||||
} |
||||
} |
||||
|
@ -1,101 +1,105 @@
|
||||
/** |
||||
* |
||||
* 在搜索框中输入文本弹出的面板 |
||||
* @class BI.SingleSelectSearchPane |
||||
* @extends Widget |
||||
*/ |
||||
import { shortcut, Widget, extend, emptyFn, createWidget, i18nText, Controller, VerticalFillLayout } from "@/core"; |
||||
import { Label } from "@/base"; |
||||
import { SingleSelectSearchLoader } from "./singleselect.search.loader"; |
||||
|
||||
BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { |
||||
@shortcut() |
||||
export class SingleSelectSearchPane extends Widget { |
||||
static xtype = "bi.single_select_search_pane"; |
||||
|
||||
constants: { |
||||
height: 25, |
||||
lgap: 10, |
||||
tgap: 5 |
||||
}, |
||||
constants = { height: 25, lgap: 10, tgap: 5 }; |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-single-select-search-pane bi-card", |
||||
allowNoSelect: false, |
||||
itemsCreator: BI.emptyFn, |
||||
valueFormatter: BI.emptyFn, |
||||
keywordGetter: BI.emptyFn |
||||
itemsCreator: emptyFn, |
||||
valueFormatter: emptyFn, |
||||
keywordGetter: emptyFn, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
_init() { |
||||
super._init(...arguments); |
||||
const self = this, |
||||
o = this.options; |
||||
|
||||
this.tooltipClick = BI.createWidget({ |
||||
type: "bi.label", |
||||
this.tooltipClick = createWidget({ |
||||
type: Label.xtype, |
||||
invisible: true, |
||||
text: BI.i18nText("BI-Click_Blank_To_Select"), |
||||
text: i18nText("BI-Click_Blank_To_Select"), |
||||
cls: "single-select-toolbar", |
||||
height: this.constants.height |
||||
height: this.constants.height, |
||||
}); |
||||
|
||||
this.loader = BI.createWidget({ |
||||
type: "bi.single_select_search_loader", |
||||
this.loader = createWidget({ |
||||
type: SingleSelectSearchLoader.xtype, |
||||
allowNoSelect: o.allowNoSelect, |
||||
keywordGetter: o.keywordGetter, |
||||
valueFormatter: o.valueFormatter, |
||||
itemsCreator: function (op, callback) { |
||||
o.itemsCreator.apply(self, [op, function (res) { |
||||
callback(res); |
||||
self.setKeyword(o.keywordGetter()); |
||||
}]); |
||||
itemsCreator (op, callback) { |
||||
o.itemsCreator.apply(self, [ |
||||
op, |
||||
function (res) { |
||||
callback(res); |
||||
self.setKeyword(o.keywordGetter()); |
||||
} |
||||
]); |
||||
}, |
||||
value: o.value |
||||
value: o.value, |
||||
}); |
||||
this.loader.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
this.loader.on(Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
|
||||
this.resizer = BI.createWidget({ |
||||
type: "bi.vertical_fill", |
||||
this.resizer = createWidget({ |
||||
type: VerticalFillLayout.xtype, |
||||
rowSize: ["", "fill"], |
||||
element: this, |
||||
items: [{ |
||||
el: this.tooltipClick, |
||||
}, { |
||||
el: this.loader |
||||
}] |
||||
items: [ |
||||
{ |
||||
el: this.tooltipClick, |
||||
}, |
||||
{ |
||||
el: this.loader, |
||||
} |
||||
], |
||||
}); |
||||
this.tooltipClick.setVisible(false); |
||||
}, |
||||
} |
||||
|
||||
setKeyword: function (keyword) { |
||||
var btn, o = this.options; |
||||
var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === (o.valueFormatter(btn.getValue()) || btn.getValue())); |
||||
setKeyword(keyword) { |
||||
let btn; |
||||
const o = this.options; |
||||
const isVisible = |
||||
this.loader.getAllButtons().length > 0 && |
||||
(btn = this.loader.getAllButtons()[0]) && |
||||
keyword === (o.valueFormatter(btn.getValue()) || btn.getValue()); |
||||
if (isVisible !== this.tooltipClick.isVisible()) { |
||||
this.tooltipClick.setVisible(isVisible); |
||||
this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); |
||||
this.resizer.attr("items")[0].height = isVisible ? this.constants.height : 0; |
||||
this.resizer.resize(); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
hasMatched: function () { |
||||
hasMatched() { |
||||
return this.tooltipClick.isVisible(); |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
this.loader.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.loader.getValue(); |
||||
}, |
||||
} |
||||
|
||||
empty: function () { |
||||
empty() { |
||||
this.loader.empty(); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.loader.populate.apply(this.loader, arguments); |
||||
} |
||||
}); |
||||
|
||||
BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane); |
||||
populate(items) { |
||||
this.loader.populate(...arguments); |
||||
} |
||||
} |
||||
|
@ -1,178 +1,187 @@
|
||||
/** |
||||
* 单选加载数据面板 |
||||
* Created by guy on 15/11/2. |
||||
* @class BI.SingleSelectLoader |
||||
* @extends Widget |
||||
*/ |
||||
BI.SingleSelectLoader = BI.inherit(BI.Widget, { |
||||
|
||||
_constants: { |
||||
itemVgap: 5 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { |
||||
import { shortcut, Widget, extend, emptyFn, createWidget, isUndefined, map, isKey, Controller, VerticalLayout, delay } from "@/core"; |
||||
import { ButtonGroup, Loader } from "@/base"; |
||||
import { SingleSelectList } from "./singleselect.list"; |
||||
import { SingleSelectItem, SingleSelectRadioItem } from "@/case"; |
||||
|
||||
@shortcut() |
||||
export class SingleSelectLoader extends Widget { |
||||
static xtype = "bi.single_select_loader"; |
||||
|
||||
_constants = { itemVgap: 5 }; |
||||
|
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-single-select-loader", |
||||
logic: { |
||||
dynamic: true |
||||
dynamic: true, |
||||
}, |
||||
el: { |
||||
height: 400 |
||||
height: 400, |
||||
}, |
||||
allowNoSelect: false, |
||||
valueFormatter: BI.emptyFn, |
||||
itemsCreator: BI.emptyFn, |
||||
itemWrapper: BI.emptyFn, |
||||
onLoaded: BI.emptyFn |
||||
valueFormatter: emptyFn, |
||||
itemsCreator: emptyFn, |
||||
itemWrapper: emptyFn, |
||||
onLoaded: emptyFn, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SingleSelectLoader.superclass._init.apply(this, arguments); |
||||
_init() { |
||||
super._init(...arguments); |
||||
|
||||
var self = this, opts = this.options; |
||||
var hasNext = false; |
||||
const self = this, |
||||
opts = this.options; |
||||
let hasNext = false; |
||||
this.storeValue = opts.value; |
||||
this.button_group = BI.createWidget({ |
||||
type: "bi.single_select_list", |
||||
this.button_group = createWidget({ |
||||
type: SingleSelectList.xtype, |
||||
allowNoSelect: opts.allowNoSelect, |
||||
logic: opts.logic, |
||||
el: BI.extend({ |
||||
onLoaded: opts.onLoaded, |
||||
el: { |
||||
type: "bi.loader", |
||||
isDefaultInit: false, |
||||
logic: { |
||||
dynamic: true, |
||||
scrolly: true |
||||
}, |
||||
el: extend( |
||||
{ |
||||
onLoaded: opts.onLoaded, |
||||
el: { |
||||
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, |
||||
behaviors: { |
||||
redmark: function () { |
||||
return true; |
||||
} |
||||
type: Loader.xtype, |
||||
isDefaultInit: false, |
||||
logic: { |
||||
dynamic: true, |
||||
scrolly: true, |
||||
}, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
} |
||||
}, opts.el), |
||||
itemsCreator: function (op, callback) { |
||||
var startValue = self._startValue; |
||||
!BI.isUndefined(self.storeValue) && (op = BI.extend(op || {}, { |
||||
selectedValues: [self.storeValue] |
||||
})); |
||||
opts.itemsCreator(op, function (ob) { |
||||
el: { |
||||
chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE, |
||||
behaviors: { |
||||
redmark () { |
||||
return true; |
||||
}, |
||||
}, |
||||
layouts: [ |
||||
{ |
||||
type: VerticalLayout.xtype, |
||||
} |
||||
], |
||||
}, |
||||
}, |
||||
}, |
||||
opts.el |
||||
), |
||||
itemsCreator (op, callback) { |
||||
const startValue = self._startValue; |
||||
!isUndefined(self.storeValue) && |
||||
(op = extend(op || {}, { |
||||
selectedValues: [self.storeValue], |
||||
})); |
||||
opts.itemsCreator(op, ob => { |
||||
hasNext = ob.hasNext; |
||||
var firstItems = []; |
||||
if (op.times === 1 && !BI.isUndefined(self.storeValue)) { |
||||
var json = BI.map([self.storeValue], function (i, v) { |
||||
var txt = opts.valueFormatter(v) || v; |
||||
return opts.itemWrapper({ |
||||
text: txt, |
||||
value: v, |
||||
title: txt, |
||||
selected: true |
||||
}) || { |
||||
text: txt, |
||||
value: v, |
||||
title: txt, |
||||
selected: true |
||||
}; |
||||
let firstItems = []; |
||||
if (op.times === 1 && !isUndefined(self.storeValue)) { |
||||
const json = map([self.storeValue], (i, v) => { |
||||
const txt = opts.valueFormatter(v) || v; |
||||
|
||||
return ( |
||||
opts.itemWrapper({ |
||||
text: txt, |
||||
value: v, |
||||
title: txt, |
||||
selected: true, |
||||
}) || { |
||||
text: txt, |
||||
value: v, |
||||
title: txt, |
||||
selected: true, |
||||
} |
||||
); |
||||
}); |
||||
firstItems = self._createItems(json); |
||||
} |
||||
callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); |
||||
if (op.times === 1 && self.storeValue) { |
||||
BI.isKey(startValue) && (self.storeValue = startValue); |
||||
isKey(startValue) && (self.storeValue = startValue); |
||||
self.setValue(self.storeValue); |
||||
} |
||||
(op.times === 1) && self._scrollToTop(); |
||||
op.times === 1 && self._scrollToTop(); |
||||
}); |
||||
}, |
||||
hasNext: function () { |
||||
hasNext () { |
||||
return hasNext; |
||||
}, |
||||
value: this.storeValue |
||||
value: this.storeValue, |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
createWidget({ |
||||
type: VerticalLayout.xtype, |
||||
element: this, |
||||
items: [this.button_group], |
||||
vgap: this._constants.itemVgap |
||||
vgap: this._constants.itemVgap, |
||||
}); |
||||
|
||||
this.button_group.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
this.button_group.on(Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); |
||||
this.button_group.on(SingleSelectList.EVENT_CHANGE, function () { |
||||
self.fireEvent(SingleSelectLoader.EVENT_CHANGE, arguments); |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_createItems: function (items) { |
||||
var o = this.options; |
||||
return BI.map(items, function (i, item) { |
||||
return BI.extend({ |
||||
type: o.allowNoSelect ? "bi.single_select_item" : "bi.single_select_radio_item", |
||||
_createItems(items) { |
||||
const o = this.options; |
||||
|
||||
return map(items, (i, item) => extend( |
||||
{ |
||||
type: o.allowNoSelect ? SingleSelectItem.xtype : SingleSelectRadioItem.xtype, |
||||
logic: o.logic, |
||||
cls: "bi-list-item-active", |
||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
||||
selected: false, |
||||
iconWrapperWidth: 26, |
||||
textHgap: o.allowNoSelect ? 10 : 0, |
||||
title: item.title || item.text |
||||
}, item); |
||||
}); |
||||
}, |
||||
title: item.title || item.text, |
||||
}, |
||||
item |
||||
)); |
||||
} |
||||
|
||||
_scrollToTop: function () { |
||||
var self = this; |
||||
BI.delay(function () { |
||||
_scrollToTop() { |
||||
const self = this; |
||||
delay(() => { |
||||
self.button_group.element.scrollTop(0); |
||||
}, 30); |
||||
}, |
||||
} |
||||
|
||||
_assertValue: function (val) { |
||||
}, |
||||
_assertValue(val) {} |
||||
|
||||
setStartValue: function (v) { |
||||
setStartValue(v) { |
||||
this._startValue = v; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
this.storeValue = v; |
||||
this._assertValue(this.storeValue); |
||||
this.button_group.setValue(this.storeValue); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.button_group.getValue(); |
||||
}, |
||||
} |
||||
|
||||
getAllButtons: function () { |
||||
getAllButtons() { |
||||
return this.button_group.getAllButtons(); |
||||
}, |
||||
} |
||||
|
||||
empty: function () { |
||||
empty() { |
||||
this.button_group.empty(); |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
this.button_group.populate.apply(this.button_group, arguments); |
||||
}, |
||||
populate(items) { |
||||
this.button_group.populate(...arguments); |
||||
} |
||||
|
||||
resetHeight: function (h) { |
||||
resetHeight(h) { |
||||
this.button_group.resetHeight(h - this._constants.itemVgap * 2); |
||||
}, |
||||
} |
||||
|
||||
resetWidth: function (w) { |
||||
resetWidth(w) { |
||||
this.button_group.resetWidth(w); |
||||
} |
||||
}); |
||||
|
||||
BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader); |
||||
} |
||||
|
@ -1,84 +1,82 @@
|
||||
/** |
||||
* 带加载的单选下拉面板 |
||||
* @class BI.SingleSelectPopupView |
||||
* @extends Widget |
||||
*/ |
||||
BI.SingleSelectPopupView = BI.inherit(BI.Widget, { |
||||
import { shortcut, Widget, extend, emptyFn, createWidget } from "@/core"; |
||||
import { MultiPopupView } from "@/case"; |
||||
import { PopupView } from "@/base"; |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectPopupView.superclass._defaultConfig.apply(this, arguments), { |
||||
@shortcut() |
||||
export class SingleSelectPopupView extends Widget { |
||||
static xtype = "bi.single_select_popup_view"; |
||||
|
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-single-select-popup-view", |
||||
allowNoSelect: false, |
||||
maxWidth: "auto", |
||||
minWidth: 135, |
||||
maxHeight: 400, |
||||
valueFormatter: BI.emptyFn, |
||||
itemsCreator: BI.emptyFn, |
||||
itemWrapper: BI.emptyFn, |
||||
onLoaded: BI.emptyFn |
||||
valueFormatter: emptyFn, |
||||
itemsCreator: emptyFn, |
||||
itemWrapper: emptyFn, |
||||
onLoaded: emptyFn, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SingleSelectPopupView.superclass._init.apply(this, arguments); |
||||
var self = this, opts = this.options; |
||||
_init() { |
||||
super._init(...arguments); |
||||
const opts = this.options; |
||||
|
||||
this.loader = BI.createWidget({ |
||||
this.loader = createWidget({ |
||||
type: "bi.single_select_loader", |
||||
allowNoSelect: opts.allowNoSelect, |
||||
itemsCreator: opts.itemsCreator, |
||||
itemWrapper: opts.itemWrapper, |
||||
valueFormatter: opts.valueFormatter, |
||||
onLoaded: opts.onLoaded, |
||||
value: opts.value |
||||
value: opts.value, |
||||
}); |
||||
|
||||
this.popupView = BI.createWidget({ |
||||
type: "bi.popup_view", |
||||
this.popupView = createWidget({ |
||||
type: PopupView.xtype, |
||||
stopPropagation: false, |
||||
maxWidth: opts.maxWidth, |
||||
minWidth: opts.minWidth, |
||||
maxHeight: opts.maxHeight, |
||||
element: this, |
||||
el: this.loader, |
||||
value: opts.value |
||||
value: opts.value, |
||||
}); |
||||
|
||||
this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); |
||||
this.popupView.on(MultiPopupView.EVENT_CHANGE, () => { |
||||
this.fireEvent(SingleSelectPopupView.EVENT_CHANGE); |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
setStartValue: function (v) { |
||||
setStartValue(v) { |
||||
this.loader.setStartValue(v); |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
this.popupView.setValue(v); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.popupView.getValue(); |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
this.popupView.populate.apply(this.popupView, arguments); |
||||
}, |
||||
populate(items) { |
||||
this.popupView.populate(...arguments); |
||||
} |
||||
|
||||
resetHeight: function (h) { |
||||
resetHeight(h) { |
||||
this.popupView.resetHeight(h); |
||||
}, |
||||
} |
||||
|
||||
resetWidth: function (w) { |
||||
resetWidth(w) { |
||||
this.popupView.resetWidth(w); |
||||
}, |
||||
} |
||||
|
||||
setDirection: function (direction, position) { |
||||
setDirection(direction, position) { |
||||
this.popupView.setDirection(direction, position); |
||||
}, |
||||
}); |
||||
|
||||
BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
|
||||
BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,2 @@
|
||||
export { SingleSelectEditor } from "./editor.singleselect"; |
||||
export { SingleSelectSearcher } from "./searcher.singleselect"; |
@ -1,162 +1,161 @@
|
||||
/** |
||||
* searcher |
||||
* Created by guy on 15/11/3. |
||||
* @class BI.SingleSelectSearcher |
||||
* @extends Widget |
||||
*/ |
||||
BI.SingleSelectSearcher = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { |
||||
import { shortcut, Widget, extend, emptyFn, createWidget, isNotNull, isUndefined, Selection } from "@/core"; |
||||
import { SingleSelectEditor } from "./editor.singleselect"; |
||||
import { Searcher } from "@/base"; |
||||
|
||||
@shortcut() |
||||
export class SingleSelectSearcher extends Widget { |
||||
static xtype = "bi.single_select_searcher"; |
||||
|
||||
static EVENT_FOCUS = "EVENT_FOCUS"; |
||||
static EVENT_BLUR = "EVENT_BLUR"; |
||||
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
static EVENT_START = "EVENT_START"; |
||||
static EVENT_STOP = "EVENT_STOP"; |
||||
static EVENT_PAUSE = "EVENT_PAUSE"; |
||||
static EVENT_SEARCHING = "EVENT_SEARCHING"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-single-select-searcher", |
||||
itemsCreator: BI.emptyFn, |
||||
itemsCreator: emptyFn, |
||||
el: {}, |
||||
popup: {}, |
||||
valueFormatter: BI.emptyFn, |
||||
valueFormatter: emptyFn, |
||||
adapter: null, |
||||
masker: {}, |
||||
allowNoSelect: false |
||||
allowNoSelect: false, |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.SingleSelectSearcher.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.editor = BI.createWidget(o.el, { |
||||
_init() { |
||||
super._init(...arguments); |
||||
const self = this, |
||||
o = this.options; |
||||
this.editor = createWidget(o.el, { |
||||
type: "bi.single_select_editor", |
||||
height: o.height, |
||||
watermark: o.watermark, |
||||
text: o.text, |
||||
listeners: [{ |
||||
eventName: BI.SingleSelectEditor.EVENT_FOCUS, |
||||
action: function () { |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_FOCUS); |
||||
} |
||||
}, { |
||||
eventName: BI.SingleSelectEditor.EVENT_BLUR, |
||||
action: function () { |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_BLUR); |
||||
} |
||||
}] |
||||
eventName: SingleSelectEditor.EVENT_FOCUS, |
||||
action: () => { |
||||
this.fireEvent(SingleSelectSearcher.EVENT_FOCUS); |
||||
}, |
||||
}, |
||||
{ |
||||
eventName: SingleSelectEditor.EVENT_BLUR, |
||||
action: () => { |
||||
this.fireEvent(SingleSelectSearcher.EVENT_BLUR); |
||||
}, |
||||
} |
||||
], |
||||
}); |
||||
|
||||
this.searcher = BI.createWidget({ |
||||
type: "bi.searcher", |
||||
this.searcher = createWidget({ |
||||
type: Searcher.xtype, |
||||
element: this, |
||||
height: o.height, |
||||
isAutoSearch: false, |
||||
isAutoSync: false, |
||||
onSearch: function (op, callback) { |
||||
onSearch(op, callback) { |
||||
callback(); |
||||
}, |
||||
el: this.editor, |
||||
|
||||
popup: BI.extend({ |
||||
popup: extend({ |
||||
type: "bi.single_select_search_pane", |
||||
allowNoSelect: o.allowNoSelect, |
||||
valueFormatter: o.valueFormatter, |
||||
keywordGetter: function () { |
||||
return self.editor.getValue(); |
||||
}, |
||||
itemsCreator: function (op, callback) { |
||||
var keyword = self.editor.getValue(); |
||||
keywordGetter: () => this.editor.getValue(), |
||||
itemsCreator(op, callback) { |
||||
const keyword = self.editor.getValue(); |
||||
op.keywords = [keyword]; |
||||
this.setKeyword(keyword); |
||||
o.itemsCreator(op, callback); |
||||
}, |
||||
value: o.value |
||||
}, o.popup), |
||||
value: o.value, |
||||
}, |
||||
o.popup |
||||
), |
||||
|
||||
adapter: o.adapter, |
||||
masker: o.masker |
||||
masker: o.masker, |
||||
}); |
||||
this.searcher.on(BI.Searcher.EVENT_START, function () { |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_START); |
||||
this.searcher.on(Searcher.EVENT_START, () => { |
||||
this.fireEvent(SingleSelectSearcher.EVENT_START); |
||||
}); |
||||
this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { |
||||
if (this.hasMatched()) { |
||||
|
||||
} |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_PAUSE); |
||||
this.searcher.on(Searcher.EVENT_PAUSE, () => { |
||||
this.fireEvent(SingleSelectSearcher.EVENT_PAUSE); |
||||
}); |
||||
this.searcher.on(BI.Searcher.EVENT_STOP, function () { |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_STOP); |
||||
this.searcher.on(Searcher.EVENT_STOP, () => { |
||||
this.fireEvent(SingleSelectSearcher.EVENT_STOP); |
||||
}); |
||||
this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); |
||||
this.searcher.on(Searcher.EVENT_CHANGE, (...args) => { |
||||
this.fireEvent(SingleSelectSearcher.EVENT_CHANGE, ...args); |
||||
}); |
||||
this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { |
||||
var keywords = this.getKeywords(); |
||||
self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); |
||||
this.searcher.on(Searcher.EVENT_SEARCHING, () => { |
||||
const keywords = this.searcher.getKeywords(); |
||||
this.fireEvent(SingleSelectSearcher.EVENT_SEARCHING, keywords); |
||||
}); |
||||
|
||||
if(BI.isNotNull(o.value)){ |
||||
if (isNotNull(o.value)) { |
||||
this.setState(o.value); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
adjustView: function () { |
||||
adjustView() { |
||||
this.searcher.adjustView(); |
||||
}, |
||||
} |
||||
|
||||
isSearching: function () { |
||||
isSearching() { |
||||
return this.searcher.isSearching(); |
||||
}, |
||||
} |
||||
|
||||
stopSearch: function () { |
||||
stopSearch() { |
||||
this.searcher.stopSearch(); |
||||
}, |
||||
} |
||||
|
||||
getKeyword: function () { |
||||
getKeyword() { |
||||
return this.editor.getKeyword(); |
||||
}, |
||||
} |
||||
|
||||
hasMatched: function () { |
||||
hasMatched() { |
||||
return this.searcher.hasMatched(); |
||||
}, |
||||
} |
||||
|
||||
hasChecked: function () { |
||||
hasChecked() { |
||||
return this.searcher.getView() && this.searcher.getView().hasChecked(); |
||||
}, |
||||
} |
||||
|
||||
setAdapter: function (adapter) { |
||||
setAdapter(adapter) { |
||||
this.searcher.setAdapter(adapter); |
||||
}, |
||||
} |
||||
|
||||
setState: function (v) { |
||||
var o = this.options; |
||||
if (BI.isUndefined(v)) { |
||||
this.editor.setState(BI.Selection.None); |
||||
setState(v) { |
||||
const o = this.options; |
||||
if (isUndefined(v)) { |
||||
this.editor.setState(Selection.None); |
||||
} else { |
||||
v = v ?? ""; |
||||
this.editor.setState(o.valueFormatter(v + "") || (v + "")); |
||||
this.editor.setState(o.valueFormatter(`${v}`) || `${v}`); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setValue: function (ob) { |
||||
setValue(ob) { |
||||
this.setState(ob); |
||||
this.searcher.setValue(ob); |
||||
}, |
||||
} |
||||
|
||||
getKey: function () { |
||||
getKey() { |
||||
return this.editor.getValue(); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.searcher.getValue(); |
||||
}, |
||||
} |
||||
|
||||
populate: function (items) { |
||||
this.searcher.populate.apply(this.searcher, arguments); |
||||
populate(items) { |
||||
this.searcher.populate(...arguments); |
||||
} |
||||
}); |
||||
|
||||
BI.SingleSelectSearcher.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
BI.SingleSelectSearcher.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; |
||||
BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; |
||||
BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; |
||||
BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; |
||||
BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; |
||||
BI.shortcut("bi.single_select_searcher", BI.SingleSelectSearcher); |
||||
} |
||||
|
@ -1,194 +1,205 @@
|
||||
/** |
||||
* 年份展示面板 |
||||
* |
||||
* Created by GUY on 2015/9/2. |
||||
* @class BI.StaticYearCard |
||||
* @extends BI.Trigger |
||||
*/ |
||||
BI.StaticYearCard = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.StaticYearCard.superclass._defaultConfig.apply(this, arguments), { |
||||
import { shortcut, Widget, extend, createWidget, getDate, bind, Controller, isKey, HTapeLayout, CenterAdaptLayout, Layout, each, isNotEmptyString, checkDateVoid, parseInt } from "@/core"; |
||||
import { YearCalendar } from "@/case"; |
||||
import { IconButton, Navigation } from "@/base"; |
||||
|
||||
@shortcut() |
||||
export class StaticYearCard extends Widget { |
||||
static xtype = "bi.static_year_card"; |
||||
|
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
baseCls: "bi-year-card", |
||||
behaviors: {}, |
||||
min: "1900-01-01", // 最小日期
|
||||
max: "2099-12-31" // 最大日期
|
||||
max: "2099-12-31", // 最大日期
|
||||
}); |
||||
}, |
||||
|
||||
_createYearCalendar: function (v) { |
||||
var o = this.options, y = this._year; |
||||
} |
||||
|
||||
var calendar = BI.createWidget({ |
||||
type: "bi.year_calendar", |
||||
_createYearCalendar(v) { |
||||
const o = this.options, |
||||
y = this._year; |
||||
const calendar = createWidget({ |
||||
type: YearCalendar.xtype, |
||||
behaviors: o.behaviors, |
||||
min: o.min, |
||||
max: o.max, |
||||
logic: { |
||||
dynamic: true |
||||
dynamic: true, |
||||
}, |
||||
year: y + v * 12 |
||||
year: y + v * 12, |
||||
}); |
||||
calendar.setValue(this._year); |
||||
|
||||
return calendar; |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.StaticYearCard.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
} |
||||
|
||||
this.selectedYear = this._year = BI.getDate().getFullYear(); |
||||
_init() { |
||||
super._init(...arguments); |
||||
const o = this.options; |
||||
|
||||
this.backBtn = BI.createWidget({ |
||||
type: "bi.icon_button", |
||||
this.selectedYear = this._year = getDate().getFullYear(); |
||||
this.backBtn = createWidget({ |
||||
type: IconButton.xtype, |
||||
cls: "pre-page-h-font", |
||||
width: 25, |
||||
height: 25, |
||||
value: -1, |
||||
listeners: [{ |
||||
eventName: BI.IconButton.EVENT_CHANGE, |
||||
action: function () { |
||||
self.navigation.setSelect(self.navigation.getSelect() - 1); |
||||
self._checkLeftValid(); |
||||
self._checkRightValid(); |
||||
listeners: [ |
||||
{ |
||||
eventName: IconButton.EVENT_CHANGE, |
||||
action :() => { |
||||
this.navigation.setSelect( |
||||
this.navigation.getSelect() - 1 |
||||
); |
||||
this._checkLeftValid(); |
||||
this._checkRightValid(); |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}); |
||||
|
||||
this.preBtn = BI.createWidget({ |
||||
type: "bi.icon_button", |
||||
this.preBtn = createWidget({ |
||||
type: IconButton.xtype, |
||||
cls: "next-page-h-font", |
||||
width: 25, |
||||
height: 25, |
||||
value: 1, |
||||
listeners: [{ |
||||
eventName: BI.IconButton.EVENT_CHANGE, |
||||
action: function () { |
||||
self.navigation.setSelect(self.navigation.getSelect() + 1); |
||||
self._checkLeftValid(); |
||||
self._checkRightValid(); |
||||
listeners: [ |
||||
{ |
||||
eventName: IconButton.EVENT_CHANGE, |
||||
action :() => { |
||||
this.navigation.setSelect( |
||||
this.navigation.getSelect() + 1 |
||||
); |
||||
this._checkLeftValid(); |
||||
this._checkRightValid(); |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}); |
||||
|
||||
this.navigation = BI.createWidget({ |
||||
type: "bi.navigation", |
||||
this.navigation = createWidget({ |
||||
type: Navigation.xtype, |
||||
direction: "top", |
||||
element: this, |
||||
single: true, |
||||
logic: { |
||||
dynamic: true |
||||
dynamic: true, |
||||
}, |
||||
tab: { |
||||
type: "bi.htape", |
||||
type: HTapeLayout.xtype, |
||||
cls: "bi-split-top bi-split-bottom", |
||||
height: 30, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.center_adapt", |
||||
items: [self.backBtn] |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: CenterAdaptLayout.xtype, |
||||
items: [this.backBtn], |
||||
}, |
||||
width: 25, |
||||
}, |
||||
width: 25 |
||||
}, { |
||||
type: "bi.layout" |
||||
}, { |
||||
el: { |
||||
type: "bi.center_adapt", |
||||
items: [self.preBtn] |
||||
{ |
||||
type: Layout.xtype, |
||||
}, |
||||
width: 25 |
||||
}] |
||||
{ |
||||
el: { |
||||
type: CenterAdaptLayout.xtype, |
||||
items: [this.preBtn], |
||||
}, |
||||
width: 25, |
||||
} |
||||
], |
||||
}, |
||||
cardCreator: BI.bind(this._createYearCalendar, this), |
||||
cardCreator: bind(this._createYearCalendar, this), |
||||
|
||||
afterCardShow: function () { |
||||
this.setValue(self.selectedYear); |
||||
afterCardShow: () => { |
||||
this.navigation.setValue(this.selectedYear); |
||||
// var calendar = this.getSelectedCard();
|
||||
// self.backBtn.setEnable(!calendar.isFrontYear());
|
||||
// self.preBtn.setEnable(!calendar.isFinalYear());
|
||||
} |
||||
// this.backBtn.setEnable(!calendar.isFrontYear());
|
||||
// this.preBtn.setEnable(!calendar.isFinalYear());
|
||||
}, |
||||
}); |
||||
|
||||
this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { |
||||
self.selectedYear = this.getValue(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
self.fireEvent(BI.StaticYearCard.EVENT_CHANGE, self.selectedYear); |
||||
this.navigation.on(Navigation.EVENT_CHANGE, () => { |
||||
this.selectedYear = this.navigation.getValue(); |
||||
this.fireEvent(Controller.EVENT_CHANGE, ...arguments); |
||||
this.fireEvent(StaticYearCard.EVENT_CHANGE, this.selectedYear); |
||||
}); |
||||
|
||||
if(BI.isKey(o.value)){ |
||||
if (isKey(o.value)) { |
||||
this.setValue(o.value); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
_checkLeftValid: function () { |
||||
var o = this.options; |
||||
var valid = true; |
||||
_checkLeftValid() { |
||||
const valid = true; |
||||
this.backBtn.setEnable(valid); |
||||
|
||||
return valid; |
||||
}, |
||||
} |
||||
|
||||
_checkRightValid: function () { |
||||
var o = this.options; |
||||
var valid = true; |
||||
_checkRightValid() { |
||||
const valid = true; |
||||
this.preBtn.setEnable(valid); |
||||
|
||||
return valid; |
||||
}, |
||||
} |
||||
|
||||
_checkMin: function () { |
||||
var o = this.options; |
||||
BI.each(this.navigation.getAllCard(), function (idx, calendar) { |
||||
_checkMin() { |
||||
const o = this.options; |
||||
each(this.navigation.getAllCard(), (idx, calendar) => { |
||||
calendar.setMinDate(o.min); |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_checkMax: function () { |
||||
var o = this.options; |
||||
BI.each(this.navigation.getAllCard(), function (idx, calendar) { |
||||
_checkMax() { |
||||
const o = this.options; |
||||
each(this.navigation.getAllCard(), (idx, calendar) => { |
||||
calendar.setMaxDate(o.max); |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
setMinDate: function (minDate) { |
||||
if (BI.isNotEmptyString(this.options.min)) { |
||||
setMinDate(minDate) { |
||||
if (isNotEmptyString(this.options.min)) { |
||||
this.options.min = minDate; |
||||
this._checkLeftValid(); |
||||
this._checkRightValid(); |
||||
this._checkMin(); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setMaxDate: function (maxDate) { |
||||
if (BI.isNotEmptyString(this.options.max)) { |
||||
setMaxDate(maxDate) { |
||||
if (isNotEmptyString(this.options.max)) { |
||||
this.options.max = maxDate; |
||||
this._checkLeftValid(); |
||||
this._checkRightValid(); |
||||
this._checkMax(); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return { |
||||
year: this.selectedYear |
||||
year: this.selectedYear, |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (obj) { |
||||
var o = this.options; |
||||
setValue(obj) { |
||||
const o = this.options; |
||||
obj = obj || {}; |
||||
var v = obj.year; |
||||
if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { |
||||
v = BI.getDate().getFullYear(); |
||||
let v = obj.year; |
||||
if (checkDateVoid(v, 1, 1, o.min, o.max)[0]) { |
||||
v = getDate().getFullYear(); |
||||
this.selectedYear = ""; |
||||
this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); |
||||
this.navigation.setSelect(YearCalendar.getPageByYear(v)); |
||||
this.navigation.setValue(""); |
||||
} else { |
||||
this.selectedYear = BI.parseInt(v); |
||||
this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); |
||||
this.selectedYear = parseInt(v); |
||||
this.navigation.setSelect(YearCalendar.getPageByYear(v)); |
||||
this.navigation.setValue(this.selectedYear); |
||||
} |
||||
this._checkLeftValid(); |
||||
this._checkRightValid(); |
||||
} |
||||
}); |
||||
BI.StaticYearCard.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.static_year_card", BI.StaticYearCard); |
||||
} |
||||
|
@ -0,0 +1,5 @@
|
||||
export { DynamicYearCard } from "./card.dynamic.year"; |
||||
export { StaticYearCard } from "./card.year"; |
||||
export { DynamicYearCombo } from "./combo.year"; |
||||
export { DynamicYearPopup } from "./popup.year"; |
||||
export { DynamicYearTrigger } from "./trigger.year"; |
@ -1,246 +1,318 @@
|
||||
/** |
||||
* 年份展示面板 |
||||
* |
||||
* Created by GUY on 2015/9/2. |
||||
* @class BI.DynamicYearPopup |
||||
* @extends BI.Trigger |
||||
*/ |
||||
BI.DynamicYearPopup = BI.inherit(BI.Widget, { |
||||
constants: { |
||||
tabHeight: 40, |
||||
}, |
||||
import { shortcut, Widget, toPix, i18nText, VerticalLayout, GridLayout, print, getDate, checkDateVoid, createItems } from "@/core"; |
||||
import { TextButton, Tab } from "@/base"; |
||||
import { DynamicDateCombo, DynamicDateHelper, DynamicYearCard, DynamicYearCombo, StaticYearCard } from "@/widget"; |
||||
import { LinearSegment } from "@/case"; |
||||
|
||||
props: { |
||||
@shortcut() |
||||
export class DynamicYearPopup extends Widget { |
||||
static xtype = "bi.dynamic_year_popup"; |
||||
props = { |
||||
baseCls: "bi-dynamic-year-popup", |
||||
behaviors: {}, |
||||
min: "1900-01-01", // 最小日期
|
||||
max: "2099-12-31", // 最大日期,
|
||||
min: "1900-01-01", |
||||
max: "2099-12-31", |
||||
width: 180, |
||||
supportDynamic: true, |
||||
}, |
||||
}; |
||||
constants = { |
||||
tabHeight: 40, |
||||
}; |
||||
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.DynamicYearCombo.Static}; |
||||
render() { |
||||
this.storeValue = { type: DynamicYearCombo.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", |
||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
||||
shadow: true, |
||||
text: BI.i18nText("BI-Basic_Clear"), |
||||
listeners: [{ |
||||
eventName: BI.TextButton.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE); |
||||
} |
||||
}] |
||||
}, { |
||||
type: "bi.text_button", |
||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
||||
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
||||
shadow: true, |
||||
text: BI.i18nText("BI-Basic_Current_Year"), |
||||
disabled: this._checkTodayValid(), |
||||
ref: function () { |
||||
self.yearButton = this; |
||||
}, |
||||
listeners: [{ |
||||
eventName: BI.TextButton.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); |
||||
} |
||||
}] |
||||
}, { |
||||
type: "bi.text_button", |
||||
cls: "bi-split-top bi-high-light", |
||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
||||
shadow: true, |
||||
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.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); |
||||
} else { |
||||
self.fireEvent(BI.DynamicYearPopup.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", |
||||
textHeight: toPix( |
||||
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
1 |
||||
), |
||||
shadow: true, |
||||
text: i18nText("BI-Basic_Clear"), |
||||
listeners: [ |
||||
{ |
||||
eventName: TextButton.EVENT_CHANGE, |
||||
action :() => { |
||||
this.fireEvent( |
||||
DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
}, |
||||
{ |
||||
type: TextButton.xtype, |
||||
textHeight: toPix( |
||||
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
1 |
||||
), |
||||
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
||||
shadow: true, |
||||
text: i18nText("BI-Basic_Current_Year"), |
||||
disabled: this._checkTodayValid(), |
||||
ref: _ref => { |
||||
this.yearButton = _ref; |
||||
}, |
||||
listeners: [ |
||||
{ |
||||
eventName: TextButton.EVENT_CHANGE, |
||||
action :() => { |
||||
this.fireEvent( |
||||
DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
}, |
||||
{ |
||||
type: TextButton.xtype, |
||||
cls: "bi-split-top bi-high-light", |
||||
textHeight: toPix( |
||||
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
1 |
||||
), |
||||
shadow: true, |
||||
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( |
||||
BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE |
||||
); |
||||
} else { |
||||
this.fireEvent( |
||||
DynamicYearPopup.BUTTON_OK_EVENT_CHANGE |
||||
); |
||||
} |
||||
}, |
||||
} |
||||
], |
||||
} |
||||
] |
||||
], |
||||
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
}, |
||||
} |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
_setInnerValue: function () { |
||||
if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { |
||||
this.yearButton.setValue(BI.i18nText("BI-Basic_Current_Year")); |
||||
_setInnerValue() { |
||||
if (this.dateTab.getSelect() === DynamicDateCombo.Static) { |
||||
this.yearButton.setValue(i18nText("BI-Basic_Current_Year")); |
||||
this.yearButton.setEnable(!this._checkYearValid()); |
||||
} else { |
||||
var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getInputValue()); |
||||
date = BI.print(date, "%Y"); |
||||
let date = DynamicDateHelper.getCalculation( |
||||
this.dynamicPane.getInputValue() |
||||
); |
||||
date = print(date, "%Y"); |
||||
this.yearButton.setValue(date); |
||||
this.yearButton.setEnable(false); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
_checkYearValid: function () { |
||||
var o = this.options; |
||||
var today = BI.getDate(); |
||||
return !!BI.checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0]; |
||||
}, |
||||
_checkYearValid() { |
||||
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, |
||||
invisible: !o.supportDynamic, |
||||
height: this.constants.tabHeight, |
||||
items: BI.createItems([{ |
||||
text: BI.i18nText("BI-Basic_Year_Fen"), |
||||
value: BI.DynamicYearCombo.Static |
||||
}, { |
||||
text: BI.i18nText("BI-Basic_Dynamic_Title"), |
||||
value: BI.DynamicYearCombo.Dynamic |
||||
}], { |
||||
textAlign: "center" |
||||
}) |
||||
items: createItems( |
||||
[ |
||||
{ |
||||
text: i18nText("BI-Basic_Year_Fen"), |
||||
value: DynamicYearCombo.Static, |
||||
}, |
||||
{ |
||||
text: i18nText("BI-Basic_Dynamic_Title"), |
||||
value: DynamicYearCombo.Dynamic, |
||||
} |
||||
], |
||||
{ |
||||
textAlign: "center", |
||||
} |
||||
), |
||||
}, |
||||
cardCreator: function (v) { |
||||
cardCreator: v => { |
||||
switch (v) { |
||||
case BI.DynamicYearCombo.Dynamic: |
||||
return { |
||||
type: "bi.dynamic_year_card", |
||||
cls: "dynamic-year-pane", |
||||
min: self.options.min, |
||||
max: self.options.max, |
||||
listeners: [{ |
||||
case DynamicYearCombo.Dynamic: |
||||
return { |
||||
type: DynamicYearCard.xtype, |
||||
cls: "dynamic-year-pane", |
||||
min: o.min, |
||||
max: o.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.DynamicYearCombo.Static: |
||||
default: |
||||
return { |
||||
type: "bi.static_year_card", |
||||
behaviors: o.behaviors, |
||||
min: self.options.min, |
||||
max: self.options.max, |
||||
listeners: [{ |
||||
eventName: BI.StaticYearCard.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); |
||||
} |
||||
}], |
||||
ref: function () { |
||||
self.year = this; |
||||
], |
||||
ref: _ref => { |
||||
this.dynamicPane = _ref; |
||||
}, |
||||
}; |
||||
case DynamicYearCombo.Static: |
||||
default: |
||||
return { |
||||
type: StaticYearCard.xtype, |
||||
behaviors: o.behaviors, |
||||
min: o.min, |
||||
max: o.max, |
||||
listeners: [ |
||||
{ |
||||
eventName: StaticYearCard.EVENT_CHANGE, |
||||
action: () => { |
||||
this.fireEvent( |
||||
DynamicYearPopup.EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
}; |
||||
], |
||||
ref: _ref => { |
||||
this.year = _ref; |
||||
}, |
||||
}; |
||||
} |
||||
}, |
||||
listeners: [{ |
||||
eventName: BI.Tab.EVENT_CHANGE, |
||||
action: function () { |
||||
var v = self.dateTab.getSelect(); |
||||
switch (v) { |
||||
case BI.DynamicYearCombo.Static: |
||||
var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); |
||||
self.year.setValue({year: date.getFullYear()}); |
||||
self._setInnerValue(); |
||||
listeners: [ |
||||
{ |
||||
eventName: Tab.EVENT_CHANGE, |
||||
action :() => { |
||||
const v = this.dateTab.getSelect(); |
||||
switch (v) { |
||||
case DynamicYearCombo.Static: { |
||||
const date = DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); |
||||
this.year.setValue({ year: date.getFullYear() }); |
||||
this._setInnerValue(); |
||||
break; |
||||
case BI.DynamicYearCombo.Dynamic: |
||||
} |
||||
case DynamicYearCombo.Dynamic: |
||||
default: |
||||
if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { |
||||
self.dynamicPane.setValue(self.storeValue.value); |
||||
}else{ |
||||
self.dynamicPane.setValue({ |
||||
year: 0 |
||||
if ( |
||||
this.storeValue && |
||||
this.storeValue.type === |
||||
DynamicYearCombo.Dynamic |
||||
) { |
||||
this.dynamicPane.setValue( |
||||
this.storeValue.value |
||||
); |
||||
} else { |
||||
this.dynamicPane.setValue({ |
||||
year: 0, |
||||
}); |
||||
} |
||||
self._setInnerValue(); |
||||
this._setInnerValue(); |
||||
break; |
||||
} |
||||
} |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
_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]; |
||||
} |
||||
|
||||
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.yearButton.setValue(BI.i18nText("BI-Basic_Current_Year")); |
||||
this.yearButton.setEnable(!this._checkTodayValid()); |
||||
break; |
||||
case DynamicDateCombo.Dynamic: |
||||
this.dynamicPane.setValue(value); |
||||
this._setInnerValue(); |
||||
break; |
||||
case DynamicDateCombo.Static: |
||||
default: |
||||
this.year.setValue(value); |
||||
this.yearButton.setValue(i18nText("BI-Basic_Current_Year")); |
||||
this.yearButton.setEnable(!this._checkTodayValid()); |
||||
break; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return { |
||||
type: this.dateTab.getSelect(), |
||||
value: this.dateTab.getValue() |
||||
value: this.dateTab.getValue(), |
||||
}; |
||||
} |
||||
|
||||
}); |
||||
BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; |
||||
BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; |
||||
BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; |
||||
BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup); |
||||
} |
||||
|
@ -1,204 +1,227 @@
|
||||
BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { |
||||
_const: { |
||||
hgap: 4, |
||||
vgap: 2, |
||||
iconWidth: 24 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { |
||||
import { shortcut, extend, i18nText, bind, createWidget, isPositiveInteger, checkDateVoid, parseDateTime, isNotNull, isNotEmptyString, parseInt, print, getDate, HorizontalFillLayout } from "@/core"; |
||||
import { Trigger, TextButton } from "@/base"; |
||||
import { SignEditor, TriggerIconButton } from "@/case"; |
||||
import { DynamicDateCombo, DynamicDateHelper } from "@/widget"; |
||||
|
||||
@shortcut() |
||||
export class DynamicYearTrigger extends Trigger { |
||||
static xtype = "bi.dynamic_year_trigger"; |
||||
|
||||
_const = { hgap: 4, vgap: 2, iconWidth: 24 }; |
||||
|
||||
static EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; |
||||
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_VALID = "EVENT_VALID"; |
||||
|
||||
_defaultConfig() { |
||||
return extend(super._defaultConfig(...arguments), { |
||||
extraCls: "bi-year-trigger", |
||||
min: "1900-01-01", // 最小日期
|
||||
max: "2099-12-31", // 最大日期
|
||||
height: 24, |
||||
watermark: BI.i18nText("BI-Basic_Unrestricted") |
||||
watermark: i18nText("BI-Basic_Unrestricted"), |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
beforeInit: function (callback) { |
||||
var o = this.options; |
||||
o.title = BI.bind(this._titleCreator, this); |
||||
beforeInit(callback) { |
||||
const o = this.options; |
||||
o.title = bind(this._titleCreator, this); |
||||
callback(); |
||||
}, |
||||
} |
||||
|
||||
_init: function () { |
||||
BI.DynamicYearTrigger.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options, c = this._const; |
||||
this.editor = BI.createWidget({ |
||||
type: "bi.sign_editor", |
||||
_init() { |
||||
super._init(...arguments); |
||||
const o = this.options, |
||||
c = this._const; |
||||
this.editor = createWidget({ |
||||
type: SignEditor.xtype, |
||||
simple: o.simple, |
||||
height: o.height, |
||||
validationChecker: function (v) { |
||||
return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); |
||||
}, |
||||
quitChecker: function (v) { |
||||
return false; |
||||
}, |
||||
validationChecker: v => ( |
||||
v === "" || |
||||
(isPositiveInteger(v) && |
||||
!checkDateVoid(v, 1, 1, o.min, o.max)[0]) |
||||
), |
||||
quitChecker: () => false, |
||||
hgap: c.hgap, |
||||
vgap: c.vgap, |
||||
watermark: o.watermark, |
||||
allowBlank: true, |
||||
errorText: function (v) { |
||||
if (BI.isPositiveInteger(v)) { |
||||
var start = BI.parseDateTime(o.min, "%Y-%X-%d"); |
||||
var end = BI.parseDateTime(o.max, "%Y-%X-%d"); |
||||
errorText:v => { |
||||
if (isPositiveInteger(v)) { |
||||
const start = parseDateTime(o.min, "%Y-%X-%d"); |
||||
const end = parseDateTime(o.max, "%Y-%X-%d"); |
||||
|
||||
return BI.i18nText("BI-Basic_Year_Range_Error", |
||||
return i18nText( |
||||
"BI-Basic_Year_Range_Error", |
||||
start.getFullYear(), |
||||
end.getFullYear()); |
||||
end.getFullYear() |
||||
); |
||||
} |
||||
|
||||
return BI.i18nText("BI-Year_Trigger_Invalid_Text"); |
||||
return i18nText("BI-Year_Trigger_Invalid_Text"); |
||||
}, |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { |
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_KEY_DOWN, arguments); |
||||
this.editor.on(SignEditor.EVENT_KEY_DOWN, () => { |
||||
this.fireEvent(DynamicYearTrigger.EVENT_KEY_DOWN, ...arguments); |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { |
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); |
||||
this.editor.on(SignEditor.EVENT_FOCUS, () => { |
||||
this.fireEvent(DynamicYearTrigger.EVENT_FOCUS); |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_STOP, function () { |
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); |
||||
this.editor.on(SignEditor.EVENT_STOP, () => { |
||||
this.fireEvent(DynamicYearTrigger.EVENT_STOP); |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { |
||||
var value = self.editor.getValue(); |
||||
if (BI.isNotNull(value)) { |
||||
self.editor.setValue(value); |
||||
this.editor.on(SignEditor.EVENT_CONFIRM, () => { |
||||
const value = this.editor.getValue(); |
||||
if (isNotNull(value)) { |
||||
this.editor.setValue(value); |
||||
} |
||||
if (BI.isNotEmptyString(value)) { |
||||
self.storeValue = { |
||||
type: BI.DynamicDateCombo.Static, |
||||
if (isNotEmptyString(value)) { |
||||
this.storeValue = { |
||||
type: DynamicDateCombo.Static, |
||||
value: { |
||||
year: value |
||||
} |
||||
year: value, |
||||
}, |
||||
}; |
||||
} |
||||
|
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_CONFIRM); |
||||
this.fireEvent(DynamicYearTrigger.EVENT_CONFIRM); |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_SPACE, function () { |
||||
if (self.editor.isValid()) { |
||||
self.editor.blur(); |
||||
this.editor.on(SignEditor.EVENT_SPACE, () => { |
||||
if (this.editor.isValid()) { |
||||
this.editor.blur(); |
||||
} |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_START, function () { |
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_START); |
||||
this.editor.on(SignEditor.EVENT_START, () => { |
||||
this.fireEvent(DynamicYearTrigger.EVENT_START); |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_ERROR, function () { |
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); |
||||
this.editor.on(SignEditor.EVENT_ERROR, () => { |
||||
this.fireEvent(DynamicYearTrigger.EVENT_ERROR); |
||||
}); |
||||
this.editor.on(BI.SignEditor.EVENT_VALID, function () { |
||||
self.fireEvent(BI.DynamicYearTrigger.EVENT_VALID); |
||||
this.editor.on(SignEditor.EVENT_VALID, () => { |
||||
this.fireEvent(DynamicYearTrigger.EVENT_VALID); |
||||
}); |
||||
BI.createWidget({ |
||||
createWidget({ |
||||
element: this, |
||||
type: "bi.horizontal_fill", |
||||
type: HorizontalFillLayout.xtype, |
||||
columnSize: ["fill", "", ""], |
||||
items: [{ |
||||
el: this.editor |
||||
}, { |
||||
el: { |
||||
type: "bi.text_button", |
||||
baseCls: "bi-trigger-year-text", |
||||
text: BI.i18nText("BI-Multi_Date_Year"), |
||||
items: [ |
||||
{ |
||||
el: this.editor, |
||||
}, |
||||
{ |
||||
el: { |
||||
type: TextButton.xtype, |
||||
baseCls: "bi-trigger-year-text", |
||||
text: i18nText("BI-Multi_Date_Year"), |
||||
}, |
||||
}, |
||||
}, { |
||||
el: { |
||||
type: "bi.trigger_icon_button", |
||||
width: this._const.iconWidth |
||||
{ |
||||
el: { |
||||
type: TriggerIconButton.xtype, |
||||
width: this._const.iconWidth, |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}); |
||||
this.setValue(o.value); |
||||
}, |
||||
} |
||||
|
||||
_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")); |
||||
} |
||||
|
||||
return value; |
||||
}, |
||||
} |
||||
|
||||
_setInnerValue: function (date, text) { |
||||
var dateStr = BI.print(date, "%Y"); |
||||
_setInnerValue(date) { |
||||
const dateStr = print(date, "%Y"); |
||||
this.editor.setState(dateStr); |
||||
this.editor.setValue(dateStr); |
||||
}, |
||||
} |
||||
|
||||
_titleCreator: function () { |
||||
var storeValue = this.storeValue || {}; |
||||
var type = storeValue.type || BI.DynamicDateCombo.Static; |
||||
var value = storeValue.value; |
||||
if(!this.editor.isValid()) { |
||||
_titleCreator() { |
||||
const storeValue = this.storeValue || {}; |
||||
const type = storeValue.type || DynamicDateCombo.Static; |
||||
let value = storeValue.value; |
||||
if (!this.editor.isValid()) { |
||||
return ""; |
||||
} |
||||
|
||||
switch (type) { |
||||
case BI.DynamicDateCombo.Dynamic: |
||||
var text = this._getText(value); |
||||
var date = BI.getDate(); |
||||
date = BI.DynamicDateHelper.getCalculation(value); |
||||
var dateStr = BI.print(date, "%Y"); |
||||
return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); |
||||
case BI.DynamicDateCombo.Static: |
||||
default: |
||||
value = value || {}; |
||||
return value.year; |
||||
case DynamicDateCombo.Dynamic: { |
||||
const text = this._getText(value); |
||||
let date = getDate(); |
||||
date = DynamicDateHelper.getCalculation(value); |
||||
const dateStr = BI.print(date, "%Y"); |
||||
|
||||
return BI.isEmptyString(text) ? dateStr : (`${text}:${dateStr}`); |
||||
} |
||||
|
||||
case DynamicDateCombo.Static: |
||||
default: |
||||
value = value || {}; |
||||
|
||||
return value.year; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
var type, value; |
||||
var date = BI.getDate(); |
||||
setValue(v) { |
||||
let type, value; |
||||
let date = getDate(); |
||||
this.storeValue = v; |
||||
if (BI.isNotNull(v)) { |
||||
type = v.type || BI.DynamicDateCombo.Static; |
||||
if (isNotNull(v)) { |
||||
type = v.type || DynamicDateCombo.Static; |
||||
value = v.value || v; |
||||
} |
||||
switch (type) { |
||||
case BI.DynamicDateCombo.Dynamic: |
||||
var text = this._getText(value); |
||||
date = BI.DynamicDateHelper.getCalculation(value); |
||||
this._setInnerValue(date, text); |
||||
break; |
||||
case BI.DynamicDateCombo.Static: |
||||
default: |
||||
value = value || {}; |
||||
this.editor.setState(value.year); |
||||
this.editor.setValue(value.year); |
||||
break; |
||||
case DynamicDateCombo.Dynamic: { |
||||
const text = this._getText(value); |
||||
date = DynamicDateHelper.getCalculation(value); |
||||
this._setInnerValue(date, text); |
||||
break; |
||||
} |
||||
case DynamicDateCombo.Static: |
||||
default: |
||||
value = value || {}; |
||||
this.editor.setState(value.year); |
||||
this.editor.setValue(value.year); |
||||
break; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
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; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.storeValue; |
||||
}, |
||||
} |
||||
|
||||
getKey: function () { |
||||
getKey() { |
||||
return this.editor.getValue() | 0; |
||||
}, |
||||
} |
||||
|
||||
setWaterMark: function (v) { |
||||
setWaterMark(v) { |
||||
this.editor.setWaterMark(v); |
||||
} |
||||
}); |
||||
BI.DynamicYearTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; |
||||
BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; |
||||
BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; |
||||
BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; |
||||
BI.DynamicYearTrigger.EVENT_VALID = "EVENT_VALID"; |
||||
BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger); |
||||
} |
||||
|
@ -1,194 +1,232 @@
|
||||
/** |
||||
* @author windy |
||||
* @version 2.0 |
||||
* Created by windy on 2021/1/25 |
||||
*/ |
||||
BI.YearInterval = BI.inherit(BI.Single, { |
||||
constants: { |
||||
import { shortcut, HorizontalFillLayout, createWidget, i18nText, print, parseDateTime, checkDateVoid, isNotNull, checkDateLegal } from "@/core"; |
||||
import { Single, Label, Bubbles } from "@/base"; |
||||
import { DynamicYearCombo } from "../year"; |
||||
|
||||
@shortcut() |
||||
export class YearInterval extends Single { |
||||
static xtype = "bi.year_interval"; |
||||
|
||||
constants = { |
||||
height: 24, |
||||
width: 25, |
||||
lgap: 15, |
||||
offset: -15, |
||||
timeErrorCls: "time-error" |
||||
}, |
||||
|
||||
props: { |
||||
timeErrorCls: "time-error", |
||||
}; |
||||
props = { |
||||
extraCls: "bi-year-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_combo", |
||||
_createCombo(v, watermark) { |
||||
const o = this.options; |
||||
const combo = createWidget({ |
||||
type: DynamicYearCombo.xtype, |
||||
supportDynamic: o.supportDynamic, |
||||
minDate: o.minDate, |
||||
maxDate: o.maxDate, |
||||
height: o.height, |
||||
behaviors: o.behaviors, |
||||
value: v, |
||||
watermark: watermark, |
||||
listeners: [{ |
||||
eventName: BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW, |
||||
action: function () { |
||||
self.fireEvent(BI.YearInterval.EVENT_BEFORE_POPUPVIEW); |
||||
watermark, |
||||
listeners: [ |
||||
{ |
||||
eventName: DynamicYearCombo.EVENT_BEFORE_POPUPVIEW, |
||||
action: () => { |
||||
this.fireEvent(YearInterval.EVENT_BEFORE_POPUPVIEW); |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}); |
||||
combo.on(BI.DynamicYearCombo.EVENT_ERROR, function () { |
||||
self._clearTitle(); |
||||
BI.Bubbles.hide("error"); |
||||
self.element.removeClass(self.constants.timeErrorCls); |
||||
self.fireEvent(BI.YearInterval.EVENT_ERROR); |
||||
combo.on(DynamicYearCombo.EVENT_ERROR, () => { |
||||
this._clearTitle(); |
||||
Bubbles.hide("error"); |
||||
this.element.removeClass(this.constants.timeErrorCls); |
||||
this.fireEvent(YearInterval.EVENT_ERROR); |
||||
}); |
||||
|
||||
combo.on(BI.DynamicYearCombo.EVENT_VALID, function () { |
||||
self._checkValid(); |
||||
combo.on(DynamicYearCombo.EVENT_VALID, () => { |
||||
this._checkValid(); |
||||
}); |
||||
|
||||
combo.on(BI.DynamicYearCombo.EVENT_FOCUS, function () { |
||||
self._checkValid(); |
||||
combo.on(DynamicYearCombo.EVENT_FOCUS, () => { |
||||
this._checkValid(); |
||||
}); |
||||
|
||||
combo.on(BI.DynamicYearCombo.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.YearInterval.EVENT_ERROR); |
||||
}else{ |
||||
self._clearTitle(); |
||||
self.element.removeClass(self.constants.timeErrorCls); |
||||
self.fireEvent(BI.YearInterval.EVENT_CHANGE); |
||||
combo.on(DynamicYearCombo.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(YearInterval.EVENT_ERROR); |
||||
} else { |
||||
this._clearTitle(); |
||||
this.element.removeClass(this.constants.timeErrorCls); |
||||
this.fireEvent(YearInterval.EVENT_CHANGE); |
||||
} |
||||
}); |
||||
|
||||
return combo; |
||||
}, |
||||
|
||||
|
||||
_dateCheck: function (date) { |
||||
return BI.print(BI.parseDateTime(date, "%Y"), "%Y") === date || BI.print(BI.parseDateTime(date, "%Y"), "%Y") === date; |
||||
}, |
||||
} |
||||
|
||||
_dateCheck(date) { |
||||
return ( |
||||
print(parseDateTime(date, "%Y"), "%Y") === date || |
||||
print(parseDateTime(date, "%Y"), "%Y") === date |
||||
); |
||||
} |
||||
|
||||
// 判是否在最大最小之间
|
||||
_checkVoid: function (obj) { |
||||
var o = this.options; |
||||
return !BI.checkDateVoid(obj.year, 1, 1, o.minDate, o.maxDate)[0]; |
||||
}, |
||||
_checkVoid(obj) { |
||||
const o = this.options; |
||||
|
||||
return !checkDateVoid(obj.year, 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)) { |
||||
let smallDate4Check = ""; |
||||
if (isNotNull(smallObj)) { |
||||
smallDate4Check = smallObj[0] || ""; |
||||
} |
||||
|
||||
var bigDate4Check = ""; |
||||
if (BI.isNotNull(bigObj)) { |
||||
let bigDate4Check = ""; |
||||
if (isNotNull(bigObj)) { |
||||
bigDate4Check = bigObj[0] || ""; |
||||
} |
||||
|
||||
return this._dateCheck(smallDate4Check) && BI.checkDateLegal(smallDate4Check) && this._checkVoid({ |
||||
year: smallObj[0], |
||||
month: 1, |
||||
day: 1 |
||||
}) && this._dateCheck(bigDate4Check) && BI.checkDateLegal(bigDate4Check) && this._checkVoid({ |
||||
year: bigObj[0], |
||||
month: 12, |
||||
day: 1 |
||||
}); |
||||
}, |
||||
|
||||
_compare: function (smallDate, bigDate) { |
||||
smallDate = BI.print(BI.parseDateTime(smallDate, "%Y"), "%Y"); |
||||
bigDate = BI.print(BI.parseDateTime(bigDate, "%Y"), "%Y"); |
||||
return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; |
||||
}, |
||||
_setTitle: function (v) { |
||||
return ( |
||||
this._dateCheck(smallDate4Check) && |
||||
checkDateLegal(smallDate4Check) && |
||||
this._checkVoid({ |
||||
year: smallObj[0], |
||||
month: 1, |
||||
day: 1, |
||||
}) && |
||||
this._dateCheck(bigDate4Check) && |
||||
checkDateLegal(bigDate4Check) && |
||||
this._checkVoid({ |
||||
year: bigObj[0], |
||||
month: 12, |
||||
day: 1, |
||||
}) |
||||
); |
||||
} |
||||
|
||||
_compare(smallDate, bigDate) { |
||||
smallDate = print(parseDateTime(smallDate, "%Y"), "%Y"); |
||||
bigDate = print(parseDateTime(bigDate, "%Y"), "%Y"); |
||||
|
||||
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.YearInterval.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(YearInterval.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.YearInterval.EVENT_VALID = "EVENT_VALID"; |
||||
BI.YearInterval.EVENT_ERROR = "EVENT_ERROR"; |
||||
BI.YearInterval.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.YearInterval.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; |
||||
BI.shortcut("bi.year_interval", BI.YearInterval); |
||||
|
||||
getValue() { |
||||
return { start: this.left.getValue(), end: this.right.getValue() }; |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue