ui.date_box.strategy.date_view.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * DevExtreme (ui/date_box/ui.date_box.strategy.date_view.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 window = require("../../core/utils/window").getWindow();
  12. var DateView = require("./ui.date_view");
  13. var DateBoxStrategy = require("./ui.date_box.strategy");
  14. var support = require("../../core/utils/support");
  15. var extend = require("../../core/utils/extend").extend;
  16. var dateUtils = require("./ui.date_utils");
  17. var messageLocalization = require("../../localization/message");
  18. var DateViewStrategy = DateBoxStrategy.inherit({
  19. NAME: "DateView",
  20. getDefaultOptions: function() {
  21. return extend(this.callBase(), {
  22. openOnFieldClick: true,
  23. applyButtonText: messageLocalization.format("OK")
  24. })
  25. },
  26. getDisplayFormat: function(displayFormat) {
  27. return displayFormat || dateUtils.FORMATS_MAP[this.dateBox.option("type")]
  28. },
  29. popupConfig: function(config) {
  30. return {
  31. showTitle: true,
  32. toolbarItems: this.dateBox._popupToolbarItemsConfig(),
  33. onInitialized: config.onInitialized,
  34. defaultOptionsRules: [{
  35. device: function(_device) {
  36. return "win" === _device.platform && _device.version && 8 === _device.version[0]
  37. },
  38. options: {
  39. showNames: true
  40. }
  41. }, {
  42. device: function(_device2) {
  43. return "win" === _device2.platform && _device2.phone && _device2.version && 8 === _device2.version[0]
  44. },
  45. options: {
  46. animation: null
  47. }
  48. }, {
  49. device: {
  50. platform: "android"
  51. },
  52. options: {
  53. width: 333,
  54. height: 331
  55. }
  56. }, {
  57. device: function(_device3) {
  58. var platform = _device3.platform;
  59. var version = _device3.version;
  60. return "generic" === platform || "ios" === platform || "win" === platform && version && 10 === version[0]
  61. },
  62. options: {
  63. width: "auto",
  64. height: "auto"
  65. }
  66. }, {
  67. device: function(_device4) {
  68. var platform = _device4.platform;
  69. var phone = _device4.phone;
  70. return "generic" === platform && phone
  71. },
  72. options: {
  73. width: 333,
  74. maxWidth: "100%",
  75. maxHeight: "100%",
  76. height: "auto",
  77. position: {
  78. collision: "flipfit flip"
  79. }
  80. }
  81. }, {
  82. device: {
  83. platform: "ios",
  84. phone: true
  85. },
  86. options: {
  87. width: "100%",
  88. position: {
  89. my: "bottom",
  90. at: "bottom",
  91. of: window
  92. }
  93. }
  94. }]
  95. }
  96. },
  97. _renderWidget: function() {
  98. if (support.inputType(this.dateBox.option("mode")) && this.dateBox._isNativeType() || this.dateBox.option("readOnly")) {
  99. if (this._widget) {
  100. this._widget.$element().remove();
  101. this._widget = null
  102. }
  103. return
  104. }
  105. var popup = this._getPopup();
  106. if (this._widget) {
  107. this._widget.option(this._getWidgetOptions())
  108. } else {
  109. var element = $("<div>").appendTo(popup.$content());
  110. this._widget = this._createWidget(element)
  111. }
  112. this._widget.$element().appendTo(this._getWidgetContainer())
  113. },
  114. _getWidgetName: function() {
  115. return DateView
  116. },
  117. renderOpenedState: function() {
  118. this.callBase();
  119. if (this._widget) {
  120. this._widget.option("value", this._widget._getCurrentDate())
  121. }
  122. },
  123. _getWidgetOptions: function() {
  124. return {
  125. value: this.dateBoxValue() || new Date,
  126. type: this.dateBox.option("type"),
  127. minDate: this.dateBox.dateOption("min") || new Date(1900, 0, 1),
  128. maxDate: this.dateBox.dateOption("max") || new Date(Date.now() + 50 * dateUtils.ONE_YEAR),
  129. onDisposing: function() {
  130. this._widget = null
  131. }.bind(this)
  132. }
  133. }
  134. });
  135. module.exports = DateViewStrategy;