ui.scheduler.timezone_editor.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * DevExtreme (ui/scheduler/timezones/ui.scheduler.timezone_editor.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 registerComponent = require("../../../core/component_registrator");
  12. var extend = require("../../../core/utils/extend").extend;
  13. var publisherMixin = require("../ui.scheduler.publisher_mixin");
  14. var messageLocalization = require("../../../localization/message");
  15. var Editor = require("../../editor/editor");
  16. var SelectBox = require("../../select_box");
  17. var TIMEZONE_EDITOR_CLASS = "dx-timezone-editor";
  18. var TIMEZONE_DISPLAY_NAME_SELECTBOX_CLASS = "dx-timezone-display-name";
  19. var TIMEZONE_IANA_ID_SELECTBOX_CLASS = "dx-timezone-iana-id";
  20. var SchedulerTimezoneEditor = Editor.inherit({
  21. _getDefaultOptions: function() {
  22. return extend(this.callBase(), {
  23. value: null
  24. })
  25. },
  26. _createComponent: function(element, name, config) {
  27. config = config || {};
  28. this._extendConfig(config, {
  29. readOnly: this.option("readOnly")
  30. });
  31. return this.callBase(element, name, config)
  32. },
  33. _init: function() {
  34. this.callBase();
  35. this.$element().addClass(TIMEZONE_EDITOR_CLASS)
  36. },
  37. _render: function() {
  38. this._renderDisplayNameEditor();
  39. this._renderIanaIdEditor();
  40. this.callBase()
  41. },
  42. _renderDisplayNameEditor: function() {
  43. var noTzTitle = messageLocalization.format("dxScheduler-noTimezoneTitle");
  44. var value = this.invoke("getTimezoneDisplayNameById", this.option("value")) || noTzTitle;
  45. this._displayNameEditor = this._renderSelectBox(TIMEZONE_DISPLAY_NAME_SELECTBOX_CLASS, {
  46. items: [noTzTitle].concat(this.invoke("getTimezonesDisplayName")),
  47. value: value,
  48. onOptionChanged: function(e) {
  49. if ("value" === e.name) {
  50. this._processDisplayNameChanging(e.value)
  51. }
  52. }.bind(this)
  53. })
  54. },
  55. _renderIanaIdEditor: function() {
  56. this._ianaIdEditor = this._renderSelectBox(TIMEZONE_IANA_ID_SELECTBOX_CLASS, {
  57. items: this._idsDataSource(),
  58. value: this.option("value"),
  59. onOptionChanged: function(e) {
  60. if ("value" === e.name) {
  61. this.option("value", e.value)
  62. }
  63. }.bind(this),
  64. valueExpr: "id",
  65. displayExpr: "displayName",
  66. disabled: this._calculateIanaIdEditorDisabledState()
  67. })
  68. },
  69. _renderSelectBox: function(cssClass, options) {
  70. options = options || {};
  71. var $element = $("<div>").addClass(cssClass);
  72. var selectBox = this._createComponent($element, SelectBox, options);
  73. this.$element().append($element);
  74. return selectBox
  75. },
  76. _idsDataSource: function() {
  77. return this.invoke("getSimilarTimezones", this.option("value"))
  78. },
  79. _calculateIanaIdEditorDisabledState: function() {
  80. return !this.option("value")
  81. },
  82. _processDisplayNameChanging: function(displayName) {
  83. var tzIds = this.invoke("getTimezonesIdsByDisplayName", displayName);
  84. var tzId = tzIds.length ? tzIds[0].id : null;
  85. this.option("value", tzId);
  86. this._ianaIdEditor.option({
  87. value: tzId,
  88. items: this._idsDataSource(tzIds),
  89. disabled: this._calculateIanaIdEditorDisabledState()
  90. })
  91. },
  92. _optionChanged: function(args) {
  93. var value = args.value;
  94. switch (args.name) {
  95. case "value":
  96. this._ianaIdEditor.option({
  97. value: value,
  98. items: this._idsDataSource()
  99. });
  100. if (value) {
  101. this._displayNameEditor.option("value", this.invoke("getTimezoneDisplayNameById", value))
  102. } else {
  103. this._displayNameEditor.option("value", messageLocalization.format("dxScheduler-noTimezoneTitle"))
  104. }
  105. this.callBase(args);
  106. break;
  107. case "readOnly":
  108. this._displayNameEditor && this._displayNameEditor.option("readOnly", value);
  109. this._ianaIdEditor && this._ianaIdEditor.option("readOnly", value);
  110. break;
  111. default:
  112. this.callBase(args)
  113. }
  114. }
  115. }).include(publisherMixin);
  116. registerComponent("dxSchedulerTimezoneEditor", {}, SchedulerTimezoneEditor);
  117. module.exports = SchedulerTimezoneEditor;