b96fb6a2552e11d1e340d420498e8df35b2f1fbe
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / mod / scripts.js
1 function toggleElement(elementName) {
2 toggleEl = $(elementName);
3 if (toggleEl.style.display == 'none') {
4 openLeaf(elementName);
5 } else {
6 closeLeaf(elementName);
7 }
8 }
9
10 function openLeaf(elementName) {
11 if ($(elementName).style.display == 'none') {
12 img = $('img_'+elementName);
13 if (img) img.src = minusSrc;
14 new Effect.SlideDown(elementName, {duration: 0.1});
15 }
16 }
17
18 function closeLeaf(elementName) {
19 if ($(elementName).style.display != 'none') {
20 img = $('img_'+elementName);
21 if (img) img.src = plusSrc;
22 new Effect.SlideUp(elementName, {duration: 0.1});
23 }
24 }
25
26 function toggleHelp(elementName) {
27 toggleEl = $(elementName);
28 if (toggleEl.style.display == 'none') {
29 new Effect.BlindDown(elementName, {duration: 0.1});
30 } else {
31 new Effect.BlindUp(elementName, {duration: 0.1});
32 }
33 }
34
35
36 function toggleAllLeafs() {
37 var iconUrl = expandSrc;
38 var label = labelExpand;
39
40 if (!allOpen) {
41 iconUrl = collapseSrc;
42 label = labelCollapse;
43 }
44
45 Element.setStyle('collapseExpandToggle', {backgroundImage: 'url('+iconUrl+')'});
46 $('collapseExpandToggle').innerHTML = label;
47
48 $$('.subLeaf').each(function(item, index) {
49 if (allOpen) {
50 closeLeaf(item.id);
51 } else {
52 openLeaf(item.id);
53 }
54 });
55
56 allOpen = !allOpen;
57 }
58
59 function sendForm(formId) {
60 var elements = $(formId).elements;
61 var ajaxParameters = {saveData: true};
62 for (var i = 0; i < elements.length; i++) {
63 var el = elements.item(i);
64 switch (el.type) {
65 case 'text':
66 ajaxParameters[el.name] = el.value;
67 break;
68 case 'checkbox':
69 ajaxParameters[el.name] = (el.checked == true) ? 1 : 0;
70 break;
71 }
72 };
73
74 loadModuleContent(elements.categoryMain.value, elements.categorySub.value, ajaxParameters);
75 }
76
77 function sendMethodForm(formId, module, method, callBack) {
78 var elements = $(formId).elements;
79 var ajaxParameters = {};
80 for (var i = 0; i < elements.length; i++) {
81 var el = elements.item(i);
82 switch (el.type) {
83 case 'checkbox':
84 ajaxParameters[el.name] = (el.checked == true) ? 1 : 0;
85 break;
86 case 'text':
87 default:
88 ajaxParameters[el.name] = el.value;
89 break;
90 }
91 };
92
93 executeMethod(module, method, ajaxParameters, callBack);
94 return false;
95 }
96
97 function doSearch() {
98 searchString = $('treeFilter').value;
99 $$('.tree_item').each(function(item, index) { item.setStyle({'fontWeight': 'normal', backgroundColor: '#fff'}) });
100 $$('.deliverable-box').each(function(item, index) { item.setStyle({backgroundColor: ''}) });
101
102 if (searchString.length >= 2) {
103 $('filterStatus').innerHTML = '';
104 executeMethod('setup', 'searchCategories', {'searchString': searchString}, processSearch);
105 } else {
106 $('filterStatus').innerHTML = '';
107 }
108 }
109
110 function processSearch(transport) {
111 var results = eval('('+transport.responseText+')');
112
113 // open the main cat
114 if (results.resultCount > 0) {
115 for (property in results.catMain) {
116 openLeaf(property);
117 }
118
119 // highlight the subcat where something was found
120 for (property in results.catSub) {
121 $('item_'+property).setStyle({fontWeight: 'bold', backgroundColor: '#99ff99'});
122
123
124 results.catSub[property]._each(function(item, index) {
125 console.debug($('container_'+item['deliverable']));
126 console.debug('container_'+item['deliverable']);
127 $('container_'+item['deliverable']).setStyle({backgroundColor: '#99ff99'});
128 });
129 }
130 }
131
132 $('filterStatus').innerHTML = results.resultMessage;
133 }
134
135 /**
136 * Sends an AJAX request and posts needed parameters to the server.
137 * The result replaces the exting content with a fade effect.
138 */
139 function loadModuleContent(catMain, catSub, extraParameters) {
140 var ajaxParameters = {
141 ajax: 1,
142 categoryMain: catMain,
143 categorySub: catSub
144 };
145
146 if (extraParameters) {
147 ajaxParameters = $H(ajaxParameters).merge(extraParameters).toObject();
148 }
149
150 new Ajax.Request('../../typo3/install/index.php', {
151 method: 'post',
152 parameters: ajaxParameters,
153 onSuccess: function(transport) {
154 new Effect.Fade('moduleContent', {duration: 0.2, afterFinish: function() {
155 $('moduleContent').innerHTML = transport.responseText;
156 new Effect.Appear('moduleContent', {duration: 0.2});
157 }});
158 }
159 });
160 }
161
162 function executeMethod(module, method, extraParameters, callBack) {
163 var ajaxParameters = {
164 ajax: 1,
165 module: module,
166 method: method
167 };
168
169 if (extraParameters) {
170 ajaxParameters = $H(ajaxParameters).merge(extraParameters).toObject();
171 }
172
173 new Ajax.Request('../../typo3/install/index.php', {
174 method: 'get',
175 parameters: ajaxParameters,
176 onSuccess: function(transport) {
177 if (callBack) {
178 callBack(transport);
179 }
180 }
181 });
182 }
183
184 function displayMethodResult(data) {
185 console.debug(data);
186 if (data.request.parameters.target) {
187 $(data.request.parameters.target).innerHTML = data.responseText;
188 } else {
189 // console.debug(data.responseText);
190 }
191 }
192
193 /**
194 * This function takes a list of checkboxes (identified by their ID)
195 * and toggles them on or off depeding on the value of the flag
196 */
197 function toggleCheckboxes(checkboxList, flag) {
198 for (i = 0; i < checkboxList.length; i++) {
199 $(checkboxList[i]).checked = flag;
200 }
201 }
202
203 allOpen = false;
204
205 // add event observers
206 Event.observe(window, 'load', function() {
207 new Form.Element.DelayedObserver('treeFilter', 0.2, doSearch);
208 });