load_panel.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * DevExtreme (ui/load_panel.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. var $ = require("../core/renderer");
  11. var noop = require("../core/utils/common").noop;
  12. var messageLocalization = require("../localization/message");
  13. var registerComponent = require("../core/component_registrator");
  14. var extend = require("../core/utils/extend").extend;
  15. var LoadIndicator = require("./load_indicator");
  16. var Overlay = require("./overlay");
  17. var Deferred = require("../core/utils/deferred").Deferred;
  18. var themes = require("./themes");
  19. var LOADPANEL_CLASS = "dx-loadpanel";
  20. var LOADPANEL_WRAPPER_CLASS = "dx-loadpanel-wrapper";
  21. var LOADPANEL_INDICATOR_CLASS = "dx-loadpanel-indicator";
  22. var LOADPANEL_MESSAGE_CLASS = "dx-loadpanel-message";
  23. var LOADPANEL_CONTENT_CLASS = "dx-loadpanel-content";
  24. var LOADPANEL_CONTENT_WRAPPER_CLASS = "dx-loadpanel-content-wrapper";
  25. var LOADPANEL_PANE_HIDDEN_CLASS = "dx-loadpanel-pane-hidden";
  26. var LoadPanel = Overlay.inherit({
  27. _supportedKeys: function() {
  28. return extend(this.callBase(), {
  29. escape: noop
  30. })
  31. },
  32. _getDefaultOptions: function() {
  33. return extend(this.callBase(), {
  34. message: messageLocalization.format("Loading"),
  35. width: 222,
  36. height: 90,
  37. animation: null,
  38. showIndicator: true,
  39. indicatorSrc: "",
  40. showPane: true,
  41. delay: 0,
  42. closeOnBackButton: false,
  43. resizeEnabled: false,
  44. focusStateEnabled: false
  45. })
  46. },
  47. _defaultOptionsRules: function() {
  48. return this.callBase().concat([{
  49. device: {
  50. platform: "generic"
  51. },
  52. options: {
  53. shadingColor: "transparent"
  54. }
  55. }, {
  56. device: function() {
  57. return themes.isMaterial()
  58. },
  59. options: {
  60. message: "",
  61. width: 60,
  62. height: 60,
  63. maxHeight: 60,
  64. maxWidth: 60
  65. }
  66. }])
  67. },
  68. _init: function() {
  69. this.callBase.apply(this, arguments)
  70. },
  71. _initOptions: function() {
  72. this.callBase.apply(this, arguments);
  73. this.option("templatesRenderAsynchronously", false)
  74. },
  75. _render: function() {
  76. this.callBase();
  77. this.$element().addClass(LOADPANEL_CLASS);
  78. this._wrapper().addClass(LOADPANEL_WRAPPER_CLASS)
  79. },
  80. _renderContentImpl: function() {
  81. this.callBase();
  82. this.$content().addClass(LOADPANEL_CONTENT_CLASS);
  83. this._$contentWrapper = $("<div>").addClass(LOADPANEL_CONTENT_WRAPPER_CLASS);
  84. this._$contentWrapper.appendTo(this._$content);
  85. this._togglePaneVisible();
  86. this._cleanPreviousContent();
  87. this._renderLoadIndicator();
  88. this._renderMessage()
  89. },
  90. _show: function() {
  91. var delay = this.option("delay");
  92. if (!delay) {
  93. return this.callBase()
  94. }
  95. var deferred = new Deferred;
  96. var callBase = this.callBase.bind(this);
  97. this._clearShowTimeout();
  98. this._showTimeout = setTimeout(function() {
  99. callBase().done(function() {
  100. deferred.resolve()
  101. })
  102. }, delay);
  103. return deferred.promise()
  104. },
  105. _hide: function() {
  106. this._clearShowTimeout();
  107. return this.callBase()
  108. },
  109. _clearShowTimeout: function() {
  110. clearTimeout(this._showTimeout)
  111. },
  112. _renderMessage: function() {
  113. if (!this._$contentWrapper) {
  114. return
  115. }
  116. var message = this.option("message");
  117. if (!message) {
  118. return
  119. }
  120. var $message = $("<div>").addClass(LOADPANEL_MESSAGE_CLASS).text(message);
  121. this._$contentWrapper.append($message)
  122. },
  123. _renderLoadIndicator: function() {
  124. if (!this._$contentWrapper || !this.option("showIndicator")) {
  125. return
  126. }
  127. this._$indicator = $("<div>").addClass(LOADPANEL_INDICATOR_CLASS).appendTo(this._$contentWrapper);
  128. this._createComponent(this._$indicator, LoadIndicator, {
  129. indicatorSrc: this.option("indicatorSrc")
  130. })
  131. },
  132. _cleanPreviousContent: function() {
  133. this.$content().find("." + LOADPANEL_MESSAGE_CLASS).remove();
  134. this.$content().find("." + LOADPANEL_INDICATOR_CLASS).remove()
  135. },
  136. _togglePaneVisible: function() {
  137. this.$content().toggleClass(LOADPANEL_PANE_HIDDEN_CLASS, !this.option("showPane"))
  138. },
  139. _optionChanged: function(args) {
  140. switch (args.name) {
  141. case "delay":
  142. break;
  143. case "message":
  144. case "showIndicator":
  145. this._cleanPreviousContent();
  146. this._renderLoadIndicator();
  147. this._renderMessage();
  148. break;
  149. case "showPane":
  150. this._togglePaneVisible();
  151. break;
  152. case "indicatorSrc":
  153. if (this._$indicator) {
  154. this._createComponent(this._$indicator, LoadIndicator, {
  155. indicatorSrc: this.option("indicatorSrc")
  156. })
  157. }
  158. break;
  159. default:
  160. this.callBase(args)
  161. }
  162. },
  163. _dispose: function() {
  164. this._clearShowTimeout();
  165. this.callBase()
  166. }
  167. });
  168. registerComponent("dxLoadPanel", LoadPanel);
  169. module.exports = LoadPanel;
  170. module.exports.default = module.exports;