[BUGFIX][!!!] Slider wizard misuses "max" property
[Packages/TYPO3.CMS.git] / t3lib / tceforms / class.t3lib_tceforms_valueslider.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Steffen Ritter <info@steffen-ritter.net>
6 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
19 *
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * TCEforms wizard for rendering an AJAX selector for records
30 *
31 * @author Steffen Kamper <steffen@typo3.org>
32 */
33
34 class t3lib_TCEforms_ValueSlider {
35
36 /**
37 * Renders the slider value wizard
38 *
39 * @param array $params
40 * @param t3lib_TCEforms $pObj
41 * @return string
42 */
43 function renderWizard(&$params, &$pObj) {
44
45 $jsPath = '../t3lib/js/extjs/components/slider/';
46 $pObj->loadJavascriptLib($jsPath . 'ValueSlider.js');
47
48 $field = $params['field'];
49 $value = $params['row'][$field];
50 $itemName = $params['itemName'];
51 // Set default values (which correspond to those of the JS component)
52 $min = 0;
53 $max = 10000;
54 // Use the range property, if defined, to set min and max values
55 if (isset($params['fieldConfig']['range'])) {
56 $min = isset($params['fieldConfig']['range']['lower']) ? intval($params['fieldConfig']['range']['lower']) : 0;
57 $max = isset($params['fieldConfig']['range']['upper']) ? intval($params['fieldConfig']['range']['upper']) : 10000;
58 }
59 $elementType = $params['fieldConfig']['type'];
60 $step = $params['wConf']['step'] ? $params['wConf']['step'] : 1;
61 $width = intval($params['wConf']['width']) ? intval($params['wConf']['width']) : 400;
62
63 $type = 'null';
64 if (isset($params['fieldConfig']['eval'])) {
65 $eval = t3lib_div::trimExplode(',', $params['fieldConfig']['eval'], TRUE);
66 if (in_array('time', $eval)) {
67 $type = 'time';
68 $value = (int)$value;
69 } elseif (in_array('int', $eval)) {
70 $type = 'int';
71 $value = (int)$value;
72 } elseif (in_array('double2', $eval)) {
73 $type = 'double';
74 $value = (double)$value;
75 }
76 }
77 if (isset($params['fieldConfig']['items'])) {
78 $type = 'array';
79 $value = (int)$value;
80 }
81 $callback = $params['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
82 $getField = $params['fieldChangeFunc']['typo3form.fieldGet'];
83 $id = 'slider-' . $params['md5ID'];
84 $contents = '<div id="' . $id . '"></div>';
85 $js = '
86 new TYPO3.Components.TcaValueSlider({
87 minValue: ' . $min . ',
88 maxValue: ' . $max . ',
89 value: ' . $value . ',
90 increment: ' . $step . ',
91 renderTo: "' . $id . '",
92 itemName: "' . $itemName . '",
93 changeCallback: "' . $callback . '",
94 getField: "' . $getField . '",
95 width: "' . $width . '",
96 type: "' . $type . '",
97 elementType: "' . $elementType . '"
98 });
99 ';
100 /** @var $pageRenderer t3lib_pageRenderer */
101 $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
102 $pageRenderer->addExtOnReadyCode($js);
103
104 return $contents;
105 }
106 }
107
108
109 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['classes/t3lib/tceforms/class.t3lib_tceforms_valueslider.php'])) {
110 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['classes/t3lib/tceforms/class.t3lib_tceforms_valueslider.php']);
111 }
112
113 ?>