ui.file_manager.command_manager.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * DevExtreme (ui/file_manager/ui.file_manager.command_manager.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. exports.FileManagerCommandManager = void 0;
  14. var _extend = require("../../core/utils/extend");
  15. var _type = require("../../core/utils/type");
  16. function _classCallCheck(instance, Constructor) {
  17. if (!(instance instanceof Constructor)) {
  18. throw new TypeError("Cannot call a class as a function")
  19. }
  20. }
  21. function _defineProperties(target, props) {
  22. for (var i = 0; i < props.length; i++) {
  23. var descriptor = props[i];
  24. descriptor.enumerable = descriptor.enumerable || false;
  25. descriptor.configurable = true;
  26. if ("value" in descriptor) {
  27. descriptor.writable = true
  28. }
  29. Object.defineProperty(target, descriptor.key, descriptor)
  30. }
  31. }
  32. function _createClass(Constructor, protoProps, staticProps) {
  33. if (protoProps) {
  34. _defineProperties(Constructor.prototype, protoProps)
  35. }
  36. if (staticProps) {
  37. _defineProperties(Constructor, staticProps)
  38. }
  39. Object.defineProperty(Constructor, "prototype", {
  40. writable: false
  41. });
  42. return Constructor
  43. }
  44. var FileManagerCommandManager = exports.FileManagerCommandManager = function() {
  45. function FileManagerCommandManager(permissions) {
  46. _classCallCheck(this, FileManagerCommandManager);
  47. this._actions = {};
  48. this._permissions = permissions || {};
  49. this._initCommands()
  50. }
  51. _createClass(FileManagerCommandManager, [{
  52. key: "_initCommands",
  53. value: function() {
  54. var _this = this;
  55. this._commands = [{
  56. name: "create",
  57. text: "New folder",
  58. icon: "plus",
  59. enabled: this._permissions.create,
  60. noFileItemRequired: true
  61. }, {
  62. name: "rename",
  63. text: "Rename",
  64. enabled: this._permissions.rename,
  65. isSingleFileItemCommand: true
  66. }, {
  67. name: "move",
  68. text: "Move",
  69. enabled: this._permissions.move
  70. }, {
  71. name: "copy",
  72. text: "Copy",
  73. enabled: this._permissions.copy
  74. }, {
  75. name: "delete",
  76. text: "Delete",
  77. icon: "trash",
  78. enabled: this._permissions.remove
  79. }, {
  80. name: "download",
  81. text: "Download",
  82. icon: "download",
  83. enabled: false
  84. }, {
  85. name: "upload",
  86. text: "Upload files",
  87. icon: "upload",
  88. enabled: this._permissions.upload,
  89. noFileItemRequired: true
  90. }, {
  91. name: "refresh",
  92. text: "Refresh",
  93. icon: "refresh",
  94. enabled: true,
  95. noFileItemRequired: true
  96. }, {
  97. name: "thumbnails",
  98. text: "Thumbnails View",
  99. enabled: true,
  100. noFileItemRequired: true
  101. }, {
  102. name: "details",
  103. text: "Details View",
  104. enabled: true,
  105. noFileItemRequired: true
  106. }, {
  107. name: "clear",
  108. text: "Clear selection",
  109. icon: "remove",
  110. enabled: true
  111. }, {
  112. name: "showDirsPanel",
  113. icon: "menu",
  114. enabled: false,
  115. noFileItemRequired: true
  116. }];
  117. this._commandMap = {};
  118. this._commands.forEach(function(command) {
  119. _this._commandMap[command.name] = command
  120. })
  121. }
  122. }, {
  123. key: "registerActions",
  124. value: function(actions) {
  125. this._actions = (0, _extend.extend)(this._actions, actions)
  126. }
  127. }, {
  128. key: "executeCommand",
  129. value: function(command, arg) {
  130. var commandName = (0, _type.isString)(command) ? command : command.name;
  131. var action = this._actions[commandName];
  132. if (action) {
  133. action(arg)
  134. }
  135. }
  136. }, {
  137. key: "setCommandEnabled",
  138. value: function(commandName, enabled) {
  139. var command = this.getCommandByName(commandName);
  140. if (command) {
  141. command.enabled = enabled
  142. }
  143. }
  144. }, {
  145. key: "getCommandByName",
  146. value: function(name) {
  147. return this._commandMap[name]
  148. }
  149. }, {
  150. key: "isCommandAvailable",
  151. value: function(commandName, items) {
  152. var command = this.getCommandByName(commandName);
  153. if (!command || !command.enabled) {
  154. return false
  155. }
  156. if (command.noFileItemRequired) {
  157. return true
  158. }
  159. var itemsLength = items && items.length || 0;
  160. if (0 === itemsLength || items.some(function(item) {
  161. return item.isRoot() || item.isParentFolder
  162. })) {
  163. return false
  164. }
  165. return !command.isSingleFileItemCommand || 1 === itemsLength
  166. }
  167. }]);
  168. return FileManagerCommandManager
  169. }();