OTRS API Reference JavaScript

Source: Core.Agent.TicketProcess.js

  1. // --
  2. // Copyright (C) 2001-2018 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. /**
  12. * @namespace Core.Agent.TicketProcess
  13. * @memberof Core.Agent
  14. * @author OTRS AG
  15. * @description
  16. * This namespace contains the special module functions for TicketProcess.
  17. */
  18. Core.Agent.TicketProcess = (function (TargetNS) {
  19. /**
  20. * @name Init
  21. * @memberof Core.Agent.TicketProcess
  22. * @function
  23. * @description
  24. * This function initializes the special module functions.
  25. */
  26. TargetNS.Init = function () {
  27. $('#ProcessEntityID').bind('change', function () {
  28. var Data = {
  29. Action: 'AgentTicketProcess',
  30. Subaction: 'DisplayActivityDialogAJAX',
  31. ProcessEntityID: $('#ProcessEntityID').val(),
  32. FormID: $(this).closest('form').find('input:hidden[name=FormID]').val(),
  33. IsAjaxRequest: 1,
  34. IsMainWindow: 1
  35. };
  36. if ($('#IsProcessEnroll').val() !== 'undefined' && $('#IsProcessEnroll').val() === '1') {
  37. $.extend(Data, {
  38. IsMainWindow: 0,
  39. IsProcessEnroll: 1,
  40. TicketID: $('#TicketID').val()
  41. });
  42. }
  43. // remove/destroy CKEditor instances
  44. // This is needed to initialize other instances (in other activity dialogs)
  45. // without a page reload
  46. if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances) {
  47. $.each(CKEDITOR.instances, function (Key) {
  48. CKEDITOR.instances[Key].destroy();
  49. });
  50. }
  51. if ($('#ProcessEntityID').val()) {
  52. // remove the content of the activity dialog
  53. $('#ActivityDialogContent').empty();
  54. // fade out the empty container so it will fade in again on processes change
  55. // is not recommended to empty after fade out at this point since the transition offect
  56. // will not look so nice
  57. $('#ActivityDialogContent').fadeOut('fast');
  58. // show loader icon
  59. $('#AJAXLoader').removeClass('Hidden');
  60. // get new ActivityDialog content
  61. Core.AJAX.FunctionCall(
  62. Core.Config.Get('CGIHandle'),
  63. Data,
  64. function (Response) {
  65. var $ElementToUpdate = $('#ActivityDialogContent'),
  66. JavaScriptString = '',
  67. ErrorMessage;
  68. if (!Response) {
  69. // We are out of the OTRS App scope, that's why an exception would not be caught. Therefor we handle the error manually.
  70. Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("No content received.", 'CommunicationError'));
  71. $('#AJAXLoader').addClass('Hidden');
  72. }
  73. else if ($ElementToUpdate && isJQueryObject($ElementToUpdate) && $ElementToUpdate.length) {
  74. $ElementToUpdate.get(0).innerHTML = Response;
  75. $ElementToUpdate.find('script').each(function() {
  76. JavaScriptString += $(this).html();
  77. $(this).remove();
  78. });
  79. $ElementToUpdate.fadeIn();
  80. Core.UI.InputFields.Activate($ElementToUpdate);
  81. try {
  82. /*eslint-disable no-eval */
  83. eval(JavaScriptString);
  84. /*eslint-enable no-eval */
  85. }
  86. catch (Event) {
  87. // do nothing here (code needed to not have an empty block here)
  88. $.noop(Event);
  89. }
  90. // Handle special server errors (Response = <div class="ServerError" data-message="Message"></div>)
  91. // Check if first element has class 'ServerError'
  92. if ($ElementToUpdate.children().first().hasClass('ServerError')) {
  93. ErrorMessage = $ElementToUpdate.children().first().data('message');
  94. // Add class ServerError to the process select element
  95. $('#ProcessEntityID').addClass('ServerError');
  96. // Set a custom error message to the proccess select element
  97. $('#ProcessEntityIDServerError').children().first().text(ErrorMessage);
  98. }
  99. Core.Form.Validate.Init();
  100. // Register event for tree selection dialog
  101. Core.UI.TreeSelection.InitTreeSelection();
  102. // move help triggers into field rows for dynamic fields
  103. $('.Row > .FieldHelpContainer').each(function () {
  104. if (!$(this).next('label').find('.Marker').length) {
  105. $(this).prependTo($(this).next('label'));
  106. }
  107. else {
  108. $(this).insertAfter($(this).next('label').find('.Marker'));
  109. }
  110. });
  111. // Initially display dynamic fields with TreeMode = 1 correctly
  112. Core.UI.TreeSelection.InitDynamicFieldTreeViewRestore();
  113. // trigger again a responsive event
  114. if (Core.App.Responsive.IsSmallerOrEqual(Core.App.Responsive.GetScreenSize(), 'ScreenL')) {
  115. Core.App.Publish('Event.App.Responsive.SmallerOrEqualScreenL');
  116. }
  117. $('#AJAXLoader').addClass('Hidden');
  118. $('#AJAXDialog').val('1');
  119. }
  120. else {
  121. // We are out of the OTRS App scope, that's why an exception would not be caught. Therefor we handle the error manually.
  122. Core.Exception.HandleFinalError(new Core.Exception.ApplicationError("No such element id: " + $ElementToUpdate.attr('id') + " in page!", 'CommunicationError'));
  123. $('#AJAXLoader').addClass('Hidden');
  124. }
  125. }, 'html');
  126. }
  127. else {
  128. $('#ActivityDialogContent').fadeOut(400, function() {
  129. $('#ActivityDialogContent').empty();
  130. });
  131. }
  132. return false;
  133. });
  134. };
  135. return TargetNS;
  136. }(Core.Agent.TicketProcess || {}));

^ Use Elevator