d1a5dc179de838bc8062cff1499674eef6393049
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Resources / Public / JavaScript / Recordlist.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/Recordlist/Recordlist
16 * Usability improvements for the record list
17 */
18 define(['jquery', 'TYPO3/CMS/Backend/Storage', 'TYPO3/CMS/Backend/Icons'], function($, Storage, Icons) {
19 'use strict';
20
21 /**
22 *
23 * @type {{identifier: {toggle: string, icons: {collapse: string, expand: string}}}}
24 * @exports TYPO3/CMS/Recordlist/Recordlist
25 */
26 var Recordlist = {
27 identifier: {
28 toggle: '.t3js-toggle-recordlist',
29 icons: {
30 collapse: 'actions-view-list-collapse',
31 expand: 'actions-view-list-expand'
32 }
33 }
34 };
35
36 /**
37 *
38 * @param {Event} e
39 */
40 Recordlist.toggleClick = function(e) {
41 e.preventDefault();
42
43 var $me = $(this),
44 table = $me.data('table'),
45 $target = $($me.data('target')),
46 isExpanded = $target.data('state') === 'expanded',
47 $collapseIcon = $me.find('.collapseIcon'),
48 toggleIcon = isExpanded ? Recordlist.identifier.icons.expand : Recordlist.identifier.icons.collapse;
49
50 Icons.getIcon(toggleIcon, Icons.sizes.small).done(function(toggleIcon) {
51 $collapseIcon.html(toggleIcon);
52 });
53
54 // Store collapse state in UC
55 var storedModuleDataList = {};
56
57 if (Storage.Persistent.isset('moduleData.list')) {
58 storedModuleDataList = Storage.Persistent.get('moduleData.list');
59 }
60
61 var collapseConfig = {};
62 collapseConfig[table] = isExpanded ? 1 : 0;
63
64 $.extend(true, storedModuleDataList, collapseConfig);
65 Storage.Persistent.set('moduleData.list', storedModuleDataList).done(function() {
66 $target.data('state', isExpanded ? 'collapsed' : 'expanded');
67 });
68 };
69
70 $(function() {
71 $(document).on('click', Recordlist.identifier.toggle, Recordlist.toggleClick);
72 });
73
74 return Recordlist;
75 });