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.
116 lines
3.3 KiB
116 lines
3.3 KiB
BI.VirtualGroup = BI.inherit(BI.Widget, { |
|
_defaultConfig: function () { |
|
return BI.extend(BI.VirtualGroup.superclass._defaultConfig.apply(this, arguments), { |
|
baseCls: "bi-virtual-group", |
|
items: [], |
|
layouts: [{ |
|
type: "bi.center", |
|
hgap: 0, |
|
vgap: 0 |
|
}] |
|
}); |
|
}, |
|
|
|
render: function () { |
|
var o = this.options; |
|
this.populate(o.items); |
|
if (BI.isKey(o.value)) { |
|
this.setValue(o.value); |
|
} |
|
}, |
|
|
|
_packageBtns: function (items) { |
|
var o = this.options; |
|
var map = this.buttonMap = {}; |
|
for (var i = o.layouts.length - 1; i > 0; i--) { |
|
items = BI.map(items, function (k, it) { |
|
var el = BI.stripEL(it); |
|
return BI.extend({}, o.layouts[i], { |
|
items: [ |
|
BI.extend({}, o.layouts[i].el, { |
|
el: BI.extend({ |
|
ref: function (_ref) { |
|
if (BI.isKey(map[el.value])) { |
|
map[el.value] = _ref; |
|
} |
|
} |
|
}, el) |
|
}) |
|
] |
|
}); |
|
}); |
|
} |
|
return items; |
|
}, |
|
|
|
_packageLayout: function (items) { |
|
var o = this.options, layout = BI.deepClone(o.layouts[0]); |
|
|
|
var lay = BI.formatEL(layout).el; |
|
while (lay && lay.items && !BI.isEmpty(lay.items)) { |
|
lay = BI.formatEL(lay.items[0]).el; |
|
} |
|
lay.items = items; |
|
return layout; |
|
}, |
|
|
|
addItems: function (items) { |
|
this.layouts.addItems(items); |
|
}, |
|
|
|
prependItems: function (items) { |
|
this.layouts.prependItems(items); |
|
}, |
|
|
|
setValue: function (v) { |
|
v = BI.isArray(v) ? v : [v]; |
|
BI.each(this.buttonMap, function (key, item) { |
|
if (item) { |
|
if (v.deepContains(key)) { |
|
item.setSelected && item.setSelected(true); |
|
} else { |
|
item.setSelected && item.setSelected(false); |
|
} |
|
} |
|
}); |
|
}, |
|
|
|
getNotSelectedValue: function () { |
|
var v = []; |
|
BI.each(this.buttonMap, function (i, item) { |
|
if (item) { |
|
if (item.isEnabled() && !(item.isSelected && item.isSelected())) { |
|
v.push(item.getValue()); |
|
} |
|
} |
|
}); |
|
return v; |
|
}, |
|
|
|
getValue: function () { |
|
var v = []; |
|
BI.each(this.buttonMap, function (i, item) { |
|
if (item) { |
|
if (item.isEnabled() && item.isSelected && item.isSelected()) { |
|
v.push(item.getValue()); |
|
} |
|
} |
|
}); |
|
return v; |
|
}, |
|
|
|
populate: function (items) { |
|
var self = this; |
|
items = items || []; |
|
this.options.items = items; |
|
items = this._packageBtns(items); |
|
if (!this.layouts) { |
|
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); |
|
} else { |
|
this.layouts.populate(items); |
|
} |
|
} |
|
}); |
|
BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE"; |
|
|
|
BI.shortcut("bi.virtual_group", BI.VirtualGroup); |