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.
252 lines
7.4 KiB
252 lines
7.4 KiB
/** |
|
* |
|
* @class BI.MultiTreeCombo |
|
* @extends BI.Single |
|
*/ |
|
|
|
BI.MultiTreeCombo = BI.inherit(BI.Single, { |
|
|
|
constants: { |
|
offset: { |
|
top: 1, |
|
left: 1, |
|
right: 2, |
|
bottom: 33 |
|
} |
|
}, |
|
|
|
|
|
_defaultConfig: function () { |
|
return BI.extend(BI.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { |
|
baseCls: 'bi-multi-tree-combo', |
|
itemsCreator: BI.emptyFn, |
|
height: 25 |
|
}); |
|
}, |
|
|
|
_init: function () { |
|
BI.MultiTreeCombo.superclass._init.apply(this, arguments); |
|
|
|
var self = this, o = this.options; |
|
|
|
this.popup = BI.createWidget({ |
|
type: 'bi.multi_tree_popup_view', |
|
itemsCreator: o.itemsCreator, |
|
onLoaded: function () { |
|
BI.nextTick(function () { |
|
self.trigger.getCounter().adjustView(); |
|
self.trigger.getSearcher().adjustView(); |
|
}); |
|
} |
|
}); |
|
var isInit = false; |
|
var want2showCounter = false; |
|
|
|
this.popup.on(BI.MultiTreePopup.EVENT_AFTERINIT, function () { |
|
self.trigger.getCounter().adjustView(); |
|
isInit = true; |
|
if (want2showCounter === true) { |
|
showCounter(); |
|
} |
|
}); |
|
|
|
this.trigger = BI.createWidget({ |
|
type: "bi.multi_select_trigger", |
|
height: o.height, |
|
adapter: this.popup, |
|
masker: { |
|
offset: this.constants.offset |
|
}, |
|
searcher: { |
|
type: "bi.multi_tree_searcher", |
|
itemsCreator: o.itemsCreator |
|
}, |
|
switcher: { |
|
el: { |
|
type: "bi.multi_tree_check_selected_button" |
|
}, |
|
popup: { |
|
type: "bi.multi_tree_check_pane", |
|
itemsCreator: o.itemsCreator |
|
} |
|
} |
|
|
|
}); |
|
|
|
this.combo = BI.createWidget({ |
|
type: "bi.combo", |
|
toggle: false, |
|
el: this.trigger, |
|
adjustLength: 1, |
|
popup: this.popup |
|
}); |
|
|
|
this.storeValue = {value: {}}; |
|
var change = false; |
|
var clear = false; //标识当前是否点击了清空 |
|
|
|
var isSearching = function () { |
|
return self.trigger.getSearcher().isSearching(); |
|
}; |
|
|
|
var isPopupView = function () { |
|
return self.combo.isViewVisible(); |
|
}; |
|
|
|
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { |
|
self.storeValue = {value: self.combo.getValue()}; |
|
this.setValue(self.storeValue); |
|
}); |
|
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { |
|
self.storeValue = {value: this.getValue()}; |
|
self.combo.setValue(self.storeValue); |
|
BI.nextTick(function () { |
|
if (isPopupView()) { |
|
self.combo.populate(); |
|
} |
|
}); |
|
}); |
|
function showCounter() { |
|
if (isSearching()) { |
|
self.storeValue = {value: self.trigger.getValue()}; |
|
} else if (isPopupView()) { |
|
self.storeValue = {value: self.combo.getValue()}; |
|
} |
|
self.trigger.setValue(self.storeValue); |
|
} |
|
|
|
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { |
|
if (want2showCounter === false) { |
|
want2showCounter = true; |
|
} |
|
if (isInit === true) { |
|
want2showCounter = null; |
|
showCounter(); |
|
} |
|
}); |
|
this.trigger.on(BI.MultiSelectTrigger.EVENT_TRIGGER_CLICK, function () { |
|
self.combo.toggle(); |
|
}); |
|
this.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { |
|
if (!self.combo.isViewVisible()) { |
|
self.combo.showView(); |
|
} |
|
}); |
|
|
|
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { |
|
var val = { |
|
type: BI.Selection.Multi, |
|
value: this.getSearcher().hasChecked() ? {1: 1} : {} |
|
}; |
|
this.getSearcher().setState(val); |
|
this.getCounter().setButtonChecked(val); |
|
}); |
|
this.popup.on(BI.MultiTreePopup.EVENT_CHANGE, function () { |
|
change = true; |
|
var val = { |
|
type: BI.Selection.Multi, |
|
value: this.hasChecked() ? {1: 1} : {} |
|
}; |
|
self.trigger.getSearcher().setState(val); |
|
self.trigger.getCounter().setButtonChecked(val); |
|
}); |
|
|
|
this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CONFIRM, function () { |
|
self._defaultState(); |
|
}); |
|
this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CLEAR, function () { |
|
clear = true; |
|
self.setValue(); |
|
self._defaultState(); |
|
}); |
|
|
|
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { |
|
if (isSearching()) { |
|
return; |
|
} |
|
if (change === true) { |
|
self.storeValue = {value: self.combo.getValue()}; |
|
change = false; |
|
} |
|
self.combo.setValue(self.storeValue); |
|
self.populate(); |
|
|
|
}); |
|
this.combo.on(BI.Combo.EVENT_BEFORE_HIDEVIEW, function () { |
|
if (isSearching()) { |
|
self.trigger.stopEditing(); |
|
self.fireEvent(BI.MultiTreeCombo.EVENT_CONFIRM); |
|
return; |
|
} |
|
if (isPopupView()) { |
|
self.trigger.stopEditing(); |
|
self.storeValue = {value: self.combo.getValue()}; |
|
if (clear === true) { |
|
self.storeValue = {value: {}}; |
|
clear = false; |
|
change = false; |
|
} |
|
self.fireEvent(BI.MultiTreeCombo.EVENT_CONFIRM); |
|
} |
|
}); |
|
|
|
var triggerBtn = BI.createWidget({ |
|
type: "bi.trigger_icon_button", |
|
width: o.height, |
|
height: o.height, |
|
cls: "multi-select-trigger-icon-button" |
|
}); |
|
triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { |
|
self.trigger.getCounter().hideView(); |
|
if (self.combo.isViewVisible()) { |
|
self.combo.hideView(); |
|
} else { |
|
self.combo.showView(); |
|
} |
|
}); |
|
BI.createWidget({ |
|
type: "bi.absolute", |
|
element: this, |
|
items: [{ |
|
el: this.combo, |
|
left: 0, |
|
right: 0, |
|
top: 0, |
|
bottom: 0 |
|
}, { |
|
el: triggerBtn, |
|
right: 0, |
|
top: 0, |
|
bottom: 0 |
|
}] |
|
}) |
|
}, |
|
|
|
_defaultState: function () { |
|
this.trigger.stopEditing(); |
|
this.combo.hideView(); |
|
}, |
|
|
|
setEnable: function(v){ |
|
this.combo.setEnable(v); |
|
}, |
|
|
|
setValue: function (v) { |
|
this.storeValue.value = v || {}; |
|
this.combo.setValue({ |
|
value: v || {} |
|
}); |
|
}, |
|
|
|
getValue: function () { |
|
return this.storeValue.value; |
|
}, |
|
|
|
populate: function () { |
|
this.combo.populate.apply(this.combo, arguments); |
|
} |
|
}); |
|
|
|
BI.MultiTreeCombo.EVENT_CONFIRM = "MultiTreeCombo.EVENT_CONFIRM"; |
|
|
|
$.shortcut('bi.multi_tree_combo', BI.MultiTreeCombo); |