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.
172 lines
5.1 KiB
172 lines
5.1 KiB
8 years ago
|
/**
|
||
|
* list面板
|
||
|
*
|
||
|
* Created by GUY on 2015/10/30.
|
||
|
* @class BI.ListPane
|
||
|
* @extends BI.Pane
|
||
|
*/
|
||
|
BI.ListPane = BI.inherit(BI.Pane, {
|
||
|
|
||
|
_defaultConfig: function () {
|
||
|
var conf = BI.ListPane.superclass._defaultConfig.apply(this, arguments);
|
||
|
return BI.extend(conf, {
|
||
|
baseCls: (conf.baseCls || "") + " bi-list-pane",
|
||
|
logic: {
|
||
|
dynamic: true
|
||
|
},
|
||
|
lgap: 0,
|
||
|
rgap: 0,
|
||
|
tgap: 0,
|
||
|
bgap: 0,
|
||
|
vgap: 0,
|
||
|
hgap: 0,
|
||
|
items: [],
|
||
|
itemsCreator: BI.emptyFn,
|
||
|
hasNext: BI.emptyFn,
|
||
|
onLoaded: BI.emptyFn,
|
||
|
el: {
|
||
|
type: "bi.button_group"
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
_init: function () {
|
||
|
BI.ListPane.superclass._init.apply(this, arguments);
|
||
|
var self = this, o = this.options;
|
||
|
|
||
|
this.button_group = BI.createWidget(o.el, {
|
||
|
type: "bi.button_group",
|
||
|
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
|
||
|
behaviors: {},
|
||
|
items: o.items,
|
||
|
itemsCreator: function (op, calback) {
|
||
|
if (op.times === 1) {
|
||
|
self.empty();
|
||
|
BI.nextTick(function () {
|
||
|
self.loading()
|
||
|
});
|
||
|
}
|
||
|
o.itemsCreator(op, function () {
|
||
|
calback.apply(self, arguments);
|
||
|
op.times === 1 && BI.nextTick(function () {
|
||
|
self.loaded();
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
hasNext: o.hasNext,
|
||
|
layouts: [{
|
||
|
type: "bi.vertical"
|
||
|
}]
|
||
|
});
|
||
|
|
||
|
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
|
||
|
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
|
||
|
if (type === BI.Events.CLICK) {
|
||
|
self.fireEvent(BI.ListPane.EVENT_CHANGE, value, obj);
|
||
|
}
|
||
|
});
|
||
|
this.check();
|
||
|
|
||
|
BI.createWidget(BI.extend({
|
||
|
element: this.element
|
||
|
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Top), BI.extend({
|
||
|
scrolly: true,
|
||
|
lgap: o.lgap,
|
||
|
rgap: o.rgap,
|
||
|
tgap: o.tgap,
|
||
|
bgap: o.bgap,
|
||
|
vgap: o.vgap,
|
||
|
hgap: o.hgap
|
||
|
}, o.logic, {
|
||
|
items: BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Top, this.button_group)
|
||
|
}))));
|
||
|
},
|
||
|
|
||
|
hasPrev: function () {
|
||
|
return this.button_group.hasPrev && this.button_group.hasPrev();
|
||
|
},
|
||
|
|
||
|
hasNext: function () {
|
||
|
return this.button_group.hasNext && this.button_group.hasNext();
|
||
|
},
|
||
|
|
||
|
prependItems: function (items) {
|
||
|
this.options.items = items.concat(this.options.items);
|
||
|
this.button_group.prependItems.apply(this.button_group, arguments);
|
||
|
this.check();
|
||
|
},
|
||
|
|
||
|
addItems: function (items) {
|
||
|
this.options.items = this.options.items.concat(items);
|
||
|
this.button_group.addItems.apply(this.button_group, arguments);
|
||
|
this.check();
|
||
|
},
|
||
|
|
||
|
populate: function (items) {
|
||
|
var self = this, o = this.options;
|
||
|
if (arguments.length === 0 && (BI.isFunction(this.button_group.attr("itemsCreator")))) {//接管loader的populate方法
|
||
|
this.button_group.attr("itemsCreator").apply(this, [{times: 1}, function () {
|
||
|
if (arguments.length === 0) {
|
||
|
throw new Error("参数不能为空");
|
||
|
}
|
||
|
self.populate.apply(self, arguments);
|
||
|
}]);
|
||
|
return;
|
||
|
}
|
||
|
BI.ListPane.superclass.populate.apply(this, arguments);
|
||
|
this.button_group.populate.apply(this.button_group, arguments);
|
||
|
},
|
||
|
|
||
|
empty: function () {
|
||
|
this.button_group.empty();
|
||
|
},
|
||
|
|
||
|
doBehavior: function () {
|
||
|
this.button_group.doBehavior.apply(this.button_group, arguments);
|
||
|
},
|
||
|
|
||
|
setNotSelectedValue: function () {
|
||
|
this.button_group.setNotSelectedValue.apply(this.button_group, arguments);
|
||
|
},
|
||
|
|
||
|
getNotSelectedValue: function () {
|
||
|
return this.button_group.getNotSelectedValue();
|
||
|
},
|
||
|
|
||
|
setValue: function () {
|
||
|
this.button_group.setValue.apply(this.button_group, arguments);
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return this.button_group.getValue.apply(this.button_group, arguments);
|
||
|
},
|
||
|
|
||
|
getAllButtons: function () {
|
||
|
return this.button_group.getAllButtons();
|
||
|
},
|
||
|
|
||
|
getAllLeaves: function () {
|
||
|
return this.button_group.getAllLeaves();
|
||
|
},
|
||
|
|
||
|
getSelectedButtons: function () {
|
||
|
return this.button_group.getSelectedButtons();
|
||
|
},
|
||
|
|
||
|
getNotSelectedButtons: function () {
|
||
|
return this.button_group.getNotSelectedButtons();
|
||
|
},
|
||
|
|
||
|
getIndexByValue: function (value) {
|
||
|
return this.button_group.getIndexByValue(value);
|
||
|
},
|
||
|
|
||
|
getNodeById: function (id) {
|
||
|
return this.button_group.getNodeById(id);
|
||
|
},
|
||
|
|
||
|
getNodeByValue: function (value) {
|
||
|
return this.button_group.getNodeByValue(value);
|
||
|
}
|
||
|
});
|
||
|
BI.ListPane.EVENT_CHANGE = "EVENT_CHANGE";
|
||
|
$.shortcut("bi.list_pane", BI.ListPane);
|