b3bb52e8d14bc1cb47efd3c1a5bfffc7f7127ad1
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / Toolbar / SystemInformationMenu.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * Module: TYPO3/CMS/Backend/Toolbar/SystemInformationMenu
16 * System information menu handler
17 */
18 define([
19 'jquery',
20 'TYPO3/CMS/Backend/Icons',
21 'TYPO3/CMS/Backend/Storage',
22 'TYPO3/CMS/Backend/Viewport'
23 ], function($, Icons, Storage, Viewport) {
24 'use strict';
25
26 /**
27 *
28 * @type {{identifier: {containerSelector: string, toolbarIconSelector: string, menuContainerSelector: string, moduleLinks: string}, elements: {$counter: (*|jQuery|HTMLElement)}}}
29 * @exports TYPO3/CMS/Backend/Toolbar/SystemInformationMenu
30 */
31 var SystemInformationMenu = {
32 identifier: {
33 containerSelector: '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
34 toolbarIconSelector: '.toolbar-item-icon .t3js-icon',
35 menuContainerSelector: '.dropdown-menu',
36 moduleLinks: '.t3js-systeminformation-module',
37 counter: '.t3js-systeminformation-counter'
38 }
39 };
40
41 /**
42 * Initialize the events
43 */
44 SystemInformationMenu.initialize = function() {
45 $(SystemInformationMenu.identifier.moduleLinks).on('click', SystemInformationMenu.openModule);
46 };
47
48 /**
49 * Updates the menu
50 */
51 SystemInformationMenu.updateMenu = function() {
52 var $toolbarItemIcon = $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector),
53 $existingIcon = $toolbarItemIcon.clone(),
54 $menuContainer = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector);
55
56 // hide the menu if it's active
57 if ($menuContainer.is(':visible')) {
58 $menuContainer.click();
59 }
60
61 Icons.getIcon('spinner-circle-light', Icons.sizes.small).done(function(spinner) {
62 $toolbarItemIcon.replaceWith(spinner);
63 });
64
65 $.ajax({
66 url: TYPO3.settings.ajaxUrls['systeminformation_render'],
67 type: 'post',
68 cache: false,
69 success: function(data) {
70 $menuContainer.html(data);
71 SystemInformationMenu.updateCounter();
72 $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector).replaceWith($existingIcon);
73
74 SystemInformationMenu.initialize();
75 }
76 });
77 };
78
79 /**
80 * Updates the counter
81 */
82 SystemInformationMenu.updateCounter = function() {
83 var $container = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector).find('.t3js-systeminformation-container'),
84 $counter = $(SystemInformationMenu.identifier.counter),
85 count = $container.data('count'),
86 badgeClass = $container.data('severityclass');
87
88 $counter.text(count).toggle(parseInt(count) > 0);
89 $counter.removeClass();
90
91 if (badgeClass !== '') {
92 $counter.addClass('toolbar-item-badge badge ' + badgeClass);
93 }
94 };
95
96 /**
97 * Updates the UC and opens the linked module
98 *
99 * @param {Event} e
100 */
101 SystemInformationMenu.openModule = function(e) {
102 e.preventDefault();
103 e.stopPropagation();
104
105 var storedSystemInformationSettings = {},
106 moduleStorageObject = {},
107 requestedModule = $(e.currentTarget).data('modulename'),
108 timestamp = Math.floor((new Date()).getTime() / 1000);
109
110 if (Storage.Persistent.isset('systeminformation')) {
111 storedSystemInformationSettings = JSON.parse(Storage.Persistent.get('systeminformation'));
112 }
113
114 moduleStorageObject[requestedModule] = {lastAccess: timestamp};
115 $.extend(true, storedSystemInformationSettings, moduleStorageObject);
116 var $ajax = Storage.Persistent.set('systeminformation', JSON.stringify(storedSystemInformationSettings));
117 $ajax.done(function() {
118 // finally, open the module now
119 TYPO3.ModuleMenu.App.showModule(requestedModule);
120 Viewport.Topbar.refresh();
121 });
122 };
123
124 Viewport.Topbar.Toolbar.registerEvent(SystemInformationMenu.updateMenu);
125
126 return SystemInformationMenu;
127 });