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.
261 lines
8.3 KiB
261 lines
8.3 KiB
7 years ago
|
/**
|
||
|
*
|
||
7 years ago
|
* @class BI.SingleSelectInsertCombo
|
||
7 years ago
|
* @extends BI.Single
|
||
|
*/
|
||
7 years ago
|
BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
|
||
7 years ago
|
|
||
|
_defaultConfig: function () {
|
||
7 years ago
|
return BI.extend(BI.SingleSelectInsertCombo.superclass._defaultConfig.apply(this, arguments), {
|
||
7 years ago
|
baseCls: "bi-single-select-combo",
|
||
7 years ago
|
itemsCreator: BI.emptyFn,
|
||
|
valueFormatter: BI.emptyFn,
|
||
|
height: 28
|
||
|
});
|
||
|
},
|
||
|
|
||
|
_init: function () {
|
||
7 years ago
|
BI.SingleSelectInsertCombo.superclass._init.apply(this, arguments);
|
||
7 years ago
|
var self = this, o = this.options;
|
||
|
|
||
|
var assertShowValue = function () {
|
||
|
BI.isKey(self._startValue) && (self.storeValue = self._startValue);
|
||
|
self.trigger.getSearcher().setState(self.storeValue);
|
||
|
};
|
||
7 years ago
|
this.storeValue = o.value;
|
||
7 years ago
|
// 标记正在请求数据
|
||
7 years ago
|
this.requesting = false;
|
||
|
|
||
|
this.trigger = BI.createWidget({
|
||
7 years ago
|
type: "bi.single_select_trigger",
|
||
7 years ago
|
height: o.height,
|
||
|
// adapter: this.popup,
|
||
|
masker: {
|
||
|
offset: {
|
||
|
left: 1,
|
||
|
top: 1,
|
||
|
right: 2,
|
||
|
bottom: 33
|
||
|
}
|
||
|
},
|
||
|
valueFormatter: o.valueFormatter,
|
||
|
itemsCreator: function (op, callback) {
|
||
|
o.itemsCreator(op, function (res) {
|
||
|
if (op.times === 1 && BI.isNotNull(op.keywords)) {
|
||
7 years ago
|
// 预防trigger内部把当前的storeValue改掉
|
||
7 years ago
|
self.trigger.setValue(self.getValue());
|
||
|
}
|
||
|
callback.apply(self, arguments);
|
||
|
});
|
||
7 years ago
|
},
|
||
|
value: this.storeValue
|
||
7 years ago
|
});
|
||
|
|
||
|
this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () {
|
||
7 years ago
|
self._setStartValue();
|
||
7 years ago
|
this.getSearcher().setValue(self.storeValue);
|
||
|
});
|
||
|
this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () {
|
||
7 years ago
|
self._setStartValue();
|
||
7 years ago
|
});
|
||
|
this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () {
|
||
7 years ago
|
var keyword = this.getSearcher().getKeyword();
|
||
|
self.storeValue = keyword;
|
||
|
self.combo.setValue(self.storeValue);
|
||
|
self._setStartValue(keyword);
|
||
|
assertShowValue();
|
||
|
self.populate();
|
||
|
self._setStartValue();
|
||
7 years ago
|
});
|
||
|
this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) {
|
||
|
var last = BI.last(keywords);
|
||
|
keywords = BI.initial(keywords || []);
|
||
|
if (keywords.length > 0) {
|
||
|
self._joinKeywords(keywords, function () {
|
||
|
if (BI.isEndWithBlank(last)) {
|
||
|
self.combo.setValue(self.storeValue);
|
||
|
assertShowValue();
|
||
|
self.combo.populate();
|
||
7 years ago
|
self._setStartValue();
|
||
7 years ago
|
} else {
|
||
|
self.combo.setValue(self.storeValue);
|
||
|
assertShowValue();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) {
|
||
|
self.storeValue = this.getValue();
|
||
|
assertShowValue();
|
||
7 years ago
|
self._defaultState();
|
||
7 years ago
|
});
|
||
|
this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () {
|
||
|
if (!self.combo.isViewVisible()) {
|
||
|
self.combo.showView();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
this.combo = BI.createWidget({
|
||
|
type: "bi.combo",
|
||
|
toggle: false,
|
||
|
el: this.trigger,
|
||
|
adjustLength: 1,
|
||
|
popup: {
|
||
7 years ago
|
type: "bi.single_select_popup_view",
|
||
7 years ago
|
ref: function () {
|
||
|
self.popup = this;
|
||
|
self.trigger.setAdapter(this);
|
||
|
},
|
||
|
listeners: [{
|
||
|
eventName: BI.SingleSelectPopupView.EVENT_CHANGE,
|
||
|
action: function () {
|
||
|
self.storeValue = this.getValue();
|
||
|
self._adjust(function () {
|
||
|
assertShowValue();
|
||
7 years ago
|
self._defaultState();
|
||
7 years ago
|
});
|
||
|
}
|
||
|
}],
|
||
|
itemsCreator: o.itemsCreator,
|
||
|
valueFormatter: o.valueFormatter,
|
||
|
onLoaded: function () {
|
||
|
BI.nextTick(function () {
|
||
|
self.combo.adjustWidth();
|
||
|
self.combo.adjustHeight();
|
||
|
self.trigger.getSearcher().adjustView();
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
hideChecker: function (e) {
|
||
|
return triggerBtn.element.find(e.target).length === 0;
|
||
7 years ago
|
},
|
||
|
value: o.value
|
||
7 years ago
|
});
|
||
|
|
||
|
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () {
|
||
|
this.setValue(self.storeValue);
|
||
|
BI.nextTick(function () {
|
||
|
self.populate();
|
||
|
});
|
||
|
});
|
||
7 years ago
|
// 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件
|
||
7 years ago
|
this.wants2Quit = false;
|
||
|
this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () {
|
||
7 years ago
|
// important:关闭弹出时又可能没有退出编辑状态
|
||
7 years ago
|
self.trigger.stopEditing();
|
||
|
if (self.requesting === true) {
|
||
|
self.wants2Quit = true;
|
||
|
} else {
|
||
7 years ago
|
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CONFIRM);
|
||
7 years ago
|
}
|
||
|
});
|
||
|
|
||
|
var triggerBtn = BI.createWidget({
|
||
|
type: "bi.trigger_icon_button",
|
||
|
width: o.height,
|
||
|
height: o.height,
|
||
7 years ago
|
cls: "single-select-trigger-icon-button"
|
||
7 years ago
|
});
|
||
|
triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () {
|
||
|
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
|
||
|
}]
|
||
7 years ago
|
});
|
||
7 years ago
|
},
|
||
|
|
||
|
_defaultState: function () {
|
||
|
this.trigger.stopEditing();
|
||
|
this.combo.hideView();
|
||
|
},
|
||
|
|
||
|
_assertValue: function (val) {
|
||
|
},
|
||
|
|
||
|
_makeMap: function (values) {
|
||
|
return BI.makeObject(values || []);
|
||
|
},
|
||
|
|
||
|
_joinKeywords: function (keywords, callback) {
|
||
|
var self = this, o = this.options;
|
||
|
this._assertValue(this.storeValue);
|
||
|
this.requesting = true;
|
||
|
o.itemsCreator({
|
||
7 years ago
|
type: BI.SingleSelectInsertCombo.REQ_GET_ALL_DATA,
|
||
7 years ago
|
keywords: keywords
|
||
|
}, function (ob) {
|
||
7 years ago
|
var values = BI.map(ob.items, "value");
|
||
7 years ago
|
digest(values);
|
||
|
});
|
||
|
|
||
7 years ago
|
function digest (items) {
|
||
7 years ago
|
var selectedMap = self._makeMap(items);
|
||
|
BI.each(keywords, function (i, val) {
|
||
|
if (BI.isNotNull(selectedMap[val])) {
|
||
|
self.storeValue.value["remove"](val);
|
||
|
}
|
||
|
});
|
||
|
self._adjust(callback);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
_adjust: function (callback) {
|
||
|
var self = this, o = this.options;
|
||
7 years ago
|
adjust();
|
||
|
callback();
|
||
7 years ago
|
|
||
7 years ago
|
function adjust () {
|
||
7 years ago
|
if (self.wants2Quit === true) {
|
||
7 years ago
|
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CONFIRM);
|
||
7 years ago
|
self.wants2Quit = false;
|
||
|
}
|
||
|
self.requesting = false;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
_setStartValue: function (value) {
|
||
|
this._startValue = value;
|
||
|
this.popup.setStartValue(value);
|
||
|
},
|
||
|
|
||
|
setValue: function (v) {
|
||
7 years ago
|
this.storeValue = v;
|
||
7 years ago
|
this._assertValue(this.storeValue);
|
||
|
this.combo.setValue(this.storeValue);
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return this.storeValue;
|
||
|
},
|
||
|
|
||
|
populate: function () {
|
||
|
this.combo.populate.apply(this.combo, arguments);
|
||
|
}
|
||
|
});
|
||
|
|
||
7 years ago
|
BI.extend(BI.SingleSelectInsertCombo, {
|
||
7 years ago
|
REQ_GET_DATA_LENGTH: 0,
|
||
|
REQ_GET_ALL_DATA: -1
|
||
|
});
|
||
|
|
||
7 years ago
|
BI.SingleSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
|
||
7 years ago
|
|
||
7 years ago
|
BI.shortcut("bi.single_select_insert_combo", BI.SingleSelectInsertCombo);
|