1. 1 : import { EMPTY_STRING } from '../../../../mel_metapage/js/lib/constants/constants.js';
  2. 2 : import {
  3. 3 : SELECTOR_CHECKBOX_CHANNEL,
  4. 4 : SELECTOR_DIV_CHANNEL,
  5. 5 : SELECTOR_DIV_WSP,
  6. 6 : } from '../consts.js';
  7. 7 : import { ACheckBox } from './abstract/ACheckBox.js';
  8. 8 : export { ChannelPart };
  9. 9 :
  10. 10 : /**
  11. 11 : * Classes lié au choix des canaux lié à la visio si un plugin compatible existe
  12. 12 : * @module Visio/Parts/Channel
  13. 13 : * @local ChannelPart
  14. 14 : */
  15. 15 :
  16. 16 : /**
  17. 17 : * @class
  18. 18 : * @classdesc Récupère le champs qui correspond à l'état de la checkbox
  19. 19 : * @extends ACheckBox
  20. 20 : * @frommodule Visio/Abstract/Checkbox
  21. 21 : */
  22. 22 : class ChannelPart extends ACheckBox {
  23. 23 : constructor() {
  24. 24 : super(SELECTOR_CHECKBOX_CHANNEL);
  25. 25 : this._init()._setup()._main();
  26. 26 : }
  27. 27 :
  28. 28 : /**
  29. 29 : * @private
  30. 30 : * @returns
  31. 31 : */
  32. 32 : _init() {
  33. 33 : /**
  34. 34 : * Champ qui correspond à l'état de la checkbox
  35. 35 : * @type {external:jQuery}
  36. 36 : * @readonly
  37. 37 : * @member
  38. 38 : */
  39. 39 : this.$field = null;
  40. 40 :
  41. 41 : return this;
  42. 42 : }
  43. 43 :
  44. 44 : /**
  45. 45 : * @private
  46. 46 : * @returns
  47. 47 : */
  48. 48 : _setup() {
  49. 49 : Object.defineProperty(this, '$field', {
  50. 50 : get: () =>
  51. 51 : this.is_checked()
  52. 52 : ? $(`${SELECTOR_DIV_WSP} select`)
  53. 53 : : $(`${SELECTOR_DIV_CHANNEL} select`),
  54. 54 : });
  55. 55 :
  56. 56 : return this;
  57. 57 : }
  58. 58 :
  59. 59 : /**
  60. 60 : * @private
  61. 61 : */
  62. 62 : _main() {
  63. 63 : this._p_on_change.push(this._on_checkbox_change.bind(this));
  64. 64 : this._p_on_change.call(this.is_checked());
  65. 65 :
  66. 66 : //Gestion des champs si les plugins n'éxistent pas
  67. 67 : if (
  68. 68 : rcmail.env['visio.has_channel'] !== true ||
  69. 69 : rcmail.env['visio.has_wsp'] !== true
  70. 70 : ) {
  71. 71 : this._p_$checkbox.parent().hide();
  72. 72 :
  73. 73 : if (rcmail.env['visio.has_channel'] !== true) {
  74. 74 : $(SELECTOR_DIV_CHANNEL).remove();
  75. 75 : this._p_$checkbox.prop('checked', true);
  76. 76 : $(SELECTOR_DIV_WSP)
  77. 77 : .css('display', EMPTY_STRING)
  78. 78 : .find('.title-conf-item')
  79. 79 : .text('Attacher à un espace de travail ?')
  80. 80 : .parent()
  81. 81 : .find('select')
  82. 82 : .prepend('<option value="" selected>Ne pas attacher</option>');
  83. 83 : }
  84. 84 :
  85. 85 : if (rcmail.env['visio.has_wsp'] !== true) {
  86. 86 : this._p_$checkbox.prop('checked', false);
  87. 87 : $(SELECTOR_DIV_WSP).remove();
  88. 88 : }
  89. 89 :
  90. 90 : try {
  91. 91 : this.value();
  92. 92 : } catch (error) {
  93. 93 : this.value = () => EMPTY_STRING;
  94. 94 : }
  95. 95 : }
  96. 96 : }
  97. 97 :
  98. 98 : /**
  99. 99 : * Action à faire lorsque la checkbox change d'état
  100. 100 : * @param {!boolean} state
  101. 101 : * @package
  102. 102 : */
  103. 103 : _on_checkbox_change(state) {
  104. 104 : if (state) {
  105. 105 : $(SELECTOR_DIV_WSP).show();
  106. 106 : $(SELECTOR_DIV_CHANNEL).hide();
  107. 107 : } else {
  108. 108 : $(SELECTOR_DIV_WSP).hide();
  109. 109 : $(SELECTOR_DIV_CHANNEL).show();
  110. 110 : }
  111. 111 : }
  112. 112 :
  113. 113 : /**
  114. 114 : * Désactive les champs
  115. 115 : * @override
  116. 116 : */
  117. 117 : disable() {
  118. 118 : super.disable();
  119. 119 : this._p_disable(this.$field);
  120. 120 : }
  121. 121 :
  122. 122 : /**
  123. 123 : * Active les champs
  124. 124 : * @override
  125. 125 : */
  126. 126 : enable() {
  127. 127 : super.enable();
  128. 128 : this._p_enable(this.$field);
  129. 129 : }
  130. 130 :
  131. 131 : /**
  132. 132 : * Récupère la valeur du champ
  133. 133 : * @override
  134. 134 : * @returns {string}
  135. 135 : */
  136. 136 : value() {
  137. 137 : return this.$field?.val?.() || EMPTY_STRING;
  138. 138 : }
  139. 139 : }