8461cc55d87ef09d6f9fce28a64d65d8b8b1814a
[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 * System information menu handler
16 */
17 define(['jquery', 'TYPO3/CMS/Backend/Icons', 'TYPO3/CMS/Backend/Storage'], function($, Icons, Storage) {
18 'use strict';
19
20 var SystemInformationMenu = {
21 identifier: {
22 containerSelector: '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
23 toolbarIconSelector: '.dropdown-toggle span.icon',
24 menuContainerSelector: '.dropdown-menu',
25 moduleLinks: '.t3js-systeminformation-module'
26 },
27 elements: {
28 $counter: $('#t3js-systeminformation-counter')
29 }
30 };
31
32 /**
33 * Initialize the events
34 */
35 SystemInformationMenu.initialize = function() {
36 $(SystemInformationMenu.identifier.moduleLinks).on('click', SystemInformationMenu.openModule);
37 };
38
39 /**
40 * Updates the menu
41 */
42 SystemInformationMenu.updateMenu = function() {
43 var $toolbarItemIcon = $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector),
44 $existingIcon = $toolbarItemIcon.clone(),
45 $menuContainer = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector);
46
47 // hide the menu if it's active
48 if ($menuContainer.is(':visible')) {
49 $menuContainer.click();
50 }
51
52 Icons.getIcon('spinner-circle-light', Icons.sizes.small).done(function(icons) {
53 $toolbarItemIcon.replaceWith(icons['spinner-circle-light']);
54 });
55
56 $.ajax({
57 url: TYPO3.settings.ajaxUrls['systeminformation_render'],
58 type: 'post',
59 cache: false,
60 success: function(data) {
61 $menuContainer.html(data);
62 SystemInformationMenu.updateCounter();
63 $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector).replaceWith($existingIcon);
64
65 SystemInformationMenu.initialize();
66 }
67 });
68 };
69
70 /**
71 * Updates the counter
72 */
73 SystemInformationMenu.updateCounter = function() {
74 var $ul = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector).find('ul'),
75 count = $ul.data('count'),
76 badgeClass = $ul.data('severityclass');
77
78 SystemInformationMenu.elements.$counter.text(count).toggle(count > 0);
79 SystemInformationMenu.elements.$counter.removeClass();
80
81 if (badgeClass !== '') {
82 SystemInformationMenu.elements.$counter.addClass('badge ' + badgeClass);
83 }
84 };
85
86 /**
87 * Updates the UC and opens the linked module
88 */
89 SystemInformationMenu.openModule = function(e) {
90 e.preventDefault();
91 e.stopPropagation();
92
93 var storedSystemInformationSettings = {},
94 moduleStorageObject = {},
95 requestedModule = $(e.currentTarget).data('modulename'),
96 timestamp = Math.floor((new Date()).getTime() / 1000);
97
98 if (Storage.Persistent.isset('systeminformation')) {
99 storedSystemInformationSettings = JSON.parse(Storage.Persistent.get('systeminformation'));
100 }
101
102 moduleStorageObject[requestedModule] = {lastAccess: timestamp};
103 $.extend(true, storedSystemInformationSettings, moduleStorageObject);
104 var $ajax = Storage.Persistent.set('systeminformation', JSON.stringify(storedSystemInformationSettings));
105 $ajax.done(function() {
106 // finally, open the module now
107 TYPO3.ModuleMenu.App.showModule(requestedModule);
108 SystemInformationMenu.updateMenu();
109 });
110 };
111
112 $(SystemInformationMenu.updateMenu);
113
114 return SystemInformationMenu;
115 });