ui.date_box.strategy.native.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * DevExtreme (ui/date_box/ui.date_box.strategy.native.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 noop = require("../../core/utils/common").noop;
  11. var DateBoxStrategy = require("./ui.date_box.strategy");
  12. var support = require("../../core/utils/support");
  13. var inArray = require("../../core/utils/array").inArray;
  14. var dateUtils = require("./ui.date_utils");
  15. var dateSerialization = require("../../core/utils/date_serialization");
  16. var NativeStrategy = DateBoxStrategy.inherit({
  17. NAME: "Native",
  18. popupConfig: noop,
  19. getParsedText: function(text) {
  20. if (!text) {
  21. return null
  22. }
  23. if ("datetime" === this.dateBox.option("type")) {
  24. return new Date(text.replace(/-/g, "/").replace("T", " ").split(".")[0])
  25. }
  26. return dateUtils.fromStandardDateFormat(text)
  27. },
  28. renderPopupContent: noop,
  29. _getWidgetName: noop,
  30. _getWidgetOptions: noop,
  31. _getDateBoxType: function() {
  32. var type = this.dateBox.option("type");
  33. if (inArray(type, dateUtils.SUPPORTED_FORMATS) === -1) {
  34. type = "date"
  35. } else {
  36. if ("datetime" === type && !support.inputType(type)) {
  37. type = "datetime-local"
  38. }
  39. }
  40. return type
  41. },
  42. customizeButtons: function() {
  43. var dropDownButton = this.dateBox.getButton("dropDown");
  44. if (dropDownButton) {
  45. dropDownButton.on("click", function() {
  46. this.dateBox._input().get(0).click()
  47. }.bind(this))
  48. }
  49. },
  50. getDefaultOptions: function() {
  51. return {
  52. mode: this._getDateBoxType()
  53. }
  54. },
  55. getDisplayFormat: function(displayFormat) {
  56. var type = this._getDateBoxType();
  57. return displayFormat || dateUtils.FORMATS_MAP[type]
  58. },
  59. renderInputMinMax: function($input) {
  60. $input.attr({
  61. min: dateSerialization.serializeDate(this.dateBox.dateOption("min"), "yyyy-MM-dd"),
  62. max: dateSerialization.serializeDate(this.dateBox.dateOption("max"), "yyyy-MM-dd")
  63. })
  64. }
  65. });
  66. module.exports = NativeStrategy;