[BUGFIX] Scheduler: Correctly toggle results on task type change 39/45239/6
authorJoerg Kummer <service@enobe.de>
Mon, 14 Dec 2015 15:11:04 +0000 (16:11 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 16 Dec 2015 18:13:54 +0000 (19:13 +0100)
Adapt JS and HTML to solve toggle on load and change task type.

Resolves: #72213
Releases: master
Change-Id: Idb4c964c42cb8bd408ebd98a528a603f1a0bead1
Reviewed-on: https://review.typo3.org/45239
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/Resources/Public/JavaScript/Scheduler.js

index e6e9bba..5c9285d 100644 (file)
@@ -798,7 +798,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
         $label = '<label for="tceforms-datetimefield-task_start">' . BackendUtility::wrapInHelp($this->cshKey, 'task_start', $this->getLanguageService()->getLL('label.start')) . '</label>';
         $value = ($taskInfo['start'] > 0 ? strftime($dateFormat, $taskInfo['start']) : '');
         $table[] =
-            '<div class="form-section"><div class="row"><div class="form-group col-sm-6">'
+            '<div class="form-section"><div class="row"><div class="form-group col-sm-6" id="task_start_col">'
                 . $label
                 . '<div class="form-control-wrap">'
                     . '<div class="input-group" id="tceforms-datetimefield-task_start_row-wrapper">'
@@ -814,7 +814,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
         $value = ($taskInfo['end'] > 0 ? strftime($dateFormat, $taskInfo['end']) : '');
         $label = '<label for="tceforms-datetimefield-task_end">' . $this->getLanguageService()->getLL('label.end') . '</label>';
         $table[] =
-            '<div class="form-group col-sm-6">'
+            '<div class="form-group col-sm-6" id="task_end_col">'
                 . BackendUtility::wrapInHelp($this->cshKey, 'task_end', $label)
                 . '<div class="form-control-wrap">'
                     . '<div class="input-group" id="tceforms-datetimefield-task_end_row-wrapper">'
index c18bbf2..de34770 100644 (file)
@@ -42,18 +42,10 @@ define(['jquery'], function($) {
        };
 
        /**
-        * This method reacts on changes to the type of a task, i.e. single or recurring,
-        * by showing or hiding the relevant form fields
-        *
-        * @param {Object} theSelector
+        * This method reacts on changes to the type of a task, i.e. single or recurring
         */
-       Scheduler.actOnChangedTaskType = function(theSelector) {
-               // Get task type from selected value, or set default value
-               // Single taskType = 1, Recurring task = 0
-               var taskType = parseInt(theSelector.val()) == 1 ? 0 : 1;
-               $('#task_end_row').toggle(taskType);
-               $('#task_frequency_row').toggle(taskType);
-               $('#task_multiple_row').toggle(taskType);
+       Scheduler.actOnChangedTaskType = function() {
+               Scheduler.toggleFieldsByTaskType($(this).val());
        };
 
        /**
@@ -114,6 +106,18 @@ define(['jquery'], function($) {
        };
 
        /**
+        * Toggle the relevant form fields by task type
+        *
+        * @param {Integer} taskType
+        */
+       Scheduler.toggleFieldsByTaskType = function(taskType) {
+               // Single task option = 1, Recurring task option = 2
+               taskType = parseInt(taskType);
+               $('#task_end_col').toggle(taskType === 2);
+               $('#task_frequency_row').toggle(taskType === 2);
+       };
+
+       /**
         * Registers listeners
         */
        Scheduler.initializeEvents = function() {
@@ -125,9 +129,7 @@ define(['jquery'], function($) {
                        Scheduler.actOnChangedTaskClass($(this));
                });
 
-               $('#task_type').change(function() {
-                       Scheduler.actOnChangedTaskType($(this));
-               });
+               $('#task_type').change(Scheduler.actOnChangedTaskType);
 
                $('#task_tableGarbageCollection_allTables').change(function() {
                        Scheduler.actOnChangeSchedulerTableGarbageCollectionAllTables($(this));
@@ -138,7 +140,18 @@ define(['jquery'], function($) {
                });
        };
 
+       /**
+        * Initialize default states
+        */
+       Scheduler.initializeDefaultStates = function() {
+               var $taskType = $('#task_type');
+               if ($taskType.length) {
+                       Scheduler.toggleFieldsByTaskType($taskType.val());
+               }
+       };
+
        $(Scheduler.initializeEvents);
+       $(Scheduler.initializeDefaultStates);
 
        return Scheduler;
 });