c50ac921811ceb80a2737bfc2442523d30767db8
[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 $min = intval($params['fieldConfig']['min']);
52 $max = intval($params['fieldConfig']['max']);
53 $elementType = $params['fieldConfig']['type'];
54 $step = $params['wConf']['step'] ? $params['wConf']['step'] : 1;
55 $width = intval($params['wConf']['width']) ? intval($params['wConf']['width']) : 400;
56
57 $type = 'null';
58 if (isset($params['fieldConfig']['eval'])) {
59 $eval = t3lib_div::trimExplode(',', $params['fieldConfig']['eval'], TRUE);
60 if (in_array('time', $eval)) {
61 $type = 'time';
62 $value = (int)$value;
63 } elseif (in_array('int', $eval)) {
64 $type = 'int';
65 $value = (int)$value;
66 } elseif (in_array('double2', $eval)) {
67 $type = 'double';
68 $value = (double)$value;
69 }
70 }
71 if (isset($params['fieldConfig']['items'])) {
72 $type = 'array';
73 $value = (int)$value;
74 }
75 $callback = $params['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
76 $getField = $params['fieldChangeFunc']['typo3form.fieldGet'];
77 $id = 'slider-' . $params['md5ID'];
78 $contents = '<div id="' . $id . '"></div>';
79 $js = '
80 new TYPO3.Components.TcaValueSlider({
81 minValue: ' . $min . ',
82 maxValue: ' . $max . ',
83 value: ' . $value . ',
84 increment: ' . $step . ',
85 renderTo: "' . $id . '",
86 itemName: "' . $itemName . '",
87 changeCallback: "' . $callback . '",
88 getField: "' . $getField . '",
89 width: "' . $width . '",
90 type: "' . $type . '",
91 elementType: "' . $elementType . '"
92 });
93 ';
94 /** @var $pageRenderer t3lib_pageRenderer */
95 $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
96 $pageRenderer->addExtOnReadyCode($js);
97
98 return $contents;
99 }
100 }
101
102
103 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['classes/t3lib/tceforms/class.t3lib_tceforms_valueslider.php'])) {
104 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['classes/t3lib/tceforms/class.t3lib_tceforms_valueslider.php']);
105 }
106
107 ?>