de34770bb212a1f4fae8c8a9991c1eeb01fefb35
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Resources / Public / JavaScript / Scheduler.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/Scheduler/Scheduler
16 */
17 define(['jquery'], function($) {
18
19 /**
20 *
21 * @type {{}}
22 * @exports TYPO3/CMS/Scheduler/Scheduler
23 */
24 var Scheduler = {};
25
26 var allCheckedStatus = false;
27
28 /**
29 * This method reacts on changes to the task class
30 * It switches on or off the relevant extra fields
31 *
32 * @param {Object} theSelector
33 */
34 Scheduler.actOnChangedTaskClass = function(theSelector) {
35 var taskClass = theSelector.val();
36 taskClass = taskClass.toLowerCase().replace(/\\/g, '-');
37
38 // Hide all extra fields
39 $('.extraFields').hide();
40 // Show only relevant extra fields
41 $('.extra_fields_' + taskClass).show();
42 };
43
44 /**
45 * This method reacts on changes to the type of a task, i.e. single or recurring
46 */
47 Scheduler.actOnChangedTaskType = function() {
48 Scheduler.toggleFieldsByTaskType($(this).val());
49 };
50
51 /**
52 * This method reacts on field changes of all table field for table garbage collection task
53 *
54 * @param {Object} theCheckbox
55 */
56 Scheduler.actOnChangeSchedulerTableGarbageCollectionAllTables = function(theCheckbox) {
57 var $numberOfDays = $('#task_tableGarbageCollection_numberOfDays');
58 var $taskTableGarbageCollectionTable = $('#task_tableGarbageCollection_table');
59 if (theCheckbox.prop('checked')) {
60 $taskTableGarbageCollectionTable.prop('disabled', true);
61 $numberOfDays.prop('disabled', true);
62 } else {
63 // Get number of days for selected table
64 var numberOfDays = parseInt($numberOfDays.val());
65 if (numberOfDays < 1) {
66 var selectedTable = $taskTableGarbageCollectionTable.val();
67 if (typeof(defaultNumberOfDays[selectedTable]) !== 'undefined') {
68 numberOfDays = defaultNumberOfDays[selectedTable];
69 }
70 }
71
72 $taskTableGarbageCollectionTable.prop('disabled', false);
73 if (numberOfDays > 0) {
74 $numberOfDays.prop('disabled', false);
75 }
76 }
77 };
78
79 /**
80 * This methods set the 'number of days' field to the default expire period
81 * of the selected table
82 *
83 * @param {Object} theSelector
84 */
85 Scheduler.actOnChangeSchedulerTableGarbageCollectionTable = function(theSelector) {
86 var $numberOfDays = $('#task_tableGarbageCollection_numberOfDays');
87 if (defaultNumberOfDays[theSelector.val()] > 0) {
88 $numberOfDays.prop('disabled', false);
89 $numberOfDays.val(defaultNumberOfDays[theSelector.val()]);
90 } else {
91 $numberOfDays.prop('disabled', true);
92 $numberOfDays.val(0);
93 }
94 };
95
96 /**
97 * Check or uncheck all checkboxes
98 *
99 * @param {Object} theSelector
100 * @returns {Boolean}
101 */
102 Scheduler.checkOrUncheckAllCheckboxes = function(theSelector) {
103 theSelector.parents('.tx_scheduler_mod1').find(':checkbox').prop('checked', !allCheckedStatus);
104 allCheckedStatus = !allCheckedStatus;
105 return false;
106 };
107
108 /**
109 * Toggle the relevant form fields by task type
110 *
111 * @param {Integer} taskType
112 */
113 Scheduler.toggleFieldsByTaskType = function(taskType) {
114 // Single task option = 1, Recurring task option = 2
115 taskType = parseInt(taskType);
116 $('#task_end_col').toggle(taskType === 2);
117 $('#task_frequency_row').toggle(taskType === 2);
118 };
119
120 /**
121 * Registers listeners
122 */
123 Scheduler.initializeEvents = function() {
124 $('#checkall').on('click', function() {
125 Scheduler.checkOrUncheckAllCheckboxes($(this));
126 });
127
128 $('#task_class').change(function() {
129 Scheduler.actOnChangedTaskClass($(this));
130 });
131
132 $('#task_type').change(Scheduler.actOnChangedTaskType);
133
134 $('#task_tableGarbageCollection_allTables').change(function() {
135 Scheduler.actOnChangeSchedulerTableGarbageCollectionAllTables($(this));
136 });
137
138 $('#task_tableGarbageCollection_table').change(function() {
139 Scheduler.actOnChangeSchedulerTableGarbageCollectionTable($(this));
140 });
141 };
142
143 /**
144 * Initialize default states
145 */
146 Scheduler.initializeDefaultStates = function() {
147 var $taskType = $('#task_type');
148 if ($taskType.length) {
149 Scheduler.toggleFieldsByTaskType($taskType.val());
150 }
151 };
152
153 $(Scheduler.initializeEvents);
154 $(Scheduler.initializeDefaultStates);
155
156 return Scheduler;
157 });