3cc6419af01d8ecf826449df2fbcb17bc4258982
[Packages/TYPO3.CMS.git] / typo3 / sysext / taskcenter / Resources / Public / JavaScript / Taskcenter.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/Taskcenter/Taskcenter
16 */
17 define(['jquery', 'jquery-ui/sortable'], function($) {
18 'use strict';
19
20 /**
21 *
22 * @type {{}}
23 * @exports TYPO3/CMS/Taskcenter/Taskcenter
24 */
25 var Taskcenter = {};
26
27 /**
28 *
29 */
30 Taskcenter.resizeIframe = function() {
31 var $listFrame = $('#list_frame');
32 if ($listFrame.length > 0) {
33 $listFrame.ready(function() {
34 var parent = $('#typo3-docbody');
35 var parentHeight = parent.height();
36 var parentWidth = parent.width() - $('#taskcenter-menu').width() - 61;
37 $listFrame.css({height: parentHeight + 'px', width: parentWidth + 'px'});
38
39 $(window).on('resize', function() {
40 Taskcenter.resizeIframe();
41 });
42 });
43 }
44 };
45
46 /**
47 *
48 * @param {Object} element
49 */
50 Taskcenter.doCollapseOrExpand = function(element) {
51 var itemParent = element.parent();
52 var item = element.next('div').next('div').next('div').next('div');
53 var state = itemParent.hasClass('expanded') ? 1 : 0;
54 itemParent.toggleClass('expanded', state);
55 itemParent.toggleClass('collapsed', !state);
56 item.toggle(state);
57 if (state) {
58 element.find('i.fa').removeClass('fa-caret-down').addClass('fa-caret-up');
59 } else {
60 element.find('i.fa').removeClass('fa-caret-up').addClass('fa-caret-down');
61 }
62
63 $.ajax({
64 url: TYPO3.settings.ajaxUrls['taskcenter_collapse'],
65 type: 'post',
66 cache: false,
67 data: {
68 'item': itemParent.prop('id'),
69 'state': state
70 }
71 });
72 };
73
74 /**
75 *
76 */
77 Taskcenter.initializeSorting = function() {
78 $('#task-list').sortable({
79 update: function(event, ui) {
80 $.ajax({
81 url: TYPO3.settings.ajaxUrls['taskcenter_sort'],
82 type: 'post',
83 cache: false,
84 data: {
85 'data': $(this).sortable('serialize', {
86 key: 'task-list[]',
87 expression: /[=_](.+)/
88 })
89 }
90 });
91 }
92 });
93 };
94
95 /**
96 * Register listeners
97 */
98 Taskcenter.initializeEvents = function() {
99 $('#taskcenter-menu').find('.down').on('click', function() {
100 Taskcenter.doCollapseOrExpand($(this));
101 });
102
103 Taskcenter.resizeIframe();
104 Taskcenter.initializeSorting();
105 };
106
107 $(Taskcenter.initializeEvents);
108
109 return Taskcenter;
110 });