ui.date_box.strategy.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * DevExtreme (ui/date_box/ui.date_box.strategy.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 eventsEngine = require("../../events/core/events_engine");
  12. var noop = require("../../core/utils/common").noop;
  13. var Class = require("../../core/class");
  14. var dateLocalization = require("../../localization/date");
  15. var abstract = Class.abstract;
  16. var DateBoxStrategy = Class.inherit({
  17. ctor: function(dateBox) {
  18. this.dateBox = dateBox
  19. },
  20. widgetOption: function() {
  21. return this._widget && this._widget.option.apply(this._widget, arguments)
  22. },
  23. _renderWidget: function(element) {
  24. element = element || $("<div>");
  25. this._widget = this._createWidget(element);
  26. this._widget.$element().appendTo(this._getWidgetContainer())
  27. },
  28. _createWidget: function(element) {
  29. var widgetName = this._getWidgetName();
  30. var widgetOptions = this._getWidgetOptions();
  31. return this.dateBox._createComponent(element, widgetName, widgetOptions)
  32. },
  33. _getWidgetOptions: abstract,
  34. _getWidgetName: abstract,
  35. getDefaultOptions: function() {
  36. return {
  37. mode: "text"
  38. }
  39. },
  40. getDisplayFormat: abstract,
  41. supportedKeys: noop,
  42. customizeButtons: noop,
  43. attachKeyboardEvents: function(keyboardProcessor) {
  44. this._widgetKeyboardProcessor = keyboardProcessor.attachChildProcessor()
  45. },
  46. getParsedText: function(text, format) {
  47. var value = dateLocalization.parse(text, format);
  48. return value ? value : dateLocalization.parse(text)
  49. },
  50. renderInputMinMax: noop,
  51. renderOpenedState: function() {
  52. this._updateValue()
  53. },
  54. popupConfig: abstract,
  55. renderPopupContent: function() {
  56. var popup = this._getPopup();
  57. this._renderWidget();
  58. var $popupContent = popup.$content().parent();
  59. eventsEngine.off($popupContent, "mousedown");
  60. eventsEngine.on($popupContent, "mousedown", this._preventFocusOnPopup.bind(this))
  61. },
  62. getFirstPopupElement: noop,
  63. getLastPopupElement: noop,
  64. _preventFocusOnPopup: function(e) {
  65. e.preventDefault()
  66. },
  67. _getWidgetContainer: function() {
  68. return this._getPopup().$content()
  69. },
  70. _getPopup: function() {
  71. return this.dateBox._popup
  72. },
  73. popupShowingHandler: noop,
  74. popupHiddenHandler: noop,
  75. _updateValue: function() {
  76. this._widget && this._widget.option("value", this.dateBoxValue())
  77. },
  78. _valueChangedHandler: function(args) {
  79. if (this.dateBox.option("opened") && "instantly" === this.dateBox.option("applyValueMode")) {
  80. this.dateBoxValue(args.value)
  81. }
  82. },
  83. useCurrentDateByDefault: noop,
  84. getDefaultDate: function() {
  85. return new Date
  86. },
  87. textChangedHandler: noop,
  88. renderValue: function() {
  89. if (this.dateBox.option("opened")) {
  90. this._updateValue()
  91. }
  92. },
  93. getValue: function() {
  94. return this._widget.option("value")
  95. },
  96. isAdaptivityChanged: function() {
  97. return false
  98. },
  99. dispose: function() {
  100. var popup = this._getPopup();
  101. if (popup) {
  102. popup.$content().empty()
  103. }
  104. },
  105. dateBoxValue: function() {
  106. if (arguments.length) {
  107. return this.dateBox.dateValue.apply(this.dateBox, arguments)
  108. } else {
  109. return this.dateBox.dateOption.apply(this.dateBox, ["value"])
  110. }
  111. }
  112. });
  113. module.exports = DateBoxStrategy;