/** * 文件管理导航 * * Created by GUY on 2015/12/11. * @class BI.FileManagerNav * @extends BI.Widget */ BI.FileManagerNav = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.FileManagerNav.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-file-manager-nav bi-border-left", height: 40, items: [] }) }, _init: function () { BI.FileManagerNav.superclass._init.apply(this, arguments); var self = this, o = this.options; this.tree = new BI.Tree(); this.refreshTreeData(o.items); this.tree.getRoot().set("data", { text: BI.i18nText("BI-Created_By_Me"), value: BI.FileManagerNav.ROOT_CREATE_BY_ME, id: BI.FileManagerNav.ROOT_CREATE_BY_ME }); this.button_group = BI.createWidget({ type: "bi.button_group", element: this, items: [{ type: "bi.file_manager_nav_button", text: BI.i18nText("BI-Created_By_Me"), selected: true, id: BI.FileManagerNav.ROOT_CREATE_BY_ME, value: BI.FileManagerNav.ROOT_CREATE_BY_ME }], layouts: [{ type: "bi.horizontal" }] }); this.button_group.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); }); }, _getAllParents: function (id) { var node, res = []; if (!id) { node = this.tree.getRoot(); } else { node = this.tree.search(id); } while (node.parent) { res.push(node); node = node.parent; } res.push(node); return res.reverse(); }, _formatNodes: function (nodes) { var res = []; BI.each(nodes, function (i, node) { res.push(BI.extend({ type: "bi.file_manager_nav_button", id: node.id }, node.get("data"))); }); BI.last(res).selected = true; return res; }, getValue: function () { return this.button_group.getValue(); }, getId: function () { var ids = []; BI.each(this.button_group.getSelectedButtons(), function (i, btn) { ids.push(btn.attr("id")); }); return ids; }, refreshTreeData: function(items){ this.tree.initTree(BI.Tree.transformToTreeFormat(items)); this.tree.getRoot().set("data", { text: BI.i18nText("BI-Created_By_Me"), value: BI.FileManagerNav.ROOT_CREATE_BY_ME, id: BI.FileManagerNav.ROOT_CREATE_BY_ME }); }, populate: function (node) { var parents = BI.isNull(node) ? [this.tree.getRoot()] : this._getAllParents(node.id); this.button_group.populate(this._formatNodes(parents)); } }); BI.extend(BI.FileManagerNav, { ROOT_CREATE_BY_ME: "-1" }); BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE"; BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);