OTRS API Reference JavaScript

Source: Core.Agent.Admin.PackageManager.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.PackageManager
  14. * @memberof Core.Agent.Admin
  15. * @author OTRS AG
  16. * @description
  17. * This namespace contains the special function for AdminPackageManager module.
  18. */
  19. Core.Agent.Admin.PackageManager = (function (TargetNS) {
  20. var StatusNotificationText = Core.Language.Translate('There is a package upgrade process running, click here to see status information about the upgrade progress.'),
  21. FinisedNotificationText = Core.Language.Translate('A package upgrade was recently finished. Click here to see the results.');
  22. /**
  23. * @name GetPackageUpgradeResult
  24. * @memberof Core.Agent.Admin.PackageManager
  25. * @function
  26. * @description
  27. * This function queries the status of the package upgrade process (via AJAX request) from the system data table.
  28. */
  29. TargetNS.GetPackageUpgradeResult = function() {
  30. var Data = {
  31. Action : 'AdminPackageManager',
  32. Subaction : 'AJAXGetPackageUpgradeResult',
  33. },
  34. DialogTemplate;
  35. Core.AJAX.FunctionCall(
  36. Core.Config.Get('CGIHandle'),
  37. Data,
  38. function (Response) {
  39. if (!Response || !Response.Success) {
  40. Core.UI.Dialog.ShowAlert(
  41. Core.Language.Translate('An error occurred during communication.'),
  42. Core.Language.Translate('No response from get package upgrade result.')
  43. );
  44. return false;
  45. }
  46. DialogTemplate = Core.Template.Render('PackageManager/InformationDialog', {
  47. PackageList: Response.PackageList,
  48. UpgradeStatus: Response.UpgradeStatus,
  49. UpgradeSuccess: Response.UpgradeSuccess,
  50. });
  51. // When finish, do not allow to click outside to close, instead show a button to actively remove data.
  52. if (Response.UpgradeStatus === 'Finished') {
  53. Core.UI.Dialog.ShowDialog({
  54. HTML: DialogTemplate,
  55. Title: Core.Language.Translate('Update all packages'),
  56. Modal: true,
  57. CloseOnClickOutside: false,
  58. CloseOnEscape: false,
  59. PositionTop: '10px',
  60. PositionLeft: 'Center',
  61. AllowAutoGrow: true,
  62. Buttons: [
  63. {
  64. Label: Core.Language.Translate('Dismiss'),
  65. Function: function () {
  66. Core.AJAX.FunctionCall(
  67. Core.Config.Get('CGIHandle'),
  68. 'Action=' + 'AdminPackageManager' + ';Subaction=AJAXDeletePackageUpgradeData;',
  69. function (Response) {
  70. if (!Response || !Response.Success) {
  71. alert(Core.Language.Translate("An error occurred during communication."));
  72. }
  73. Core.UI.Dialog.CloseDialog($('.Dialog:visible'));
  74. window.location.reload();
  75. });
  76. },
  77. Class: 'CallForAction',
  78. Type: 'Close',
  79. },
  80. ]
  81. });
  82. }
  83. // Otherwise show normal dialog without buttons.
  84. else {
  85. Core.UI.Dialog.ShowContentDialog(DialogTemplate, Core.Language.Translate('Update All Packages'), '100px', 'Center', true);
  86. }
  87. }, 'json'
  88. );
  89. };
  90. /**
  91. * @name PackageUpgradeAll
  92. * @memberof Core.Agent.Admin.PackageManager
  93. * @function
  94. * @description
  95. * This function creates a daemon task (via AJAX call) to upgrade all installed packages.
  96. */
  97. TargetNS.PackageUpgradeAll = function() {
  98. var Data = {
  99. Action : 'AdminPackageManager',
  100. Subaction : 'AJAXPackageUpgradeAll',
  101. };
  102. Core.AJAX.FunctionCall(
  103. Core.Config.Get('CGIHandle'),
  104. Data,
  105. function (Response) {
  106. if (!Response || !Response.Success) {
  107. Core.UI.Dialog.ShowAlert(
  108. Core.Language.Translate('An error occurred during communication.'),
  109. Core.Language.Translate('No response from package upgrade all.')
  110. );
  111. return false;
  112. }
  113. TargetNS.DisablePackageActions();
  114. TargetNS.GetPackageUpgradeRunStatus();
  115. }, 'json'
  116. );
  117. };
  118. /**
  119. * @name DisablePackageActions
  120. * @memberof Core.Agent.Admin.PackageManager
  121. * @function
  122. * @description
  123. * This function prevent package actions for running.
  124. */
  125. TargetNS.DisablePackageActions = function() {
  126. $('.UpgradeAll').off('click');
  127. $('.PackageAction').addClass('Disabled').on('click', function(Event){
  128. Core.UI.Dialog.ShowAlert(
  129. Core.Language.Translate('Currently not possible'),
  130. Core.Language.Translate('This is currently disabled because of an ongoing package upgrade.')
  131. );
  132. Event.stopPropagation();
  133. Event.preventDefault();
  134. return false;
  135. });
  136. };
  137. /**
  138. * @name EnablePackageActions
  139. * @memberof Core.Agent.Admin.PackageManager
  140. * @function
  141. * @description
  142. * Tis function activate all package actions.
  143. */
  144. TargetNS.EnablePackageActions = function() {
  145. $('.PackageAction').removeClass('Disabled').off('click');
  146. $('.UpgradeAll').off('click.UpgradeAll').on('click.UpgradeAll', function() {
  147. if (Core.Config.Get('DaemonCheckNotRunning')) {
  148. Core.UI.Dialog.ShowAlert(
  149. Core.Language.Translate('Currently not possible'),
  150. Core.Language.Translate('This option is currently disabled because the OTRS Daemon is not running.')
  151. );
  152. return false;
  153. }
  154. if (window.confirm(Core.Language.Translate("Are you sure you want to update all installed packages?"))) {
  155. TargetNS.PackageUpgradeAll();
  156. }
  157. return false;
  158. });
  159. };
  160. /**
  161. * @name GetPackageUpgradeRunStatus
  162. * @memberof Core.Agent.Admin.PackageManager
  163. * @function
  164. * @description
  165. * This function checks if there is currently a PackageUpgradeAll process running (via AJAX request),
  166. * depending on the results it also enable/disable package actions and show/hide notifications.
  167. */
  168. TargetNS.GetPackageUpgradeRunStatus = function() {
  169. var Data = {
  170. Action : 'AdminPackageManager',
  171. Subaction : 'AJAXGetPackageUpgradeRunStatus',
  172. },
  173. NotificationType;
  174. Core.AJAX.FunctionCall(
  175. Core.Config.Get('CGIHandle'),
  176. Data,
  177. function (Response) {
  178. if (!Response || !Response.Success) {
  179. Core.UI.Dialog.ShowAlert(
  180. Core.Language.Translate('An error occurred during communication.'),
  181. Core.Language.Translate('No response from get package upgrade run status.')
  182. );
  183. return false;
  184. }
  185. /* When the process is running finished notifications needs to be removed and in
  186. progress notification has to be shown, all package actions needs to be disabled
  187. */
  188. if (Response.IsRunning){
  189. TargetNS.DisablePackageActions();
  190. Core.UI.HideNotification(FinisedNotificationText, 'Error', undefined);
  191. Core.UI.HideNotification(FinisedNotificationText, 'Confirmation', undefined);
  192. Core.UI.ShowNotification(
  193. StatusNotificationText,
  194. 'Notice',
  195. undefined,
  196. function() {
  197. $('#PackageUpgradeNotification a').on('click', function(){
  198. TargetNS.GetPackageUpgradeResult();
  199. return false;
  200. });
  201. },
  202. 'PackageUpgradeNotification',
  203. 'fa-spin fa-circle-o-notch'
  204. );
  205. }
  206. else {
  207. Core.UI.HideNotification(StatusNotificationText, 'Notice', undefined);
  208. TargetNS.EnablePackageActions();
  209. }
  210. /* When we get the confirmation that the process has finished, progress notification
  211. has to be removed and finished notification has to be shown.
  212. */
  213. if (Response.UpgradeStatus && Response.UpgradeStatus === 'Finished') {
  214. Core.UI.HideNotification(StatusNotificationText, 'Notice', undefined);
  215. NotificationType = 'Error';
  216. if (Response.UpgradeSuccess && Response.UpgradeSuccess) {
  217. NotificationType = 'Confirmation';
  218. }
  219. Core.UI.ShowNotification(
  220. FinisedNotificationText,
  221. NotificationType,
  222. undefined,
  223. function() {
  224. $('#PackageUpgradeFinishedNotification a').on('click', function(){
  225. TargetNS.GetPackageUpgradeResult();
  226. return false;
  227. });
  228. },
  229. 'PackageUpgradeFinishedNotification',
  230. undefined
  231. );
  232. }
  233. }, 'json'
  234. );
  235. };
  236. /**
  237. * @name Init
  238. * @memberof Core.Agent.Admin.PackageManager
  239. * @function
  240. * @description
  241. * This function initializes module functionality.
  242. */
  243. TargetNS.Init = function () {
  244. TargetNS.EnablePackageActions();
  245. TargetNS.GetPackageUpgradeRunStatus();
  246. setInterval(function(){
  247. TargetNS.GetPackageUpgradeRunStatus();
  248. }, 30000);
  249. };
  250. Core.Init.RegisterNamespace(TargetNS, 'APP_MODULE');
  251. return TargetNS;
  252. }(Core.Agent.Admin.PackageManager || {}));

^ Use Elevator