UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

368 lines (338 loc) • 11.1 kB
"use strict"; var extend = require("../../core/utils/extend").extend, Deferred = require("../../core/utils/deferred").Deferred, treeListCore = require("./ui.tree_list.core"), equalByValue = require("../../core/utils/common").equalByValue, dataSourceAdapterProvider = require("./ui.tree_list.data_source_adapter"), dataControllerModule = require("../grid_core/ui.grid_core.data_controller"); exports.DataController = dataControllerModule.controllers.data.inherit(function () { return { _getDataSourceAdapter: function _getDataSourceAdapter() { return dataSourceAdapterProvider; }, _getNodeLevel: function _getNodeLevel(node) { var level = -1; while (node.parent) { if (node.visible) { level++; } node = node.parent; } return level; }, _generateDataItem: function _generateDataItem(node) { return { rowType: "data", node: node, key: node.key, data: node.data, isExpanded: this.isRowExpanded(node.key), level: this._getNodeLevel(node) }; }, _loadOnOptionChange: function _loadOnOptionChange() { this._dataSource.load(); }, init: function init() { this.createAction("onRowExpanding"); this.createAction("onRowExpanded"); this.createAction("onRowCollapsing"); this.createAction("onRowCollapsed"); this.callBase.apply(this, arguments); }, keyOf: function keyOf(data) { var dataSource = this._dataSource; if (dataSource) { return dataSource.keyOf(data); } }, key: function key() { var dataSource = this._dataSource; if (dataSource) { return dataSource.getKeyExpr(); } }, publicMethods: function publicMethods() { return this.callBase().concat(["expandRow", "collapseRow", "isRowExpanded", "getRootNode", "getNodeByKey", "loadDescendants", "forEachNode"]); }, changeRowExpand: function changeRowExpand(key) { if (this._dataSource) { var that = this, args = { key: key }, isExpanded = this.isRowExpanded(key); that.executeAction(isExpanded ? "onRowCollapsing" : "onRowExpanding", args); if (!args.cancel) { return that._dataSource.changeRowExpand(key).done(function () { that.executeAction(isExpanded ? "onRowCollapsed" : "onRowExpanded", args); }); } } return new Deferred().resolve(); }, /** * @name dxTreeListMethods.isRowExpanded * @publicName isRowExpanded(key) * @param1 key:any * @return boolean */ isRowExpanded: function isRowExpanded(key) { return this._dataSource && this._dataSource.isRowExpanded(key); }, /** * @name dxTreeListMethods.expandRow * @publicName expandRow(key) * @param1 key:any * @return Promise<void> */ expandRow: function expandRow(key) { if (!this.isRowExpanded(key)) { return this.changeRowExpand(key); } return new Deferred().resolve(); }, /** * @name dxTreeListMethods.collapseRow * @publicName collapseRow(key) * @param1 key:any * @return Promise<void> */ collapseRow: function collapseRow(key) { if (this.isRowExpanded(key)) { return this.changeRowExpand(key); } return new Deferred().resolve(); }, /** * @name dxTreeListMethods.getRootNode * @publicName getRootNode() * @return dxTreeListNode */ getRootNode: function getRootNode() { return this._dataSource && this._dataSource.getRootNode(); }, optionChanged: function optionChanged(args) { switch (args.name) { case "rootValue": case "parentIdExpr": case "itemsExpr": case "filterMode": case "expandNodesOnFiltering": case "autoExpandAll": case "hasItemsExpr": case "dataStructure": this._columnsController.reset(); this._items = []; this._refreshDataSource(); args.handled = true; break; case "expandedRowKeys": case "onNodesInitialized": if (this._dataSource && !this._dataSource._isNodesInitializing && !equalByValue(args.value, args.previousValue)) { this._loadOnOptionChange(); } args.handled = true; break; case "maxFilterLengthInRequest": args.handled = true; break; default: this.callBase(args); } }, /** * @name dxTreeListMethods.getNodeByKey * @publicName getNodeByKey(key) * @param1 key:object|string|number * @return dxTreeListNode */ getNodeByKey: function getNodeByKey(key) { if (!this._dataSource) { return; } return this._dataSource.getNodeByKey(key); }, getChildNodeKeys: function getChildNodeKeys(parentKey) { if (!this._dataSource) { return; } return this._dataSource.getChildNodeKeys(parentKey); }, /** * @name dxTreeListMethods.loadDescendants * @publicName loadDescendants() * @return Promise<void> */ /** * @name dxTreeListMethods.loadDescendants * @publicName loadDescendants(keys) * @param1 keys:Array<any> * @return Promise<void> */ /** * @name dxTreeListMethods.loadDescendants * @publicName loadDescendants(keys, childrenOnly) * @param1 keys:Array<any> * @param2 childrenOnly:boolean * @return Promise<void> */ loadDescendants: function loadDescendants(keys, childrenOnly) { if (!this._dataSource) { return; } return this._dataSource.loadDescendants(keys, childrenOnly); }, /** * @name dxTreeListMethods.forEachNode * @publicName forEachNode(nodes, callback) * @param1 nodes:Array<dxTreeListNode> * @param2 callback:function */ /** * @name dxTreeListMethods.forEachNode * @publicName forEachNode(callback) * @param1 callback:function */ forEachNode: function forEachNode() { this._dataSource.forEachNode.apply(this, arguments); } }; }()); treeListCore.registerModule("data", { defaultOptions: function defaultOptions() { return extend({}, dataControllerModule.defaultOptions(), { /** * @name dxTreeListOptions.itemsExpr * @publicName itemsExpr * @type string|function * @default "items" */ itemsExpr: "items", /** * @name dxTreeListOptions.keyExpr * @publicName keyExpr * @type string|function * @default "id" */ /** * @name dxTreeListOptions.hasItemsExpr * @publicName hasItemsExpr * @type string|function */ /** * @name dxTreeListOptions.parentIdExpr * @publicName parentIdExpr * @type string|function * @default "parentId" */ parentIdExpr: "parentId", /** * @name dxTreeListOptions.rootValue * @type Object * @publicName rootValue * @default 0 */ rootValue: 0, /** * @name dxTreeListOptions.dataStructure * @publicName dataStructure * @type Enums.TreeListDataStructure * @default "plain" */ dataStructure: "plain", /** * @name dxTreeListOptions.expandedRowKeys * @publicName expandedRowKeys * @type Array<any> * @default [] * @fires dxTreeListOptions.onOptionChanged */ expandedRowKeys: [], filterMode: "extended", /** * @name dxTreeListOptions.expandNodesOnFiltering * @publicName expandNodesOnFiltering * @type boolean * @default true */ expandNodesOnFiltering: true, /** * @name dxTreeListOptions.autoExpandAll * @publicName autoExpandAll * @type boolean * @default false */ autoExpandAll: false, /** * @name dxTreeListOptions.onNodesInitialized * @publicName onNodesInitialized * @type function(e) * @type_function_param1 e:object * @type_function_param1_field4 root:dxTreeListNode * @extends Action * @action */ onNodesInitialized: null, maxFilterLengthInRequest: 1500, /** * @name dxTreeListOptions.paging * @publicName paging * @type object */ paging: { /** * @name dxTreeListOptions.paging.enabled * @publicName enabled * @type boolean * @default false * @inheritdoc */ enabled: false } }); }, controllers: { data: exports.DataController } }); /** * @name dxTreeListNode * @publicName dxTreeListNode * @type object */ /** * @name dxTreeListNode.key * @publicName key * @type any */ /** * @name dxTreeListNode.data * @publicName data * @type object */ /** * @name dxTreeListNode.parent * @publicName parent * @type dxTreeListNode */ /** * @name dxTreeListNode.children * @publicName children * @type Array<dxTreeListNode> */ /** * @name dxTreeListNode.hasChildren * @publicName hasChildren * @type boolean */ /** * @name dxTreeListNode.visible * @publicName visible * @type boolean */ /** * @name dxTreeListNode.level * @publicName level * @type number */