forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
6.0 KiB
180 lines
6.0 KiB
/** |
|
* @class BI.MultiLayerSelectTreeCombo |
|
* @extends BI.Widget |
|
*/ |
|
BI.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, { |
|
|
|
_defaultConfig: function () { |
|
return BI.extend(BI.MultiLayerSelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { |
|
baseCls: "bi-multilayer-select-tree-combo", |
|
isDefaultInit: false, |
|
height: 24, |
|
text: "", |
|
itemsCreator: BI.emptyFn, |
|
items: [], |
|
value: "", |
|
attributes: { |
|
tabIndex: 0 |
|
}, |
|
allowEdit: false |
|
}); |
|
}, |
|
|
|
render: function () { |
|
var self = this, o = this.options; |
|
|
|
var combo = (o.itemsCreator === BI.emptyFn) ? this._getSyncConfig() : this._getAsyncConfig(); |
|
|
|
return (!o.allowEdit && o.itemsCreator === BI.emptyFn) ? combo : { |
|
type: "bi.absolute", |
|
items: [{ |
|
el: combo, |
|
left: 0, |
|
right: 0, |
|
top: 0, |
|
bottom: 0 |
|
}, { |
|
el: { |
|
type: "bi.trigger_icon_button", |
|
cls: "trigger-icon-button", |
|
ref: function (_ref) { |
|
self.triggerBtn = _ref; |
|
}, |
|
width: o.height, |
|
height: o.height, |
|
handler: function () { |
|
if (self.combo.isViewVisible()) { |
|
self.combo.hideView(); |
|
} else { |
|
self.combo.showView(); |
|
} |
|
} |
|
}, |
|
right: 0, |
|
bottom: 0, |
|
top: 0 |
|
}] |
|
}; |
|
}, |
|
|
|
_getBaseConfig: function () { |
|
var self = this, o = this.options; |
|
return { |
|
type: "bi.combo", |
|
container: o.container, |
|
adjustLength: 2, |
|
ref: function (_ref) { |
|
self.combo = _ref; |
|
}, |
|
popup: { |
|
el: { |
|
type: "bi.multilayer_select_tree_popup", |
|
isDefaultInit: o.isDefaultInit, |
|
itemsCreator: o.itemsCreator, |
|
items: o.items, |
|
ref: function (_ref) { |
|
self.trigger && self.trigger.getSearcher().setAdapter(_ref); |
|
}, |
|
listeners: [{ |
|
eventName: BI.MultiLayerSelectTreePopup.EVENT_CHANGE, |
|
action: function () { |
|
self.setValue(this.getValue()); |
|
self.combo.hideView(); |
|
self.fireEvent(BI.MultiLayerSelectTreeCombo.EVENT_CHANGE); |
|
} |
|
}] |
|
}, |
|
value: o.value, |
|
maxHeight: 400 |
|
} |
|
}; |
|
}, |
|
|
|
_getSyncConfig: function () { |
|
var o = this.options; |
|
var baseConfig = this._getBaseConfig(); |
|
baseConfig.el = { |
|
type: "bi.single_tree_trigger", |
|
text: o.text, |
|
height: o.height, |
|
items: o.items, |
|
value: o.value |
|
}; |
|
return baseConfig; |
|
}, |
|
|
|
_getAsyncConfig: function () { |
|
var self = this, o = this.options; |
|
var config = this._getBaseConfig(); |
|
return BI.extend(config, { |
|
el: { |
|
type: "bi.multilayer_select_tree_trigger", |
|
allowEdit: o.allowEdit, |
|
cls: "multilayer-select-tree-trigger", |
|
ref: function (_ref) { |
|
self.trigger = _ref; |
|
}, |
|
items: o.items, |
|
itemsCreator: o.itemsCreator, |
|
valueFormatter: o.valueFormatter, |
|
height: o.height - 2, |
|
text: o.text, |
|
value: o.value, |
|
tipType: o.tipType, |
|
warningTitle: o.warningTitle, |
|
title: o.title, |
|
listeners: [{ |
|
eventName: BI.MultiLayerSelectTreeTrigger.EVENT_CHANGE, |
|
action: function () { |
|
self.setValue(this.getValue()); |
|
self.combo.hideView(); |
|
self.fireEvent(BI.MultiLayerSelectTreeCombo.EVENT_CHANGE); |
|
} |
|
}, { |
|
eventName: BI.MultiLayerSelectTreeTrigger.EVENT_FOCUS, |
|
action: function () { |
|
self.fireEvent(BI.MultiLayerSelectTreeCombo.EVENT_FOCUS); |
|
} |
|
}, { |
|
eventName: BI.MultiLayerSelectTreeTrigger.EVENT_BLUR, |
|
action: function () { |
|
self.fireEvent(BI.MultiLayerSelectTreeCombo.EVENT_BLUR); |
|
} |
|
}, { |
|
eventName: BI.MultiLayerSelectTreeTrigger.EVENT_SEARCHING, |
|
action: function () { |
|
self.fireEvent(BI.MultiLayerSelectTreeCombo.EVENT_SEARCHING); |
|
} |
|
}] |
|
}, |
|
hideChecker: function (e) { |
|
return self.triggerBtn.element.find(e.target).length === 0; |
|
}, |
|
listeners: [{ |
|
eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, |
|
action: function () { |
|
self.trigger.stopEditing(); |
|
} |
|
}] |
|
}); |
|
}, |
|
|
|
setValue: function (v) { |
|
v = BI.isArray(v) ? v : [v]; |
|
this.combo.setValue(v); |
|
}, |
|
|
|
getValue: function () { |
|
return this.combo.getValue(); |
|
}, |
|
|
|
populate: function (items) { |
|
this.combo.populate(items); |
|
} |
|
}); |
|
|
|
BI.MultiLayerSelectTreeCombo.EVENT_SEARCHING = "EVENT_SEARCHING"; |
|
BI.MultiLayerSelectTreeCombo.EVENT_BLUR = "EVENT_BLUR"; |
|
BI.MultiLayerSelectTreeCombo.EVENT_FOCUS = "EVENT_FOCUS"; |
|
BI.MultiLayerSelectTreeCombo.EVENT_CHANGE = "EVENT_CHANGE"; |
|
BI.shortcut("bi.multilayer_select_tree_combo", BI.MultiLayerSelectTreeCombo); |