UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

303 lines (302 loc) • 15.1 kB
/** * DevExtreme (esm/__internal/ui/file_manager/ui.file_manager.notification.progress_panel.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import messageLocalization from "../../../common/core/localization/message"; import $ from "../../../core/renderer"; import { ensureDefined } from "../../../core/utils/common"; import { getImageContainer } from "../../../core/utils/icon"; import Button from "../../../ui/button"; import ProgressBar from "../../../ui/progress_bar"; import ScrollView from "../../../ui/scroll_view"; import Widget from "../../core/widget/widget"; const FILE_MANAGER_PROGRESS_PANEL_CLASS = "dx-filemanager-progress-panel"; const FILE_MANAGER_PROGRESS_PANEL_CONTAINER_CLASS = "dx-filemanager-progress-panel-container"; const FILE_MANAGER_PROGRESS_PANEL_TITLE_CLASS = "dx-filemanager-progress-panel-title"; const FILE_MANAGER_PROGRESS_PANEL_TITLE_TEXT_CLASS = "dx-filemanager-progress-panel-title-text"; const FILE_MANAGER_PROGRESS_PANEL_CLOSE_BUTTON_CLASS = "dx-filemanager-progress-panel-close-button"; const FILE_MANAGER_PROGRESS_PANEL_INFOS_CONTAINER_CLASS = "dx-filemanager-progress-panel-infos-container"; const FILE_MANAGER_PROGRESS_PANEL_SEPARATOR_CLASS = "dx-filemanager-progress-panel-separator"; const FILE_MANAGER_PROGRESS_PANEL_INFO_CLASS = "dx-filemanager-progress-panel-info"; const FILE_MANAGER_PROGRESS_PANEL_COMMON_CLASS = "dx-filemanager-progress-panel-common"; const FILE_MANAGER_PROGRESS_PANEL_INFO_WITH_DETAILS_CLASS = "dx-filemanager-progress-panel-info-with-details"; const FILE_MANAGER_PROGRESS_PANEL_DETAILS_CLASS = "dx-filemanager-progress-panel-details"; const FILE_MANAGER_PROGRESS_BOX_CLASS = "dx-filemanager-progress-box"; const FILE_MANAGER_PROGRESS_BOX_ERROR_CLASS = "dx-filemanager-progress-box-error"; const FILE_MANAGER_PROGRESS_BOX_WITHOUT_CLOSE_BUTTON_CLASS = "dx-filemanager-progress-box-without-close-button"; const FILE_MANAGER_PROGRESS_BOX_IMAGE_CLASS = "dx-filemanager-progress-box-image"; const FILE_MANAGER_PROGRESS_BOX_WRAPPER_CLASS = "dx-filemanager-progress-box-wrapper"; const FILE_MANAGER_PROGRESS_BOX_COMMON_CLASS = "dx-filemanager-progress-box-common"; const FILE_MANAGER_PROGRESS_BOX_PROGRESS_BAR_CLASS = "dx-filemanager-progress-box-progress-bar"; const FILE_MANAGER_PROGRESS_BOX_CLOSE_BUTTON_CLASS = "dx-filemanager-progress-box-close-button"; const DX_CARD_CLASS = "dx-card"; class FileManagerProgressPanel extends Widget { _initMarkup() { super._initMarkup(); this._initActions(); this._operationCount = 0; this.$element().addClass("dx-filemanager-progress-panel"); const $scrollView = $("<div>").appendTo(this.$element()); const $container = $("<div>").addClass("dx-filemanager-progress-panel-container").appendTo($scrollView); this._scrollView = this._createComponent($scrollView, ScrollView, { scrollByContent: true, scrollByThumb: true, showScrollbar: "onScroll" }); const $title = $("<div>").addClass("dx-filemanager-progress-panel-title").appendTo($container); $("<div>").text(messageLocalization.format("dxFileManager-notificationProgressPanelTitle")).addClass("dx-filemanager-progress-panel-title-text").appendTo($title); const $closeButton = $("<div>").addClass("dx-filemanager-progress-panel-close-button").appendTo($title); this._createComponent($closeButton, Button, { icon: "close", stylingMode: "text", onClick: () => this._raisePanelClosed() }); this._$infosContainer = $("<div>").addClass("dx-filemanager-progress-panel-infos-container").appendTo($container); this._renderEmptyListText() } _getDefaultOptions() { return Object.assign({}, super._getDefaultOptions(), { onOperationClosed: void 0, onOperationCanceled: void 0, onOperationItemCanceled: void 0, onPanelClosed: void 0 }) } _initActions() { this._actions = { onOperationClosed: this._createActionByOption("onOperationClosed"), onOperationCanceled: this._createActionByOption("onOperationCanceled"), onOperationItemCanceled: this._createActionByOption("onOperationItemCanceled"), onPanelClosed: this._createActionByOption("onPanelClosed") } } _optionChanged(args) { const { name: name } = args; switch (name) { case "onOperationClosed": case "onOperationCanceled": case "onOperationItemCanceled": this._actions[name] = this._createActionByOption(name); break; default: super._optionChanged(args) } } addOperation(commonText, showCloseButtonAlways, allowProgressAutoUpdate) { if (this._operationCount) { $("<div>").addClass("dx-filemanager-progress-panel-separator").prependTo(this._$infosContainer) } else { var _this$_$infosContaine; null === (_this$_$infosContaine = this._$infosContainer) || void 0 === _this$_$infosContaine || _this$_$infosContaine.empty() } this._operationCount += 1; const info = { customCloseHandling: showCloseButtonAlways, allowProgressAutoUpdate: ensureDefined(allowProgressAutoUpdate, true) }; const $info = $("<div>").addClass("dx-filemanager-progress-panel-info").prependTo(this._$infosContainer); info.$info = $info; const $common = $("<div>").addClass("dx-filemanager-progress-panel-common").appendTo($info); info.common = this._createProgressBox($common, { commonText: commonText, showCloseButton: true, showCloseButtonAlways: showCloseButtonAlways, onCloseButtonClick: () => this._closeOperation(info) }); return info } addOperationDetails(info, details, showCloseButton) { info.$info.addClass("dx-filemanager-progress-panel-info-with-details"); const $details = $("<div>").addClass("dx-filemanager-progress-panel-details").appendTo(info.$info); info.details = details.map((itemInfo, index) => { itemInfo.info = info; return this._createDetailsItem($details, itemInfo, index, false, showCloseButton) }) } _createDetailsItem($container, item, itemIndex, skipProgressBox, showCloseButton) { const $detailsItem = $("<div>").appendTo($container); if (-1 !== itemIndex) { $detailsItem.addClass("dx-card") } return this._createProgressBox($detailsItem, { commonText: item.commonText, imageUrl: item.imageUrl, skipProgressBox: skipProgressBox, showCloseButton: showCloseButton, showCloseButtonAlways: showCloseButton, onCloseButtonClick: () => this._cancelOperationItem(item, itemIndex) }) } completeOperationItem(operationInfo, itemIndex, commonProgress) { if (operationInfo.allowProgressAutoUpdate) { this.updateOperationItemProgress(operationInfo, itemIndex, 100, commonProgress) } this._setCloseButtonVisible(operationInfo.details[itemIndex], false) } updateOperationItemProgress(operationInfo, itemIndex, itemProgress, commonProgress) { this.updateOperationCommonProgress(operationInfo, commonProgress); if (operationInfo.details) { const detailsItem = operationInfo.details[itemIndex]; detailsItem.progressBar.option("value", itemProgress) } } updateOperationCommonProgress(operationInfo, commonProgress) { var _operationInfo$common; null === (_operationInfo$common = operationInfo.common.progressBar) || void 0 === _operationInfo$common || _operationInfo$common.option("value", commonProgress) } completeOperation(info, commonText, isError, statusText) { info.completed = true; info.common.$commonText.text(commonText); if (isError) { this._removeProgressBar(info.common) } else if (info.allowProgressAutoUpdate) { this.updateOperationCommonProgress(info, 100) } if (statusText) { this._setProgressBarText(info.common, statusText) } this._setCloseButtonVisible(info.common, true) } completeSingleOperationWithError(info, errorText) { var _info$details; const detailsItem = null === (_info$details = info.details) || void 0 === _info$details ? void 0 : _info$details[0]; info.completed = true; this._renderOperationError(detailsItem || info.common, errorText); this._setCloseButtonVisible(info.common, true); if (detailsItem) { this._setCloseButtonVisible(detailsItem, false) } } addOperationDetailsError(info, index, errorText) { const detailsItem = info.details[index]; this._renderOperationError(detailsItem, errorText); this._setCloseButtonVisible(detailsItem, false) } _renderError($container, $target, errorText) { $("<div>").text(errorText).addClass("dx-filemanager-progress-box-error").appendTo($container) } _renderEmptyListText() { this._$infosContainer.text(messageLocalization.format("dxFileManager-notificationProgressPanelEmptyListText")) } _renderOperationError(info, errorText) { this._removeProgressBar(info); this._renderError(info.$wrapper, info.$commonText, errorText) } _removeProgressBar(progressBox) { if (progressBox.progressBar) { progressBox.progressBar.dispose(); progressBox.progressBar.$element().remove(); progressBox.progressBar = null } } _createProgressBox($container, options) { $container.addClass("dx-filemanager-progress-box"); if (!options.showCloseButtonAlways) { $container.addClass("dx-filemanager-progress-box-without-close-button") } if (options.imageUrl) { var _getImageContainer; null === (_getImageContainer = getImageContainer(options.imageUrl)) || void 0 === _getImageContainer || _getImageContainer.addClass("dx-filemanager-progress-box-image").appendTo($container) } const $wrapper = $("<div>").addClass("dx-filemanager-progress-box-wrapper").appendTo($container); const $commonText = $("<div>").addClass("dx-filemanager-progress-box-common").text(options.commonText).appendTo($wrapper); let progressBar = null; if (!options.skipProgressBox) { const $progressBar = $("<div>").addClass("dx-filemanager-progress-box-progress-bar").appendTo($wrapper); progressBar = this._createComponent($progressBar, ProgressBar, { min: 0, max: 100, width: "100%", validationMessageMode: "always", statusFormat: (ratio, value) => this._getStatusString(ratio, value) }) } let closeButton = null; if (options.showCloseButton) { const $button = $("<div>").addClass("dx-filemanager-progress-box-close-button").appendTo($container); closeButton = this._createComponent($button, Button, { icon: "dx-filemanager-i dx-filemanager-i-cancel", stylingMode: "text", visible: options.showCloseButtonAlways, onClick: options.onCloseButtonClick }) } return { $commonText: $commonText, progressBar: progressBar, $element: $container, $wrapper: $wrapper, closeButton: closeButton } } _setCloseButtonVisible(progressBox, visible) { if (progressBox.closeButton) { progressBox.$element.toggleClass("dx-filemanager-progress-box-without-close-button", !visible); progressBox.closeButton.option("visible", visible) } } _setProgressBarText(progressBox, text) { progressBox.progressBar.option("statusFormat", () => text) } _closeOperation(info) { if (info.customCloseHandling && !info.completed) { this._raiseOperationCanceled(info); this._setCloseButtonVisible(info.common, false); info.details.forEach(item => this._displayClosedOperationItem(item)) } else { this._raiseOperationClosed(info); info.$info.next(".dx-filemanager-progress-panel-separator").remove(); info.$info.remove(); this._operationCount -= 1; if (!this._operationCount) { this._renderEmptyListText() } } } _cancelOperationItem(item, itemIndex) { this._raiseOperationItemCanceled(item, itemIndex); const itemInfo = item.info.details[itemIndex]; this._displayClosedOperationItem(itemInfo) } _displayClosedOperationItem(itemInfo) { this._setProgressBarText(itemInfo, messageLocalization.format("dxFileManager-notificationProgressPanelOperationCanceled")); this._setCloseButtonVisible(itemInfo, false) } _getStatusString(ratio, _value) { return 1 === ratio ? messageLocalization.format("Done") : `${Math.round(100*ratio)}%` } _raiseOperationClosed(info) { var _this$_actions$onOper, _this$_actions; null === (_this$_actions$onOper = (_this$_actions = this._actions).onOperationClosed) || void 0 === _this$_actions$onOper || _this$_actions$onOper.call(_this$_actions, { info: info }) } _raiseOperationCanceled(info) { var _this$_actions$onOper2, _this$_actions2; null === (_this$_actions$onOper2 = (_this$_actions2 = this._actions).onOperationCanceled) || void 0 === _this$_actions$onOper2 || _this$_actions$onOper2.call(_this$_actions2, { info: info }) } _raiseOperationItemCanceled(item, itemIndex) { var _this$_actions$onOper3, _this$_actions3; null === (_this$_actions$onOper3 = (_this$_actions3 = this._actions).onOperationItemCanceled) || void 0 === _this$_actions$onOper3 || _this$_actions$onOper3.call(_this$_actions3, { item: item, itemIndex: itemIndex }) } _raisePanelClosed() { var _this$_actions$onPane, _this$_actions4; null === (_this$_actions$onPane = (_this$_actions4 = this._actions).onPanelClosed) || void 0 === _this$_actions$onPane || _this$_actions$onPane.call(_this$_actions4) } } export default FileManagerProgressPanel;