ajax.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /**
  2. * DevExtreme (ui/file_manager/file_provider/ajax.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. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
  13. return typeof obj
  14. } : function(obj) {
  15. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
  16. }, _typeof(obj)
  17. }
  18. var _ajax = require("../../../core/utils/ajax");
  19. var _ajax2 = _interopRequireDefault(_ajax);
  20. var _common = require("../../../core/utils/common");
  21. var _deferred = require("../../../core/utils/deferred");
  22. var _extend = require("../../../core/utils/extend");
  23. var _file_provider = require("./file_provider");
  24. var _array = require("./array");
  25. var _array2 = _interopRequireDefault(_array);
  26. function _interopRequireDefault(obj) {
  27. return obj && obj.__esModule ? obj : {
  28. "default": obj
  29. }
  30. }
  31. function _classCallCheck(instance, Constructor) {
  32. if (!(instance instanceof Constructor)) {
  33. throw new TypeError("Cannot call a class as a function")
  34. }
  35. }
  36. function _defineProperties(target, props) {
  37. for (var i = 0; i < props.length; i++) {
  38. var descriptor = props[i];
  39. descriptor.enumerable = descriptor.enumerable || false;
  40. descriptor.configurable = true;
  41. if ("value" in descriptor) {
  42. descriptor.writable = true
  43. }
  44. Object.defineProperty(target, descriptor.key, descriptor)
  45. }
  46. }
  47. function _createClass(Constructor, protoProps, staticProps) {
  48. if (protoProps) {
  49. _defineProperties(Constructor.prototype, protoProps)
  50. }
  51. if (staticProps) {
  52. _defineProperties(Constructor, staticProps)
  53. }
  54. Object.defineProperty(Constructor, "prototype", {
  55. writable: false
  56. });
  57. return Constructor
  58. }
  59. function _inherits(subClass, superClass) {
  60. if ("function" !== typeof superClass && null !== superClass) {
  61. throw new TypeError("Super expression must either be null or a function")
  62. }
  63. subClass.prototype = Object.create(superClass && superClass.prototype, {
  64. constructor: {
  65. value: subClass,
  66. writable: true,
  67. configurable: true
  68. }
  69. });
  70. Object.defineProperty(subClass, "prototype", {
  71. writable: false
  72. });
  73. if (superClass) {
  74. _setPrototypeOf(subClass, superClass)
  75. }
  76. }
  77. function _setPrototypeOf(o, p) {
  78. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  79. o.__proto__ = p;
  80. return o
  81. };
  82. return _setPrototypeOf(o, p)
  83. }
  84. function _createSuper(Derived) {
  85. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  86. return function() {
  87. var result, Super = _getPrototypeOf(Derived);
  88. if (hasNativeReflectConstruct) {
  89. var NewTarget = _getPrototypeOf(this).constructor;
  90. result = Reflect.construct(Super, arguments, NewTarget)
  91. } else {
  92. result = Super.apply(this, arguments)
  93. }
  94. return _possibleConstructorReturn(this, result)
  95. }
  96. }
  97. function _possibleConstructorReturn(self, call) {
  98. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  99. return call
  100. } else {
  101. if (void 0 !== call) {
  102. throw new TypeError("Derived constructors may only return object or undefined")
  103. }
  104. }
  105. return _assertThisInitialized(self)
  106. }
  107. function _assertThisInitialized(self) {
  108. if (void 0 === self) {
  109. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  110. }
  111. return self
  112. }
  113. function _isNativeReflectConstruct() {
  114. if ("undefined" === typeof Reflect || !Reflect.construct) {
  115. return false
  116. }
  117. if (Reflect.construct.sham) {
  118. return false
  119. }
  120. if ("function" === typeof Proxy) {
  121. return true
  122. }
  123. try {
  124. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  125. return true
  126. } catch (e) {
  127. return false
  128. }
  129. }
  130. function _getPrototypeOf(o) {
  131. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  132. return o.__proto__ || Object.getPrototypeOf(o)
  133. };
  134. return _getPrototypeOf(o)
  135. }
  136. var AjaxFileProvider = function(_FileProvider) {
  137. _inherits(AjaxFileProvider, _FileProvider);
  138. var _super = _createSuper(AjaxFileProvider);
  139. function AjaxFileProvider(options) {
  140. var _this;
  141. _classCallCheck(this, AjaxFileProvider);
  142. options = (0, _common.ensureDefined)(options, {});
  143. _this = _super.call(this, options);
  144. _this._options = options;
  145. _this._provider = null;
  146. return _this
  147. }
  148. _createClass(AjaxFileProvider, [{
  149. key: "getItems",
  150. value: function(path, itemType) {
  151. var _this2 = this;
  152. return this._doActionAfterDataAcquired(function() {
  153. return _this2._provider.getItems(path, itemType)
  154. })
  155. }
  156. }, {
  157. key: "renameItem",
  158. value: function(item, name) {
  159. var _this3 = this;
  160. return this._doActionAfterDataAcquired(function() {
  161. return _this3._provider.renameItem(item, name)
  162. })
  163. }
  164. }, {
  165. key: "createFolder",
  166. value: function(parentFolder, name) {
  167. var _this4 = this;
  168. return this._doActionAfterDataAcquired(function() {
  169. return _this4._provider.createFolder(parentFolder, name)
  170. })
  171. }
  172. }, {
  173. key: "deleteItems",
  174. value: function(items) {
  175. var _this5 = this;
  176. return this._doActionAfterDataAcquired(function() {
  177. return _this5._provider.deleteItems(items)
  178. })
  179. }
  180. }, {
  181. key: "moveItems",
  182. value: function(items, destinationFolder) {
  183. var _this6 = this;
  184. return this._doActionAfterDataAcquired(function() {
  185. return _this6._provider.moveItems(items, destinationFolder)
  186. })
  187. }
  188. }, {
  189. key: "copyItems",
  190. value: function(items, destinationFolder) {
  191. var _this7 = this;
  192. return this._doActionAfterDataAcquired(function() {
  193. return _this7._provider.copyItems(items, destinationFolder)
  194. })
  195. }
  196. }, {
  197. key: "initiateFileUpload",
  198. value: function(uploadInfo) {
  199. var _this8 = this;
  200. return this._doActionAfterDataAcquired(function() {
  201. return _this8._provider.initiateFileUpload(uploadInfo)
  202. })
  203. }
  204. }, {
  205. key: "uploadFileChunk",
  206. value: function(uploadInfo, chunk) {
  207. var _this9 = this;
  208. return this._doActionAfterDataAcquired(function() {
  209. return _this9._provider.uploadFileChunk(uploadInfo, chunk)
  210. })
  211. }
  212. }, {
  213. key: "finalizeFileUpload",
  214. value: function(uploadInfo) {
  215. var _this10 = this;
  216. return this._doActionAfterDataAcquired(function() {
  217. return _this10._provider.finalizeFileUpload(uploadInfo)
  218. })
  219. }
  220. }, {
  221. key: "abortFileUpload",
  222. value: function(uploadInfo) {
  223. var _this11 = this;
  224. return this._doActionAfterDataAcquired(function() {
  225. return _this11._provider.abortFileUpload(uploadInfo)
  226. })
  227. }
  228. }, {
  229. key: "_doActionAfterDataAcquired",
  230. value: function(action) {
  231. return this._ensureDataAcquired().then(action.bind(this))
  232. }
  233. }, {
  234. key: "_ensureDataAcquired",
  235. value: function() {
  236. var _this12 = this;
  237. if (this._provider) {
  238. return (new _deferred.Deferred).resolve().promise()
  239. }
  240. return this._getData().done(function(data) {
  241. var arrayOptions = (0, _extend.extend)(_this12._options, {
  242. data: data
  243. });
  244. _this12._provider = new _array2.default(arrayOptions)
  245. })
  246. }
  247. }, {
  248. key: "_getData",
  249. value: function() {
  250. return _ajax2.default.sendRequest({
  251. url: this._options.url,
  252. dataType: "json",
  253. cache: false
  254. })
  255. }
  256. }]);
  257. return AjaxFileProvider
  258. }(_file_provider.FileProvider);
  259. module.exports = AjaxFileProvider;