95ddc8720175c3b0b935289eda0cae7d8b79ce07
[Packages/TYPO3.CMS.git] / t3lib / js / extjs / tceforms.js
1 /***************************************************************
2 * extJS for TCEforms
3 *
4 * $Id$
5 *
6 * Copyright notice
7 *
8 * (c) 2009-2011 Steffen Kamper <info@sk-typo3.de>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 Ext.ns('TYPO3');
29
30 // class to manipulate TCEFORMS
31 TYPO3.TCEFORMS = {
32
33 init: function() {
34 Ext.QuickTips.init();
35
36 this.convertDateFieldsToDatePicker();
37 this.convertTextareasResizable();
38 },
39
40 convertDateFieldsToDatePicker: function() {
41 var dateFields = Ext.select("input[id^=tceforms-date]"), minDate, maxDate, lowerMatch, upperMatch;
42 dateFields.each(function(element) {
43 var index = element.dom.id.match(/tceforms-datefield-/) ? 0 : 1;
44 var format = TYPO3.settings.datePickerUSmode ? TYPO3.settings.dateFormatUS : TYPO3.settings.dateFormat;
45
46 var datepicker = element.next('span');
47
48 // check for daterange
49 var lowerMatch = element.dom.className.match(/lower-(\d+)\b/);
50 minDate = Ext.isArray(lowerMatch) ? new Date(lowerMatch[1] * 1000) : null;
51 var upperMatch = element.dom.className.match(/upper-(\d+)\b/);
52 maxDate = Ext.isArray(upperMatch) ? new Date(upperMatch[1] * 1000) : null;
53
54 var menu = new Ext.menu.DateMenu({
55 id: 'p' + element.dom.id,
56 format: format[index],
57 value: Date.parseDate(element.dom.value, format[index]),
58 minDate: minDate,
59 maxDate: maxDate,
60 handler: function(picker, date){
61 var relElement = Ext.getDom(picker.ownerCt.id.substring(1));
62 relElement.value = date.format(format[index]);
63 if (Ext.isFunction(relElement.onchange)) {
64 relElement.onchange.call(relElement);
65 }
66 },
67 listeners: {
68 beforeshow: function(obj) {
69 var relElement = Ext.getDom(obj.picker.ownerCt.id.substring(1));
70 if (relElement.value) {
71 obj.picker.setValue(Date.parseDate(relElement.value, format[index]));
72 }
73 }
74 }
75 });
76
77 datepicker.on('click', function(){
78 menu.show(datepicker);
79 });
80 });
81 },
82
83 convertTextareasResizable: function() {
84 var textAreas = Ext.select("textarea[id^=tceforms-textarea-]");
85 textAreas.each(function(element) {
86 if (TYPO3.settings.textareaFlexible) {
87 var elasticTextarea = new Ext.ux.elasticTextArea().applyTo(element.dom.id, {
88 minHeight: 50,
89 maxHeight: TYPO3.settings.textareaMaxHeight
90 });
91 }
92 if (TYPO3.settings.textareaResize) {
93 element.addClass('resizable');
94 var dwrapped = new Ext.Resizable(element.dom.id, {
95 minWidth: 300,
96 minHeight: 50,
97 maxHeight: TYPO3.settings.textareaMaxHeight,
98 dynamic: true
99 });
100 }
101 });
102 }
103
104 }
105 Ext.onReady(TYPO3.TCEFORMS.init, TYPO3.TCEFORMS);