OTRS API Reference JavaScript

Source: Core.Agent.Admin.NotificationEvent.js

  1. // --
  2. // Copyright (C) 2001-2020 OTRS AG, https://otrs.com/
  3. // --
  4. // This software comes with ABSOLUTELY NO WARRANTY. For details, see
  5. // the enclosed file COPYING for license information (GPL). If you
  6. // did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
  7. // --
  8. "use strict";
  9. var Core = Core || {};
  10. Core.Agent = Core.Agent || {};
  11. Core.Agent.Admin = Core.Agent.Admin || {};
  12. /**
  13. * @namespace Core.Agent.Admin.NotificationEvent
  14. * @memberof Core.Agent.Admin
  15. * @author OTRS AG
  16. * @description
  17. * This namespace contains the special module functions for the Notification Event module.
  18. */
  19. Core.Agent.Admin.NotificationEvent = (function (TargetNS) {
  20. /**
  21. * @name Init
  22. * @memberof Core.Agent.Admin.NotificationEvent
  23. * @function
  24. * @description
  25. * This function initialize correctly all other function according to the local language.
  26. */
  27. TargetNS.Init = function () {
  28. // bind click function to add button
  29. $('.LanguageAdd').off('change.NotificationEvent').on('change.NotificationEvent', function () {
  30. TargetNS.AddLanguage($(this).val(), $('.LanguageAdd option:selected').text());
  31. return false;
  32. });
  33. // bind click function to remove button
  34. $('.LanguageRemove').off('click.NotificationEvent').on('click.NotificationEvent', function () {
  35. if (window.confirm(Core.Language.Translate('Do you really want to delete this notification language?'))) {
  36. TargetNS.RemoveLanguage($(this));
  37. }
  38. return false;
  39. });
  40. function VisibleForAgentHandler() {
  41. var TooltipObject = $('#VisibleForAgentTooltip');
  42. if ($('#VisibleForAgent').val() > 0) {
  43. TooltipObject.removeAttr('readonly');
  44. // show default transport value
  45. $('.AgentEnabledByDefault').show();
  46. }
  47. else {
  48. TooltipObject.attr('readonly', 'readonly');
  49. // hide default transport value
  50. $('.AgentEnabledByDefault').hide();
  51. }
  52. }
  53. $('#VisibleForAgent').on('change.NotificationEvent', VisibleForAgentHandler);
  54. // Run on first view.
  55. VisibleForAgentHandler();
  56. // initialize table filter
  57. Core.UI.Table.InitTableFilter($("#FilterNotifications"), $("#Notifications"));
  58. // register dialog box for delete notification
  59. $('.NotificationDelete').click(function (Event) {
  60. if (window.confirm(Core.Language.Translate('Do you really want to delete this notification?'))) {
  61. window.location = $(this).attr('href');
  62. }
  63. // don't interfere with MasterAction
  64. Event.stopPropagation();
  65. Event.preventDefault();
  66. return false;
  67. });
  68. // add special validation method
  69. Core.Form.Validate.AddMethod("Validate_OneChecked", function() {
  70. if($(".Validate_OneChecked:checkbox:checked").length > 0){
  71. return true;
  72. }
  73. return false;
  74. });
  75. // add special validation rule
  76. Core.Form.Validate.AddRule("Validate_OneChecked", {Validate_OneChecked: true});
  77. // set up attributes (enable/disable) to some fields on click
  78. $('#EmailSecuritySettings').click(function() {
  79. var InputField = [
  80. "EmailSigningCrypting_Search",
  81. "EmailMissingSigningKeys_Search",
  82. "EmailMissingCryptingKeys_Search",
  83. "EmailDefaultSigningKeys_Search"
  84. ];
  85. if (this.checked) {
  86. $.each(InputField, function(index, item) {
  87. $('#' + item)
  88. .removeAttr('readonly disabled')
  89. .parent()
  90. .removeClass('AlreadyDisabled');
  91. });
  92. $('.Security').removeAttr('disabled', 'disabled');
  93. }
  94. else {
  95. $.each(InputField, function(index, item) {
  96. $('#' + item)
  97. .attr({
  98. 'readonly' : 'readonly',
  99. 'disabled' : 'disabled'
  100. })
  101. .parent()
  102. .addClass('AlreadyDisabled');
  103. });
  104. $('.Security').attr('disabled', 'disabled');
  105. }
  106. });
  107. };
  108. /**
  109. * @name AddLanguage
  110. * @memberof Core.Agent.Admin.NotificationEvent
  111. * @function
  112. * @param {string} LanguageID - short name of the language like es_MX.
  113. * @param {string} Language - full name of the language like Spanish (Mexico).
  114. * @returns {Bool} Returns false to prevent event bubbling.
  115. * @description
  116. * This function add a new notification event language.
  117. */
  118. TargetNS.AddLanguage = function(LanguageID, Language){
  119. var $Clone = $('.Template').clone();
  120. if (Language === '-'){
  121. return false;
  122. }
  123. // remove unnecessary classes
  124. $Clone.removeClass('Hidden Template');
  125. // add title
  126. $Clone.find('.Title').html(Language);
  127. // update remove link
  128. $Clone.find('#Template_Language_Remove').attr('name', LanguageID + '_Language_Remove');
  129. $Clone.find('#Template_Language_Remove').attr('id', LanguageID + '_Language_Remove');
  130. // set hidden language field
  131. $Clone.find('.LanguageID').attr('name', 'LanguageID');
  132. $Clone.find('.LanguageID').val(LanguageID);
  133. // update subject label
  134. $Clone.find('#Template_Label_Subject').attr('for', LanguageID + '_Subject');
  135. $Clone.find('#Template_Label_Subject').attr('id', LanguageID + '_Label_Subject');
  136. // update subject field
  137. $Clone.find('#Template_Subject').attr('name', LanguageID + '_Subject');
  138. $Clone.find('#Template_Subject').addClass('Validate_Required');
  139. $Clone.find('#Template_Subject').attr('id', LanguageID + '_Subject');
  140. $Clone.find('#Template_SubjectError').attr('id', LanguageID + '_SubjectError');
  141. // update body label
  142. $Clone.find('#Template_Label_Body').attr('for', LanguageID + '_Body');
  143. $Clone.find('#Template_Label_Body').attr('id', LanguageID + '_Label_Body');
  144. // update body field
  145. $Clone.find('#Template_Body').attr('name', LanguageID + '_Body');
  146. $Clone.find('#Template_Body').addClass('RichText');
  147. $Clone.find('#Template_Body').addClass('Validate_RequiredRichText');
  148. $Clone.find('#Template_Body').attr('id', LanguageID + '_Body');
  149. $Clone.find('#Template_BodyError').attr('id', LanguageID + '_BodyError');
  150. // append to container
  151. $('.NotificationLanguageContainer').append($Clone);
  152. // initialize the rich text editor if set
  153. if (parseInt(Core.Config.Get('RichTextSet'), 10) === 1) {
  154. Core.UI.RichTextEditor.InitAllEditors();
  155. }
  156. // bind click function to remove button
  157. $('.LanguageRemove').off('click.NotificationEvent').on('click.NotificationEvent', function () {
  158. if (window.confirm(Core.Language.Translate('Do you really want to delete this notification language?'))) {
  159. TargetNS.RemoveLanguage($(this));
  160. }
  161. return false;
  162. });
  163. TargetNS.LanguageSelectionRebuild();
  164. Core.UI.InitWidgetActionToggle();
  165. return false;
  166. };
  167. /**
  168. * @name RemoveLanguage
  169. * @memberof Core.Agent.Admin.NotificationEvent
  170. * @function
  171. * @param {jQueryObject} Object - JQuery object used to remove the language block
  172. * @description
  173. * This function removes a notification event language.
  174. */
  175. TargetNS.RemoveLanguage = function (Object) {
  176. Object.closest('.NotificationLanguage').remove();
  177. TargetNS.LanguageSelectionRebuild();
  178. };
  179. /**
  180. * @name LanguageSelectionRebuild
  181. * @memberof Core.Agent.Admin.NotificationEvent
  182. * @function
  183. * @returns {Boolean} Returns true.
  184. * @description
  185. * This function rebuilds language selection, only show available languages.
  186. */
  187. TargetNS.LanguageSelectionRebuild = function () {
  188. // get original selection with all possible fields and clone it
  189. var $Languages = $('#LanguageOrig option').clone();
  190. $('#Language').empty();
  191. // strip all already used attributes
  192. $Languages.each(function () {
  193. if (!$('.NotificationLanguageContainer label#' + $(this).val() + '_Label_Subject').length) {
  194. $('#Language').append($(this));
  195. }
  196. });
  197. $('#Language').trigger('redraw.InputField');
  198. // bind click function to add button
  199. $('.LanguageAdd').off('change.NotificationEvent').on('change.NotificationEvent', function () {
  200. TargetNS.AddLanguage($(this).val(), $('.LanguageAdd option:selected').text());
  201. return false;
  202. });
  203. return true;
  204. };
  205. Core.Init.RegisterNamespace(TargetNS, 'APP_MODULE');
  206. return TargetNS;
  207. }(Core.Agent.Admin.NotificationEvent || {}));

^ Use Elevator