534113455b7be9bb2cd03c7805add4bea332f73a
[Packages/TYPO3.CMS.git] / t3lib / js / extjs / tceforms.js
1 /***************************************************************
2 * extJS for TCEforms
3 *
4 * Copyright notice
5 *
6 * (c) 2009-2011 Steffen Kamper <info@sk-typo3.de>
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 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25
26 Ext.ns('TYPO3');
27
28 // class to manipulate TCEFORMS
29 TYPO3.TCEFORMS = {
30
31 init: function() {
32 Ext.QuickTips.init();
33
34 this.convertDateFieldsToDatePicker();
35 this.convertTextareasResizable();
36 },
37
38 convertDateFieldsToDatePicker: function() {
39 var dateFields = Ext.select("input[id^=tceforms-date]"), minDate, maxDate, lowerMatch, upperMatch;
40 dateFields.each(function(element) {
41 var index = element.dom.id.match(/tceforms-datefield-/) ? 0 : 1;
42 var format = TYPO3.settings.datePickerUSmode ? TYPO3.settings.dateFormatUS : TYPO3.settings.dateFormat;
43 var datepicker = element.next('span'), menu;
44
45 // check for daterange
46 var lowerMatch = element.dom.className.match(/lower-(\d+)\b/);
47 minDate = Ext.isArray(lowerMatch) ? new Date(lowerMatch[1] * 1000) : null;
48 var upperMatch = element.dom.className.match(/upper-(\d+)\b/);
49 maxDate = Ext.isArray(upperMatch) ? new Date(upperMatch[1] * 1000) : null;
50
51 if (index === 0) {
52 menu = new Ext.menu.DateMenu({
53 id: 'p' + element.dom.id,
54 format: format[index],
55 value: Date.parseDate(element.dom.value, format[index]),
56 minDate: minDate,
57 maxDate: maxDate,
58 handler: function(picker, date){
59 var relElement = Ext.getDom(picker.ownerCt.id.substring(1));
60 relElement.value = date.format(format[index]);
61 if (Ext.isFunction(relElement.onchange)) {
62 relElement.onchange.call(relElement);
63 }
64 },
65 listeners: {
66 beforeshow: function(obj) {
67 var relElement = Ext.getDom(obj.picker.ownerCt.id.substring(1));
68 if (relElement.value) {
69 obj.picker.setValue(Date.parseDate(relElement.value, format[index]));
70 }
71 }
72 }
73 });
74 } else {
75 menu = new Ext.ux.menu.DateTimeMenu({
76 id: 'p' + element.dom.id,
77 format: format[index],
78 value: Date.parseDate(element.dom.value, format[index]),
79 minDate: minDate,
80 maxDate: maxDate,
81 listeners: {
82 beforeshow: function(obj) {
83 var relElement = Ext.getDom(obj.picker.ownerCt.id.substring(1));
84 if (relElement.value) {
85 obj.picker.setValue(Date.parseDate(relElement.value, format[index]));
86 }
87 },
88 select: function(picker) {
89 var relElement = Ext.getDom(picker.ownerCt.id.substring(1));
90 relElement.value = picker.getValue().format(format[index]);
91 if (Ext.isFunction(relElement.onchange)) {
92 relElement.onchange.call(relElement);
93 }
94 }
95 }
96 });
97 }
98
99 datepicker.on('click', function(){
100 menu.show(datepicker);
101 });
102 });
103 },
104
105 convertTextareasResizable: function() {
106 var textAreas = Ext.select("textarea[id^=tceforms-textarea-]");
107 textAreas.each(function(element) {
108 if (TYPO3.settings.textareaFlexible) {
109 var elasticTextarea = new Ext.ux.elasticTextArea().applyTo(element.dom.id, {
110 minHeight: 50,
111 maxHeight: TYPO3.settings.textareaMaxHeight
112 });
113 }
114 if (TYPO3.settings.textareaResize) {
115 element.addClass('resizable');
116 var dwrapped = new Ext.Resizable(element.dom.id, {
117 minWidth: 300,
118 minHeight: 50,
119 dynamic: true
120 });
121 }
122 });
123 }
124
125 }
126 Ext.onReady(TYPO3.TCEFORMS.init, TYPO3.TCEFORMS);