/** * 文件管理控件 * * Created by GUY on 2015/12/11. * @class BI.FileManager * @extends BI.Widget */ BI.FileManager = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.FileManager.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-file-manager", el: {}, items: [] }); }, _init: function () { BI.FileManager.superclass._init.apply(this, arguments); var self = this, o = this.options; this.tree = new BI.Tree(); var items = BI.Tree.transformToTreeFormat(o.items); this.tree.initTree(items); this.selectedValues = []; this.nav = BI.createWidget({ type: "bi.file_manager_nav", items: BI.deepClone(items) }); this.nav.on(BI.FileManagerNav.EVENT_CHANGE, function (value, obj) { if (value == "-1") {// 根节点 self.populate({children: self.tree.toJSON()}); } else { var node = self.tree.search(obj.attr("id")); self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); } self.setValue(self.selectedValues); }); this.list = BI.createWidget(o.el, { type: "bi.file_manager_list", items: items }); this.list.on(BI.Controller.EVENT_CHANGE, function (type, selected, obj) { if (type === BI.Events.CHANGE) { var node = self.tree.search(obj.attr("id")); self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); } else if (type === BI.Events.CLICK) { var values = []; if (obj instanceof BI.MultiSelectBar) { var t = self.list.getValue(); selected = t.type === BI.Selection.All; values = BI.concat(t.assist, t.value); } else { values = obj.getAllLeaves(); } BI.each(values, function (i, v) { if (selected === true) { self.selectedValues.pushDistinct(v); } else { self.selectedValues.remove(v); } }); } self.setValue(self.selectedValues); }); BI.createWidget({ type: "bi.absolute", element: this, items: [{ el: this.list, left: 0, right: 0, top: 0, bottom: 10 }, { el: this.nav, left: 40, right: 100, top: 0 }] }); }, setValue: function (value) { this.selectedValues = value || []; this.list.setValue(this.selectedValues); }, getValue: function () { var obj = this.list.getValue(); var res = obj.type === BI.Selection.All ? obj.assist : obj.value; res.pushDistinctArray(this.selectedValues); return res; }, _populate: function (items) { this.list.populate(items); }, getSelectedValue: function () { return this.nav.getValue()[0]; }, getSelectedId: function () { return this.nav.getId()[0]; }, populate: function (node) { var clone = BI.deepClone(node); this._populate(node.children); this.nav.populate(clone); } }); BI.FileManager.EVENT_CHANGE = "FileManager.EVENT_CHANGE"; BI.shortcut("bi.file_manager", BI.FileManager);