UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

159 lines (157 loc) 6.74 kB
/** * DevExtreme (cjs/__internal/ui/file_manager/ui.file_manager.command_manager.js) * Version: 25.2.3 * Build date: Fri Dec 12 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultPermissions = exports.FileManagerCommandManager = void 0; var _message = _interopRequireDefault(require("../../../common/core/localization/message")); var _extend = require("../../../core/utils/extend"); var _iterator = require("../../../core/utils/iterator"); var _type = require("../../../core/utils/type"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const defaultPermissions = exports.defaultPermissions = { create: false, copy: false, move: false, delete: false, rename: false, upload: false, download: false }; class FileManagerCommandManager { constructor(permissions) { this._actions = {}; this._permissions = permissions ?? {}; this._initCommands() } _initCommands() { var _this$_permissions, _this$_permissions2, _this$_permissions3, _this$_permissions4, _this$_permissions5, _this$_permissions6, _this$_permissions7; this._commands = [{ name: "create", text: _message.default.format("dxFileManager-commandCreate"), icon: "newfolder", enabled: null === (_this$_permissions = this._permissions) || void 0 === _this$_permissions ? void 0 : _this$_permissions.create, noFileItemRequired: true }, { name: "rename", text: _message.default.format("dxFileManager-commandRename"), icon: "rename", enabled: null === (_this$_permissions2 = this._permissions) || void 0 === _this$_permissions2 ? void 0 : _this$_permissions2.rename, isSingleFileItemCommand: true }, { name: "move", text: _message.default.format("dxFileManager-commandMove"), icon: "movetofolder", enabled: null === (_this$_permissions3 = this._permissions) || void 0 === _this$_permissions3 ? void 0 : _this$_permissions3.move }, { name: "copy", text: _message.default.format("dxFileManager-commandCopy"), icon: "copy", enabled: null === (_this$_permissions4 = this._permissions) || void 0 === _this$_permissions4 ? void 0 : _this$_permissions4.copy }, { name: "delete", text: _message.default.format("dxFileManager-commandDelete"), icon: "trash", enabled: null === (_this$_permissions5 = this._permissions) || void 0 === _this$_permissions5 ? void 0 : _this$_permissions5.delete }, { name: "download", text: _message.default.format("dxFileManager-commandDownload"), icon: "download", enabled: null === (_this$_permissions6 = this._permissions) || void 0 === _this$_permissions6 ? void 0 : _this$_permissions6.download }, { name: "upload", text: _message.default.format("dxFileManager-commandUpload"), icon: "upload", enabled: null === (_this$_permissions7 = this._permissions) || void 0 === _this$_permissions7 ? void 0 : _this$_permissions7.upload, noFileItemRequired: true }, { name: "refresh", text: _message.default.format("dxFileManager-commandRefresh"), icon: "dx-filemanager-i dx-filemanager-i-refresh", enabled: true, noFileItemRequired: true }, { name: "thumbnails", text: _message.default.format("dxFileManager-commandThumbnails"), icon: "mediumiconslayout", enabled: true, noFileItemRequired: true }, { name: "details", text: _message.default.format("dxFileManager-commandDetails"), icon: "detailslayout", enabled: true, noFileItemRequired: true }, { name: "clearSelection", text: _message.default.format("dxFileManager-commandClearSelection"), icon: "remove", enabled: true }, { name: "showNavPane", hint: _message.default.format("dxFileManager-commandShowNavPane"), icon: "menu", enabled: false, noFileItemRequired: true }]; this._commandMap = {}; this._commands.forEach((command => { this._commandMap[command.name] = command })) } registerActions(actions) { this._actions = (0, _extend.extend)(this._actions, actions) } executeCommand(command, arg) { const commandName = (0, _type.isString)(command) ? command : command.name; const action = this._actions[commandName]; if (action) { return action(arg) } } updatePermissions(permissions) { this._permissions = Object.assign({}, defaultPermissions, permissions); (0, _iterator.each)(this._permissions, (permission => { var _this$_permissions8; this._commandMap[permission].enabled = null === (_this$_permissions8 = this._permissions) || void 0 === _this$_permissions8 ? void 0 : _this$_permissions8[permission] })) } setCommandEnabled(commandName, enabled) { const command = this.getCommandByName(commandName); if (command) { command.enabled = enabled } } getCommandByName(name) { return this._commandMap[name] } isCommandAvailable(commandName, itemInfos) { const command = this.getCommandByName(commandName); if (!(null !== command && void 0 !== command && command.enabled)) { return false } if (command.noFileItemRequired) { return true } const itemsLength = (null === itemInfos || void 0 === itemInfos ? void 0 : itemInfos.length) || 0; if (0 === itemsLength || itemInfos.some((item => item.fileItem.isRoot() || item.fileItem.isParentFolder))) { return false } if ("download" === commandName) { return itemInfos.every((itemInfo => !itemInfo.fileItem.isDirectory)) } return !command.isSingleFileItemCommand || 1 === itemsLength } } exports.FileManagerCommandManager = FileManagerCommandManager;