/** * 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(); // callback可能在loading之前执行, check保证显示正确 self.check(); }); }); }, 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 }, 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(); }, removeItemAt: function (indexes) { indexes = BI.isNull(indexes) ? [] : indexes; BI.removeAt(this.options.items, indexes); this.button_group.removeItemAt.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); var context = BI.get(arguments, [2], {}); var tipText = context.tipText || ''; BI.isNotEmptyString(tipText) && this.setTipText(tipText); this.button_group.populate.apply(this.button_group, arguments); }, empty: function () { this.button_group.empty(); }, 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"; BI.shortcut("bi.list_pane", BI.ListPane);