35db469b9f93a238d7a7fadecd02ec54d9a62e2f
[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 doSearch() {
78 searchString = $('treeFilter').value;
79 $$('.tree_item').each(function(item, index) { item.setStyle({'fontWeight': 'normal', backgroundColor: '#fff'}) });
80 $$('.deliverable-box').each(function(item, index) { item.setStyle({backgroundColor: ''}) });
81
82 if (searchString.length >= 2) {
83 $('filterStatus').innerHTML = '';
84 executeMethod('setup', 'searchCategories', {'searchString': searchString}, processSearch);
85 } else {
86 $('filterStatus').innerHTML = '';
87 }
88 }
89
90 function processSearch(transport) {
91 var results = eval('('+transport.responseText+')');
92
93 // open the main cat
94 if (results.resultCount > 0) {
95 for (property in results.catMain) {
96 openLeaf(property);
97 }
98
99 // highlight the subcat where something was found
100 for (property in results.catSub) {
101 $('item_'+property).setStyle({fontWeight: 'bold', backgroundColor: '#99ff99'});
102
103
104 results.catSub[property]._each(function(item, index) {
105 console.debug($('container_'+item['deliverable']));
106 console.debug('container_'+item['deliverable']);
107 $('container_'+item['deliverable']).setStyle({backgroundColor: '#99ff99'});
108 });
109 }
110 }
111
112 $('filterStatus').innerHTML = results.resultMessage;
113 }
114
115 /**
116 * Sends an AJAX request and posts needed parameters to the server.
117 * The result replaces the exting content with a fade effect.
118 */
119 function loadModuleContent(catMain, catSub, extraParameters) {
120 var ajaxParameters = {
121 ajax: 1,
122 categoryMain: catMain,
123 categorySub: catSub
124 };
125
126 if (extraParameters) {
127 ajaxParameters = $H(ajaxParameters).merge(extraParameters).toObject();
128 }
129
130 new Ajax.Request('../../typo3/install/index.php', {
131 method: 'post',
132 parameters: ajaxParameters,
133 onSuccess: function(transport) {
134 new Effect.Fade('moduleContent', {duration: 0.2, afterFinish: function() {
135 $('moduleContent').innerHTML = transport.responseText;
136 new Effect.Appear('moduleContent', {duration: 0.2});
137 }});
138 }
139 });
140 }
141
142 function executeMethod(module, method, extraParameters, callBack) {
143 var ajaxParameters = {
144 ajax: 1,
145 module: module,
146 method: method
147 };
148
149 if (extraParameters) {
150 ajaxParameters = $H(ajaxParameters).merge(extraParameters).toObject();
151 }
152
153 new Ajax.Request('../../typo3/install/index.php', {
154 method: 'get',
155 parameters: ajaxParameters,
156 onSuccess: function(transport) {
157 if (callBack) {
158 callBack(transport);
159 }
160 }
161 });
162 }
163
164 allOpen = false;
165
166 // add event observers
167 Event.observe(window, 'load', function() {
168 new Form.Element.DelayedObserver('treeFilter', 0.2, doSearch);
169 });