UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

1,237 lines • 71.6 kB
/** * DevExtreme (esm/ui/gantt/ui.gantt.js) * Version: 21.1.4 * Build date: Mon Jun 21 2021 * * Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import $ from "../../core/renderer"; import { isDefined } from "../../core/utils/type"; import Widget from "../widget/ui.widget"; import registerComponent from "../../core/component_registrator"; import { compileGetter, compileSetter } from "../../core/utils/data"; import { GanttView } from "./ui.gantt.view"; import { GanttToolbar, GanttContextMenuBar } from "./ui.gantt.bars"; import dxTreeList from "../tree_list"; import { extend } from "../../core/utils/extend"; import { getBoundingRect } from "../../core/utils/position"; import { hasWindow, getWindow } from "../../core/utils/window"; import DataOption from "./ui.gantt.data.option"; import SplitterControl from "../splitter"; import { GanttDialog } from "./ui.gantt.dialogs"; import LoadPanel from "../load_panel"; import { getPublicElement } from "../../core/element"; import { GanttDataCache } from "./ui.gantt.cache"; import { GanttExportHelper } from "./ui.gantt.export_helper"; var window = getWindow(); var GANTT_CLASS = "dx-gantt"; var GANTT_VIEW_CLASS = "dx-gantt-view"; var GANTT_COLLAPSABLE_ROW = "dx-gantt-collapsable-row"; var GANTT_TREE_LIST_WRAPPER = "dx-gantt-treelist-wrapper"; var GANTT_TOOLBAR_WRAPPER = "dx-gantt-toolbar-wrapper"; var GANTT_MAIN_WRAPPER = "dx-gantt-main-wrapper"; var GANTT_TASKS = "tasks"; var GANTT_DEPENDENCIES = "dependencies"; var GANTT_RESOURCES = "resources"; var GANTT_RESOURCE_ASSIGNMENTS = "resourceAssignments"; var GANTT_NEW_TASK_CACHE_KEY = "gantt_new_task_key"; var GANTT_DEFAULT_ROW_HEIGHT = 34; var GANTT_MAPPED_FIELD_REGEX = /(\w*)Expr/; class Gantt extends Widget { _init() { super._init(); this._cache = new GanttDataCache; this._isGanttRendered = false } _initMarkup() { super._initMarkup(); this.$element().addClass(GANTT_CLASS); this._$toolbarWrapper = $("<div>").addClass(GANTT_TOOLBAR_WRAPPER).appendTo(this.$element()); this._$toolbar = $("<div>").appendTo(this._$toolbarWrapper); this._$mainWrapper = $("<div>").addClass(GANTT_MAIN_WRAPPER).appendTo(this.$element()); this._$treeListWrapper = $("<div>").addClass(GANTT_TREE_LIST_WRAPPER).appendTo(this._$mainWrapper); this._$treeList = $("<div>").appendTo(this._$treeListWrapper); this._$splitter = $("<div>").appendTo(this._$mainWrapper); this._$ganttView = $("<div>").addClass(GANTT_VIEW_CLASS).appendTo(this._$mainWrapper); this._$dialog = $("<div>").appendTo(this.$element()); this._$loadPanel = $("<div>").appendTo(this.$element()); this._$contextMenu = $("<div>").appendTo(this.$element()); this._refreshDataSource(GANTT_TASKS); this._refreshDataSource(GANTT_DEPENDENCIES); this._refreshDataSource(GANTT_RESOURCES); this._refreshDataSource(GANTT_RESOURCE_ASSIGNMENTS) } _refresh() { this._isGanttRendered = false; super._refresh() } _renderContent() { this._isMainElementVisible = this.$element().is(":visible"); if (this._isMainElementVisible && !this._isGanttRendered) { this._isGanttRendered = true; this._renderBars(); this._renderTreeList(); this._renderSplitter() } } _renderTreeList() { var { keyExpr: keyExpr, parentIdExpr: parentIdExpr } = this.option(GANTT_TASKS); this._treeList = this._createComponent(this._$treeList, dxTreeList, { dataSource: this._tasksRaw, keyExpr: keyExpr, parentIdExpr: parentIdExpr, columns: this._getTreeListColumns(), columnResizingMode: "nextColumn", height: this._getTreeListHeight(), width: this.option("taskListWidth"), selection: { mode: this._getSelectionMode(this.option("allowSelection")) }, selectedRowKeys: this._getArrayFromOneElement(this.option("selectedRowKey")), sorting: { mode: "none" }, scrolling: { showScrollbar: "onHover", mode: "virtual" }, allowColumnResizing: true, autoExpandAll: true, showRowLines: this.option("showRowLines"), rootValue: this.option("rootValue"), onContentReady: e => { this._onTreeListContentReady(e) }, onSelectionChanged: e => { this._onTreeListSelectionChanged(e) }, onRowCollapsed: e => { this._onTreeListRowCollapsed(e) }, onRowExpanded: e => { this._onTreeListRowExpanded(e) }, onRowPrepared: e => { this._onTreeListRowPrepared(e) }, onContextMenuPreparing: e => { this._onTreeListContextMenuPreparing(e) }, onRowClick: e => { this._onTreeListRowClick(e) }, onRowDblClick: e => { this._onTreeListRowDblClick(e) } }) } _renderSplitter() { this._splitter = this._createComponent(this._$splitter, SplitterControl, { container: this.$element(), leftElement: this._$treeListWrapper, rightElement: this._$ganttView, onApplyPanelSize: this._onApplyPanelSize.bind(this) }); this._splitter.option("initialLeftPanelWidth", this.option("taskListWidth")) } _renderBars() { this._bars = []; this._toolbar = new GanttToolbar(this._$toolbar, this); this._updateToolbarContent(); this._bars.push(this._toolbar); this._contextMenuBar = new GanttContextMenuBar(this._$contextMenu, this); this._updateContextMenu(); this._bars.push(this._contextMenuBar) } _initGanttView() { if (this._ganttView) { return } this._ganttView = this._createComponent(this._$ganttView, GanttView, { width: "100%", height: this._treeList._$element.get(0).offsetHeight, rowHeight: this._getTreeListRowHeight(), headerHeight: this._getTreeListHeaderHeight(), tasks: this._tasks, dependencies: this._dependencies, resources: this._resources, resourceAssignments: this._resourceAssignments, allowSelection: this.option("allowSelection"), selectedRowKey: this.option("selectedRowKey"), showResources: this.option("showResources"), taskTitlePosition: this.option("taskTitlePosition"), firstDayOfWeek: this.option("firstDayOfWeek"), showRowLines: this.option("showRowLines"), scaleType: this.option("scaleType"), editing: this.option("editing"), validation: this.option("validation"), stripLines: this.option("stripLines"), bars: this._bars, mainElement: this.$element(), onSelectionChanged: this._onGanttViewSelectionChanged.bind(this), onScroll: this._onGanttViewScroll.bind(this), onDialogShowing: this._showDialog.bind(this), onPopupMenuShowing: this._showPopupMenu.bind(this), onExpandAll: this._expandAll.bind(this), onCollapseAll: this._collapseAll.bind(this), modelChangesListener: this._createModelChangesListener(), exportHelper: this._getExportHelper(), taskTooltipContentTemplate: this._getTaskTooltipContentTemplateFunc(this.option("taskTooltipContentTemplate")), taskProgressTooltipContentTemplate: this._getTaskProgressTooltipContentTemplateFunc(this.option("taskProgressTooltipContentTemplate")), taskTimeTooltipContentTemplate: this._getTaskTimeTooltipContentTemplateFunc(this.option("taskTimeTooltipContentTemplate")), taskContentTemplate: this._getTaskContentTemplateFunc(this.option("taskContentTemplate")), onTaskClick: e => { this._onTreeListRowClick(e) }, onTaskDblClick: e => { this._onTreeListRowDblClick(e) }, onAdjustControl: () => { this._onAdjustControl() } }); this._fireContentReadyAction() } _onAdjustControl() { var elementHeight = this._$element.height(); this._updateGanttWidth(); this._setGanttHeight(elementHeight) } _onApplyPanelSize(e) { this._setInnerElementsWidth(e); this._updateGanttRowHeights() } _updateGanttRowHeights() { var rowHeight = this._getTreeListRowHeight(); if (this._getGanttViewOption("rowHeight") !== rowHeight) { var _this$_ganttView; this._setGanttViewOption("rowHeight", rowHeight); null === (_this$_ganttView = this._ganttView) || void 0 === _this$_ganttView ? void 0 : _this$_ganttView._ganttViewCore.updateRowHeights(rowHeight) } } _onTreeListContentReady(e) { if (e.component.getDataSource()) { this._initGanttView(); this._initScrollSync(e.component) } } _onTreeListRowPrepared(e) { if ("data" === e.rowType && e.node.children.length > 0) { $(e.rowElement).addClass(GANTT_COLLAPSABLE_ROW) } } _onTreeListContextMenuPreparing(e) { var _e$row, _e$row2; if ("data" === (null === (_e$row = e.row) || void 0 === _e$row ? void 0 : _e$row.rowType)) { this._setTreeListOption("selectedRowKeys", [e.row.data[this.option("tasks.keyExpr")]]) } e.items = []; var info = { cancel: false, event: e.event, type: "task", key: null === (_e$row2 = e.row) || void 0 === _e$row2 ? void 0 : _e$row2.key, position: { x: e.event.pageX, y: e.event.pageY } }; this._showPopupMenu(info) } _onTreeListRowClick(e) { this._raiseTaskClickAction(e.key, e.event) } _onTreeListRowDblClick(e) { if (this._raiseTaskDblClickAction(e.key, e.event)) { this._ganttView._ganttViewCore.showTaskEditDialog() } } _onTreeListSelectionChanged(e) { var selectedRowKey = e.currentSelectedRowKeys[0]; this._setGanttViewOption("selectedRowKey", selectedRowKey); this._setOptionWithoutOptionChange("selectedRowKey", selectedRowKey); this._raiseSelectionChangedAction(selectedRowKey) } _onTreeListRowCollapsed(e) { this._ganttView.changeTaskExpanded(e.key, false); this._adjustHeight() } _onTreeListRowExpanded(e) { this._ganttView.changeTaskExpanded(e.key, true); this._adjustHeight() } _adjustHeight() { if (!this._hasHeight) { this._setGanttViewOption("height", 0); this._setGanttViewOption("height", this._treeList._$element.get(0).offsetHeight) } } _getTreeListHeight() { if (this._$treeList.height()) { return this._$treeList.height() } this._hasHeight = isDefined(this.option("height")) && "" !== this.option("height"); return this._hasHeight ? "100%" : "" } _getTreeListColumns() { var columns = this.option("columns"); if (columns) { for (var i = 0; i < columns.length; i++) { var column = columns[i]; var isKeyColumn = column.dataField === this.option("".concat(GANTT_TASKS, ".keyExpr")) || column.dataField === this.option("".concat(GANTT_TASKS, ".parentIdExpr")); if (isKeyColumn && !column.dataType) { column.dataType = "object" } } } return columns } _onGanttViewSelectionChanged(e) { this._setTreeListOption("selectedRowKeys", this._getArrayFromOneElement(e.id)) } _onGanttViewScroll(e) { var treeListScrollable = this._treeList.getScrollable(); if (treeListScrollable) { var diff = e.scrollTop - treeListScrollable.scrollTop(); if (0 !== diff) { treeListScrollable.scrollBy({ left: 0, top: diff }) } } } _onTreeListScroll(treeListScrollView) { var ganttViewTaskAreaContainer = this._ganttView.getTaskAreaContainer(); if (ganttViewTaskAreaContainer.scrollTop !== treeListScrollView.component.scrollTop()) { ganttViewTaskAreaContainer.scrollTop = treeListScrollView.component.scrollTop() } } _expandAll() { this._treeList.forEachNode(node => { if (node.children && node.children.length) { this._treeList.expandRow(node.key); this._ganttView.changeTaskExpanded(node.key, true) } }) } _collapseAll() { this._treeList.forEachNode(node => { if (node.children && node.children.length) { this._treeList.collapseRow(node.key); this._ganttView.changeTaskExpanded(node.key, false) } }) } _initScrollSync(treeList) { var treeListScrollable = treeList.getScrollable(); if (treeListScrollable) { treeListScrollable.off("scroll"); treeListScrollable.on("scroll", e => { this._onTreeListScroll(e) }) } } _getTreeListRowHeight() { var $row = this._treeList._$element.find(".dx-data-row"); var height = $row.length ? getBoundingRect($row.last().get(0)).height : GANTT_DEFAULT_ROW_HEIGHT; if (!height) { height = GANTT_DEFAULT_ROW_HEIGHT } this._correctRowsViewRowHeight(height); return height } _correctRowsViewRowHeight(height) { var view = this._treeList._views && this._treeList._views.rowsView; if ((null === view || void 0 === view ? void 0 : view._rowHeight) !== height) { view._rowHeight = height } } _getTreeListHeaderHeight() { return getBoundingRect(this._treeList._$element.find(".dx-treelist-headers").get(0)).height } _setInnerElementsWidth(widths) { if (!hasWindow()) { return } if (!widths) { widths = this._getPanelsWidthByOption() } this._setTreeListDimension("width", widths.leftPanelWidth); this._setGanttViewDimension("width", widths.rightPanelWidth) } _setTreeListDimension(dimension, value) { this._$treeListWrapper[dimension](value); this._setTreeListOption(dimension, this._$treeListWrapper[dimension]()) } _setGanttViewDimension(dimension, value) { this._$ganttView[dimension](value); this._setGanttViewOption(dimension, this._$ganttView[dimension]()) } _updateGanttWidth() { this._splitter._dimensionChanged() } _setGanttHeight(height) { var _this$_ganttView2; var toolbarHeightOffset = this._$toolbarWrapper.get(0).offsetHeight; var mainWrapperHeight = height - toolbarHeightOffset; this._setTreeListDimension("height", mainWrapperHeight); this._setGanttViewDimension("height", mainWrapperHeight); null === (_this$_ganttView2 = this._ganttView) || void 0 === _this$_ganttView2 ? void 0 : _this$_ganttView2._ganttViewCore.resetAndUpdate() } _getPanelsWidthByOption() { return { leftPanelWidth: this.option("taskListWidth"), rightPanelWidth: this._$element.width() - this.option("taskListWidth") } } _setGanttViewOption(optionName, value) { this._ganttView && this._ganttView.option(optionName, value) } _getGanttViewOption(optionName, value) { var _this$_ganttView3; return null === (_this$_ganttView3 = this._ganttView) || void 0 === _this$_ganttView3 ? void 0 : _this$_ganttView3.option(optionName) } _setTreeListOption(optionName, value) { this._treeList && this._treeList.option(optionName, value) } _refreshDataSource(name) { var dataOption = this["_".concat(name, "Option")]; if (dataOption) { dataOption._disposeDataSource(); delete this["_".concat(name, "Option")]; delete this["_".concat(name)] } if (this.option("".concat(name, ".dataSource"))) { dataOption = new DataOption(name, this._getLoadPanel(), (name, data) => { this._dataSourceChanged(name, data) }); dataOption.option("dataSource", this._getSpecificDataSourceOption(name)); dataOption._refreshDataSource(); this["_".concat(name, "Option")] = dataOption } } _getSpecificDataSourceOption(name) { var dataSource = this.option("".concat(name, ".dataSource")); if (Array.isArray(dataSource)) { return { store: { type: "array", data: dataSource, key: this.option("".concat(name, ".keyExpr")) } } } return dataSource } _compileGettersByOption(optionName) { var getters = {}; var optionValue = this.option(optionName); for (var field in optionValue) { var exprMatches = field.match(/(\w*)Expr/); if (exprMatches) { getters[exprMatches[1]] = compileGetter(optionValue[exprMatches[0]]) } } return getters } _compileSettersByOption(optionName) { var setters = {}; var optionValue = this.option(optionName); for (var field in optionValue) { var exprMatches = field.match(/(\w*)Expr/); if (exprMatches) { setters[exprMatches[1]] = compileSetter(optionValue[exprMatches[0]]) } } return setters } _getStoreObject(optionName, modelObject) { var setters = this._compileSettersByOption(optionName); return Object.keys(setters).reduce((previous, key) => { if ("key" !== key) { setters[key](previous, modelObject[key]) } return previous }, {}) } _prepareSetterMapHandler(setters) { return data => Object.keys(setters).reduce((previous, key) => { var resultKey = "key" === key ? "id" : key; setters[key](previous, data[resultKey]); return previous }, {}) } _prepareMapHandler(getters) { return data => Object.keys(getters).reduce((previous, key) => { var resultKey = "key" === key ? "id" : key; previous[resultKey] = getters[key](data); return previous }, {}) } _dataSourceChanged(dataSourceName, data) { var getters = this._compileGettersByOption(dataSourceName); var mappedData = data.map(this._prepareMapHandler(getters)); this["_".concat(dataSourceName)] = mappedData; this._setGanttViewOption(dataSourceName, mappedData); if (dataSourceName === GANTT_TASKS) { this._tasksRaw = data; var expandedRowKeys = data.map(t => t[this.option("tasks.parentIdExpr")]).filter((value, index, self) => value && self.indexOf(value) === index); this._setTreeListOption("expandedRowKeys", expandedRowKeys); this._setTreeListOption("dataSource", data) } } _createModelChangesListener() { return { NotifyTaskCreated: (task, callback, errorCallback) => { this._onRecordInserted(GANTT_TASKS, task, callback) }, NotifyTaskRemoved: (taskId, errorCallback, task) => { this._onRecordRemoved(GANTT_TASKS, taskId, task) }, NotifyTaskTitleChanged: (taskId, newValue, errorCallback) => { this._onRecordUpdated(GANTT_TASKS, taskId, "title", newValue) }, NotifyTaskDescriptionChanged: (taskId, newValue, errorCallback) => { this._onRecordUpdated(GANTT_TASKS, taskId, "description", newValue) }, NotifyTaskStartChanged: (taskId, newValue, errorCallback) => { this._onRecordUpdated(GANTT_TASKS, taskId, "start", newValue) }, NotifyTaskEndChanged: (taskId, newValue, errorCallback) => { this._onRecordUpdated(GANTT_TASKS, taskId, "end", newValue) }, NotifyTaskProgressChanged: (taskId, newValue, errorCallback) => { this._onRecordUpdated(GANTT_TASKS, taskId, "progress", newValue) }, NotifyTaskColorChanged: (taskId, newValue, errorCallback) => { this._onRecordUpdated(GANTT_TASKS, taskId, "color", newValue) }, NotifyParentTaskUpdated: (task, errorCallback) => { this._onParentTaskUpdated(task) }, NotifyDependencyInserted: (dependency, callback, errorCallback) => { this._onRecordInserted(GANTT_DEPENDENCIES, dependency, callback) }, NotifyDependencyRemoved: (dependencyId, errorCallback, dependency) => { this._onRecordRemoved(GANTT_DEPENDENCIES, dependencyId, dependency) }, NotifyResourceCreated: (resource, callback, errorCallback) => { this._onRecordInserted(GANTT_RESOURCES, resource, callback) }, NotifyResourceRemoved: (resourceId, errorCallback, resource) => { this._onRecordRemoved(GANTT_RESOURCES, resourceId, resource) }, NotifyResourceAssigned: (assignment, callback, errorCallback) => { this._onRecordInserted(GANTT_RESOURCE_ASSIGNMENTS, assignment, callback) }, NotifyResourceUnassigned: (assignmentId, errorCallback, assignment) => { this._onRecordRemoved(GANTT_RESOURCE_ASSIGNMENTS, assignmentId, assignment) }, NotifyParentDataRecalculated: data => { this._onParentTasksRecalculated(data) }, NotifyTaskCreating: args => { this._raiseInsertingAction(GANTT_TASKS, args) }, NotifyTaskRemoving: args => { this._raiseDeletingAction(GANTT_TASKS, args) }, NotifyTaskUpdating: args => { this._raiseUpdatingAction(GANTT_TASKS, args) }, NotifyTaskMoving: args => { this._raiseUpdatingAction(GANTT_TASKS, args, this._getTaskMovingAction()) }, NotifyTaskEditDialogShowing: args => { this._raiseTaskEditDialogShowingAction(args) }, NotifyResourceManagerDialogShowing: args => { this._raiseResourceManagerDialogShowingAction(args) }, NotifyDependencyInserting: args => { this._raiseInsertingAction(GANTT_DEPENDENCIES, args) }, NotifyDependencyRemoving: args => { this._raiseDeletingAction(GANTT_DEPENDENCIES, args) }, NotifyResourceCreating: args => { this._raiseInsertingAction(GANTT_RESOURCES, args) }, NotifyResourceRemoving: args => { this._raiseDeletingAction(GANTT_RESOURCES, args) }, NotifyResourceAssigning: args => { this._raiseInsertingAction(GANTT_RESOURCE_ASSIGNMENTS, args) }, NotifyResourceUnassigning: args => { this._raiseDeletingAction(GANTT_RESOURCE_ASSIGNMENTS, args) } } } _onRecordInserted(optionName, record, callback) { var dataOption = this["_".concat(optionName, "Option")]; if (dataOption) { var data = this._getStoreObject(optionName, record); if (optionName === GANTT_TASKS) { this._addCustomFieldsDataFromCache(GANTT_NEW_TASK_CACHE_KEY, data) } dataOption.insert(data, response => { var keyGetter = compileGetter(this.option("".concat(optionName, ".keyExpr"))); var insertedId = keyGetter(response); callback(insertedId); if (optionName === GANTT_TASKS) { this._updateTreeListDataSource(); var parentId = record.parentId; if (void 0 !== parentId) { var expandedRowKeys = this._treeList.option("expandedRowKeys"); if (-1 === expandedRowKeys.indexOf(parentId)) { expandedRowKeys.push(parentId); this._treeList.option("expandedRowKeys", expandedRowKeys) } } this._selectTreeListRows(this._getArrayFromOneElement(insertedId)); this._setTreeListOption("focusedRowKey", insertedId); setTimeout(() => { this._updateGanttRowHeights() }, 300) } dataOption._reloadDataSource(); this._raiseInsertedAction(optionName, data, insertedId) }) } } _onRecordRemoved(optionName, key, data) { var dataOption = this["_".concat(optionName, "Option")]; if (dataOption) { dataOption.remove(key, () => { if (optionName === GANTT_TASKS) { this._updateTreeListDataSource() } dataOption._reloadDataSource(); this._raiseDeletedAction(optionName, key, this._convertCoreToMappedData(optionName, data)) }) } } _onRecordUpdated(optionName, key, fieldName, value) { var dataOption = this["_".concat(optionName, "Option")]; var isTaskUpdated = optionName === GANTT_TASKS; if (dataOption) { var setter = compileSetter(this.option("".concat(optionName, ".").concat(fieldName, "Expr"))); var data = {}; setter(data, value); var hasCustomFieldsData = isTaskUpdated && this._cache.hasData(key); if (hasCustomFieldsData) { this._addCustomFieldsDataFromCache(key, data) } dataOption.update(key, data, () => { if (isTaskUpdated) { this._updateTreeListDataSource() } dataOption._reloadDataSource(); this._raiseUpdatedAction(optionName, data, key) }) } } _onParentTaskUpdated(data) { var mappedData = this.getTaskDataByCoreData(data); this._raiseUpdatedAction(GANTT_TASKS, mappedData, data.id) } _onParentTasksRecalculated(data) { var setters = this._compileSettersByOption(GANTT_TASKS); var treeDataSource = this._appendCustomFields(data.map(this._prepareSetterMapHandler(setters))); this._setTreeListOption("dataSource", treeDataSource) } _appendCustomFields(data) { var modelData = this._tasksOption && this._tasksOption._getItems(); var keyGetter = this._getTaskKeyGetter(); var invertedData = this.getInvertedData(modelData, keyGetter); return data.reduce((previous, item) => { var key = keyGetter(item); var modelItem = invertedData[key]; if (!modelItem) { previous.push(item) } else { var updatedItem = {}; for (var field in modelItem) { updatedItem[field] = Object.prototype.hasOwnProperty.call(item, field) ? item[field] : modelItem[field] } previous.push(updatedItem) } return previous }, []) } _getTaskKeyGetter() { return compileGetter(this.option("".concat(GANTT_TASKS, ".keyExpr"))) } getInvertedData(data, keyGetter) { var inverted = {}; if (data) { for (var i = 0; i < data.length; i++) { var dataItem = data[i]; var key = keyGetter(dataItem); inverted[key] = dataItem } } return inverted } _updateTreeListDataSource() { var forceUpdate = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : false; if (!this._skipUpdateTreeListDataSource()) { var dataSource = this.option("tasks.dataSource"); var storeArray = this._tasksOption._getStore()._array || dataSource.items && dataSource.items(); this._setTreeListOption("dataSource", storeArray ? storeArray : dataSource) } else if (forceUpdate) { var data = this._treeList.option("dataSource"); this._onParentTasksRecalculated(data) } } _skipUpdateTreeListDataSource() { return this.option("validation.autoUpdateParentTasks") } _selectTreeListRows(keys) { this._setTreeListOption("selectedRowKeys", keys) } _addCustomFieldsDataFromCache(key, data) { this._cache.pullDataFromCache(key, data) } _saveCustomFieldsDataToCache(key, data) { var forceUpdateOnKeyExpire = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : false; var isCustomFieldsUpdateOnly = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : false; var customFieldsData = this._getCustomFieldsData(data); if (Object.keys(customFieldsData).length > 0) { this._cache.saveData(key, customFieldsData, forceUpdateOnKeyExpire ? (key, data) => { var dataOption = this["_".concat(GANTT_TASKS, "Option")]; if (dataOption && data) { dataOption.update(key, data, (data, key) => { var updatedCustomFields = {}; this._addCustomFieldsData(key, updatedCustomFields); this._updateTreeListDataSource(isCustomFieldsUpdateOnly); dataOption._reloadDataSource(); var selectedRowKey = this.option("selectedRowKey"); this._ganttView._selectTask(selectedRowKey); this._raiseUpdatedAction(GANTT_TASKS, updatedCustomFields, key) }) } } : null) } } _getLoadPanel() { if (!this._loadPanel) { this._loadPanel = this._createComponent(this._$loadPanel, LoadPanel, { position: { of: this.$element() } }) } return this._loadPanel } _createSelectionChangedAction() { this._selectionChangedAction = this._createActionByOption("onSelectionChanged") } _createTaskClickAction() { this._taskClickAction = this._createActionByOption("onTaskClick") } _createTaskDblClickAction() { this._taskDblClickAction = this._createActionByOption("onTaskDblClick") } _createCustomCommandAction() { this._customCommandAction = this._createActionByOption("onCustomCommand") } _createContextMenuPreparingAction() { this._contextMenuPreparingAction = this._createActionByOption("onContextMenuPreparing") } _raiseSelectionChangedAction(selectedRowKey) { if (!this._selectionChangedAction) { this._createSelectionChangedAction() } this._selectionChangedAction({ selectedRowKey: selectedRowKey }) } _raiseCustomCommand(commandName) { if (!this._customCommandAction) { this._createCustomCommandAction() } this._customCommandAction({ name: commandName }) } _raiseContextMenuPreparing(options) { if (!this._contextMenuPreparingAction) { this._createContextMenuPreparingAction() } this._contextMenuPreparingAction(options) } _raiseInsertingAction(optionName, coreArgs) { var action = this._getInsertingAction(optionName); if (action) { var args = { cancel: false, values: this._convertCoreToMappedData(optionName, coreArgs.values) }; action(args); coreArgs.cancel = args.cancel; coreArgs.values = this._convertMappedToCoreData(optionName, args.values); if (optionName === GANTT_TASKS) { this._saveCustomFieldsDataToCache(GANTT_NEW_TASK_CACHE_KEY, args.values) } } } _raiseInsertedAction(optionName, data, key) { var action = this._getInsertedAction(optionName); if (action) { var args = { values: data, key: key }; action(args) } } _raiseDeletingAction(optionName, coreArgs) { var action = this._getDeletingAction(optionName); if (action) { var args = { cancel: false, key: coreArgs.key, values: this._convertCoreToMappedData(optionName, coreArgs.values) }; action(args); coreArgs.cancel = args.cancel } } _raiseDeletedAction(optionName, key, data) { var action = this._getDeletedAction(optionName); if (action) { var args = { key: key, values: data }; action(args) } } _raiseUpdatingAction(optionName, coreArgs, action) { action = action || this._getUpdatingAction(optionName); if (action) { var args = { cancel: false, key: coreArgs.key, newValues: this._convertCoreToMappedData(optionName, coreArgs.newValues), values: this._convertCoreToMappedData(optionName, coreArgs.values) }; action(args); coreArgs.cancel = args.cancel; coreArgs.newValues = this._convertMappedToCoreData(optionName, args.newValues); if (optionName === GANTT_TASKS) { var forceUpdateOnKeyExpire = !Object.keys(coreArgs.newValues).length; this._saveCustomFieldsDataToCache(args.key, args.newValues, forceUpdateOnKeyExpire) } } } _raiseUpdatedAction(optionName, data, key) { var action = this._getUpdatedAction(optionName); if (action) { var args = { values: data, key: key }; action(args) } } _raiseTaskEditDialogShowingAction(coreArgs) { var action = this._getTaskEditDialogShowingAction(); if (action) { var args = { cancel: false, key: coreArgs.key, values: this._convertCoreToMappedData(GANTT_TASKS, coreArgs.values), readOnlyFields: this._convertCoreToMappedFields(GANTT_TASKS, coreArgs.readOnlyFields), hiddenFields: this._convertCoreToMappedFields(GANTT_TASKS, coreArgs.hiddenFields) }; action(args); coreArgs.cancel = args.cancel; coreArgs.values = this._convertMappedToCoreData(GANTT_TASKS, args.values); coreArgs.readOnlyFields = this._convertMappedToCoreFields(GANTT_TASKS, args.readOnlyFields); coreArgs.hiddenFields = this._convertMappedToCoreFields(GANTT_TASKS, args.hiddenFields) } } _raiseResourceManagerDialogShowingAction(coreArgs) { var action = this._getResourceManagerDialogShowingAction(); if (action) { var mappedResources = coreArgs.values.resources.items.map(r => this._convertMappedToCoreData(GANTT_RESOURCES, r)); var args = { cancel: false, values: mappedResources }; action(args); coreArgs.cancel = args.cancel } } _raiseTaskClickAction(key, event) { if (!this._taskClickAction) { this._createTaskClickAction() } var args = { key: key, event: event, data: this.getTaskData(key) }; this._taskClickAction(args) } _raiseTaskDblClickAction(key, event) { if (!this._taskDblClickAction) { this._createTaskDblClickAction() } var args = { cancel: false, data: this.getTaskData(key), event: event, key: key }; this._taskDblClickAction(args); return !args.cancel } _getInsertingAction(optionName) { switch (optionName) { case GANTT_TASKS: return this._getTaskInsertingAction(); case GANTT_DEPENDENCIES: return this._getDependencyInsertingAction(); case GANTT_RESOURCES: return this._getResourceInsertingAction(); case GANTT_RESOURCE_ASSIGNMENTS: return this._getResourceAssigningAction() } return () => {} } _getInsertedAction(optionName) { switch (optionName) { case GANTT_TASKS: return this._getTaskInsertedAction(); case GANTT_DEPENDENCIES: return this._getDependencyInsertedAction(); case GANTT_RESOURCES: return this._getResourceInsertedAction(); case GANTT_RESOURCE_ASSIGNMENTS: return this._getResourceAssignedAction() } return () => {} } _getDeletingAction(optionName) { switch (optionName) { case GANTT_TASKS: return this._getTaskDeletingAction(); case GANTT_DEPENDENCIES: return this._getDependencyDeletingAction(); case GANTT_RESOURCES: return this._getResourceDeletingAction(); case GANTT_RESOURCE_ASSIGNMENTS: return this._getResourceUnassigningAction() } return () => {} } _getDeletedAction(optionName) { switch (optionName) { case GANTT_TASKS: return this._getTaskDeletedAction(); case GANTT_DEPENDENCIES: return this._getDependencyDeletedAction(); case GANTT_RESOURCES: return this._getResourceDeletedAction(); case GANTT_RESOURCE_ASSIGNMENTS: return this._getResourceUnassignedAction() } return () => {} } _getUpdatingAction(optionName) { switch (optionName) { case GANTT_TASKS: return this._getTaskUpdatingAction() } return () => {} } _getUpdatedAction(optionName) { switch (optionName) { case GANTT_TASKS: return this._getTaskUpdatedAction() } return () => {} } _getTaskInsertingAction() { if (!this._taskInsertingAction) { this._createTaskInsertingAction() } return this._taskInsertingAction } _getTaskInsertedAction() { if (!this._taskInsertedAction) { this._createTaskInsertedAction() } return this._taskInsertedAction } _getTaskDeletingAction() { if (!this._taskDeletingAction) { this._createTaskDeletingAction() } return this._taskDeletingAction } _getTaskDeletedAction() { if (!this._taskDeletedAction) { this._createTaskDeletedAction() } return this._taskDeletedAction } _getTaskUpdatingAction() { if (!this._taskUpdatingAction) { this._createTaskUpdatingAction() } return this._taskUpdatingAction } _getTaskUpdatedAction() { if (!this._taskUpdatedAction) { this._createTaskUpdatedAction() } return this._taskUpdatedAction } _getTaskMovingAction() { if (!this._taskMovingAction) { this._createTaskMovingAction() } return this._taskMovingAction } _getTaskEditDialogShowingAction() { if (!this._taskEditDialogShowingAction) { this._createTaskEditDialogShowingAction() } return this._taskEditDialogShowingAction } _getResourceManagerDialogShowingAction() { if (!this._resourceManagerDialogShowingAction) { this._createResourceManagerDialogShowingAction() } return this._resourceManagerDialogShowingAction } _getDependencyInsertingAction() { if (!this._dependencyInsertingAction) { this._createDependencyInsertingAction() } return this._dependencyInsertingAction } _getDependencyInsertedAction() { if (!this._dependencyInsertedAction) { this._createDependencyInsertedAction() } return this._dependencyInsertedAction } _getDependencyDeletingAction() { if (!this._dependencyDeletingAction) { this._createDependencyDeletingAction() } return this._dependencyDeletingAction } _getDependencyDeletedAction() { if (!this._dependencyDeletedAction) { this._createDependencyDeletedAction() } return this._dependencyDeletedAction } _getResourceInsertingAction() { if (!this._resourceInsertingAction) { this._createResourceInsertingAction() } return this._resourceInsertingAction } _getResourceInsertedAction() { if (!this._resourceInsertedAction) { this._createResourceInsertedAction() } return this._resourceInsertedAction } _getResourceDeletingAction() { if (!this._resourceDeletingAction) { this._createResourceDeletingAction() } return this._resourceDeletingAction } _getResourceDeletedAction() { if (!this._resourceDeletedAction) { this._createResourceDeletedAction() } return this._resourceDeletedAction } _getResourceAssigningAction() { if (!this._resourceAssigningAction) { this._createResourceAssigningAction() } return this._resourceAssigningAction } _getResourceAssignedAction() { if (!this._resourceAssignedAction) { this._createResourceAssignedAction() } return this._resourceAssignedAction } _getResourceUnassigningAction() { if (!this._resourceUnassigningAction) { this._createResourceUnassigningAction() } return this._resourceUnassigningAction } _getResourceUnassignedAction() { if (!this._resourceUnassignedAction) { this._createResourceUnassignedAction() } return this._resourceUnassignedAction } _createResourceUnassigningAction() { this._resourceUnassigningAction = this._createActionByOption("onResourceUnassigning") } _createResourceUnassignedAction() { this._resourceUnassignedAction = this._createActionByOption("onResourceUnassigned") } _createTaskInsertingAction() { this._taskInsertingAction = this._createActionByOption("onTaskInserting") } _createTaskInsertedAction() { this._taskInsertedAction = this._createActionByOption("onTaskInserted") } _createTaskDeletingAction() { this._taskDeletingAction = this._createActionByOption("onTaskDeleting") } _createTaskDeletedAction() { this._taskDeletedAction = this._createActionByOption("onTaskDeleted") } _createTaskUpdatingAction() { this._taskUpdatingAction = this._createActionByOption("onTaskUpdating") } _createTaskUpdatedAction() { this._taskUpdatedAction = this._createActionByOption("onTaskUpdated") } _createTaskMovingAction() { this._taskMovingAction = this._createActionByOption("onTaskMoving") } _createTaskEditDialogShowingAction() { this._taskEditDialogShowingAction = this._createActionByOption("onTaskEditDialogShowing") } _createResourceManagerDialogShowingAction() { this._resourceManagerDialogShowingAction = this._createActionByOption("onResourceManagerDialogShowing") } _createDependencyInsertingAction() { this._dependencyInsertingAction = this._createActionByOption("onDependencyInserting") } _createDependencyInsertedAction() { this._dependencyInsertedAction = this._createActionByOption("onDependencyInserted") } _createDependencyDeletingAction() { this._dependencyDeletingAction = this._createActionByOption("onDependencyDeleting") } _createDependencyDeletedAction() { this._dependencyDeletedAction = this._createActionByOption("onDependencyDeleted") } _createResourceInsertingAction() { this._resourceInsertingAction = this._createActionByOption("onResourceInserting") } _createResourceInsertedAction() { this._resourceInsertedAction = this._createActionByOption("onResourceInserted") } _createResourceDeletingAction() { this._resourceDeletingAction = this._createActionByOption("onResourceDeleting") } _createResourceDeletedAction() { this._resourceDeletedAction = this._createActionByOption("onResourceDeleted") } _createResourceAssigningAction() { this._resourceAssigningAction = this._createActionByOption("onResourceAssigning") } _createResourceAssignedAction() { this._resourceAssignedAction = this._createActionByOption("onResourceAssigned") } _convertCoreToMappedData(optionName, coreData) { return Object.keys(coreData).reduce((previous, f) => { var mappedField = this._getMappedFieldName(optionName, f); if (mappedField) { var setter = compileSetter(mappedField); setter(previous, coreData[f]) } return previous }, {}) } _convertMappedToCoreData(optionName, mappedData) { var coreData = {}; if (mappedData) { var mappedFields = this.option(optionName); for (var field in mappedFields) { var exprMatches = field.match(GANTT_MAPPED_FIELD_REGEX); var mappedFieldName = exprMatches && mappedFields[exprMatches[0]]; if (mappedFieldName && void 0 !== mappedData[mappedFieldName]) { var getter = compileGetter(mappedFieldName); var coreFieldName = exprMatches[1]; coreData[coreFieldName] = getter(mappedData) } } } return coreData } _getMappedFieldName(optionName, coreField) { var coreFieldName = coreField; if ("id" === coreField) { coreFieldName = "key" } return this.option("".concat(optionName, ".").concat(coreFieldName, "Expr")) } _convertCoreToMappedFields(optionName, fields) { return fields.reduce((previous, f) => { var mappedField = this._getMappedFieldName(optionName, f); if (mappedField) { previous.push(mappedField) } return previous }, []) } _convertMappedToCoreFields(optionName, fields) { var coreFields = []; var mappedFields = this.option(optionName); for (var field in mappedFields) { var exprMatches = field.match(GANTT_MAPPED_FIELD_REGEX); var mappedFieldName = exprMatches && mappedFields[exprMatches[0]]; if (mappedFieldName && fields.indexOf(mappedFieldName) > -1) { var coreFieldName = exprMatches[1]; coreFields.push(coreFieldName) } } return coreFields } _getTaskMappedFieldNames() { var mappedFields = []; var mappedFieldsData = this.option(GANTT_TASKS); for (var field in mappedFieldsData) { var exprMatches = field.match(GANTT_MAP