source: main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js@ 22768

Last change on this file since 22768 was 22768, checked in by sjb48, 14 years ago

Few changes to look and feel

File size: 13.5 KB
Line 
1
2console.log("Loading gui_div.js\n");
3
4$(document).ready(function(){
5
6 console.log("Document ready function\n");
7
8 /******************************************/
9 /* DRAGGABLES */
10 /******************************************/
11
12 $(".element_type_gsf_template").draggable({
13 connectToSortable: '#formatStatement',
14 helper: 'clone',
15 revert: 'invalid'
16 });
17
18 $(".element_type_table").draggable({
19 connectToSortable: '.gsf_template',
20 helper: 'clone',
21 revert: 'invalid'
22 });
23
24 $(".element_type_tr").draggable({
25 connectToSortable: '.gsf_table',
26 helper: 'clone',
27 revert: 'invalid'
28 })
29
30 $(".element_type_td").draggable({
31 //connectToSortable: '.td',
32 helper: 'clone',
33 revert: 'invalid'
34 })
35
36 $(".element_type_text").draggable({
37 connectToSortable: '.gsf_otherwise',
38 helper: 'clone',
39 revert: 'invalid'
40 });
41
42 $(".element_type_gsf_choose_metadata").draggable({
43 connectToSortable: '.gsf_template',
44 helper: 'clone',
45 revert: 'invalid'
46 });
47
48 $(".element_type_gsf_metadata").draggable({
49 connectToSortable: '.gsf_choose_metadata, .gsf_template, .gsf_when, .gsf_otherwise, .td',
50 helper: 'clone',
51 revert: 'invalid'
52 });
53
54 $(".element_type_gsf_link").draggable({
55 connectToSortable: '.gsf_template',
56 helper: 'clone',
57 revert: 'invalid'
58 });
59
60 // switch, when, otherwise, icon
61 $(".element_type_gsf_switch").draggable({
62 connectToSortable: '.gsf_template',
63 helper: 'clone',
64 revert: 'invalid'
65 });
66
67 $(".element_type_gsf_when").draggable({
68 connectToSortable: '.gsf_switch',
69 helper: 'clone',
70 revert: 'invalid'
71 });
72
73 $(".element_type_gsf_otherwise").draggable({
74 connectToSortable: '.gsf_switch',
75 helper: 'clone',
76 revert: 'invalid'
77 });
78
79 $(".element_type_gsf_icon").draggable({
80 connectToSortable: '.gsf_link',
81 helper: 'clone',
82 revert: 'invalid'
83 });
84
85
86 /******************************************/
87 /* SORTABLES */
88 /******************************************/
89
90 bind_all_sortables();
91
92 $('#formatStatement').sortable({
93 cursor: 'pointer',
94 tolerance: 'pointer',
95 items: '.gsf_template',
96 placeholder:'placeholder',
97 //'nested':'div'
98 stop: function(event, ui) {
99 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_gsf_template')) { replace_with(ui.item,gsf_template_element); }
100 }
101 });
102
103 $('div.gsf_template').children(".block,.table").slideUp(300);
104});
105
106/*******************************************************************************/
107
108function bind_all_sortables()
109{
110 console.log('function bind_all_sortables()');
111 bind_template_sortable();
112 //bind_table_sortable();
113 //bind_tr_sortable();
114 //bind_td_sortable();
115 bind_choose_metadata_sortable();
116 bind_link_sortable();
117 bind_switch_sortable();
118 bind_when_sortable();
119 bind_otherwise_sortable();
120
121 bind_tables();
122
123 bind_block_mouseover();
124 bind_minmax_remove();
125}
126
127function bind_tables()
128{
129 console.log('function bind_tables()');
130 //$('.tr').resize_tables($(this)); //equalHeights();
131
132
133 $('td').click(function () {
134 console.log('td click');
135 return false;
136 });
137
138 $(".td").resizable({
139 alsoResize: 'parent',
140 //containment: 'parent',
141 handles: 'w,e',
142 stop: function(event, ui) {
143 console.log('Resize table on stop');
144 resize_tables($(this));
145 //$(this).parent().parent().equalHeights();
146 }, });
147
148 $(".droppable").droppable({
149 accept: '.element_type_td',
150 tolerance: 'pointer',
151 activate: function(event, ui) { $(this).addClass("droppable_hl");}, // console.log("droppable activated")},
152 deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); }, // console.log("droppable deactivated")},
153 drop: function(event, ui) {
154 var span = document.createElement("div");
155 span.setAttribute("class","td");
156 span.setAttribute("style","height:50px");
157 span.setAttribute("style","display:block");
158 var td = document.createElement("td");
159 var div = document.createElement("div"); // class=\"td block\" title=\"td-div\"");
160 div.setAttribute("title","td-div");
161 div.setAttribute("class","td block");
162 div.setAttribute("style","margin-left:0px");
163 div.setAttribute("width","25px");
164 td.appendChild(div);
165 div.appendChild(span);
166 var sep = document.createElement("td");
167 sep.setAttribute("class","droppable");
168 sep.setAttribute("width","10px");
169 $(this).after(sep);
170 $(this).after(td);
171 bind_tables();
172 resize_tables($(this));
173 bind_td_sortable();
174 //bind_all_sortables();
175 }
176 });
177
178}
179
180function replace_with(item, me)
181{
182 console.log('function replace_with(item, me)');
183 item.replaceWith(me); //'<div class="element element-txt">This text box has been added!</div>');
184
185 resize_tables(item);
186
187 bind_all_sortables();
188}
189
190function resize_tables(item)
191{
192 console.log('function resize_tables(item)');
193 var max_height = 0;
194 (item.parents('.table')).each(function(index) {
195 $(this).children().children().children().each(function() {
196 var sum_one = 0;
197 var sum_two = 0;
198 $(this).children('.block').each(function() { sum_one = sum_one + $(this).height();
199 $(this).children('.block').each(function() { sum_two = sum_two + $(this).height(); } );
200 console.log("My height is " + $(this).height() + ", sum height 2 is " + sum_two);
201 });
202 console.log("My height is " + $(this).height() + ", sum height 1 is " + sum_one);
203 if (sum_two > max_height)
204 max_height = sum_two;
205 });
206 });
207 equalHeights(item,max_height);
208}
209
210function bind_template_sortable()
211{
212 console.log('function bind_template_sortable()');
213 $('.gsf_template').sortable({
214 'cursor':'pointer',
215 'items':'.table, .gsf_choose_metadata, .gsf_metadata',
216 'placeholder':'placeholder',
217 //'nested':'.gsf:metadata'
218 stop: function(event, ui) {
219 //if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_table')) { replace_with(ui.item, "<table border=\"1\" width=\"100%\" height=\"50px\"><tr><td><div class=\"td block\" title=\"td-div\">XXXXXXXXXXXXXXXXXXXXXXXX</div></td></tr></table>"); }
220 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_table')) { replace_with(ui.item, "<table class=\"table\" border=\"2\"></table>"); }
221 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
222 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
223 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_link')) { replace_with(ui.item, gsf_link_element); }
224 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
225 }
226 });
227
228 $('.gsf_template').click(function () {
229 console.log('gsf_template class click');
230 return false;
231 });
232
233}
234
235function bind_td_sortable()
236{
237 console.log('function bind_td_sortable()');
238 $('.td').sortable({
239 'cursor':'pointer',
240 'tolerance': 'pointer',
241 'items':'.gsf_metadata, .gsf_choose_metadata, .gsf_link, .gsf_switch',
242 'placeholder':'placeholder',
243 //'nested':'.gsf:metadata'
244 receive: function(event, ui) { alert("Attempted to receive"); },
245 stop: function(event, ui) {
246 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
247
248 }
249
250 });
251
252 $('.td').click(function () {
253 console.log('td class click');
254 return false;
255 });
256
257
258
259}
260
261function bind_choose_metadata_sortable()
262{
263 console.log('function bind_choose_metadata_sortable()');
264 $('.gsf_choose_metadata').sortable({
265 'cursor':'pointer',
266 'tolerance': 'fit',
267 'items':'.gsf_metadata',
268 'placeholder':'placeholder',
269 'connectWith':'.gsf_choose_metadata',
270 //'nested':'.gsf:metadata'
271 stop: function(event, ui) {
272 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
273 }
274 });
275}
276
277function bind_link_sortable()
278{
279 console.log('function bind_link_sortable()');
280 $('.gsf_link').sortable({
281 'cursor':'pointer',
282 'tolerance': 'pointer',
283 'items':'.gsf_icon',
284 'placeholder':'placeholder',
285 //'nested':'.gsf:metadata'
286 stop: function(event, ui) {
287 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
288 }
289 });
290}
291
292function bind_switch_sortable()
293{
294 console.log('function bind_switch_sortable()');
295 $('.gsf_switch').sortable({
296 'cursor':'pointer',
297 'tolerance': 'pointer',
298 'items':'.gsf_metadata, .gsf_when, .gsf_otherwise',
299 'placeholder':'placeholder',
300 //'nested':'.gsf:metadata'
301 stop: function(event, ui) {
302 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_when')) { replace_with(ui.item, gsf_when_element); }
303 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_otherwise')) { replace_with(ui.item, gsf_otherwise_element); }
304 }
305 });
306}
307
308function bind_when_sortable()
309{
310 console.log('function bind_when_sortable()');
311 $('.gsf_when').sortable({
312 'cursor':'pointer',
313 'tolerance': 'pointer',
314 'items':'.leaf',
315 'placeholder':'placeholder',
316 //'nested':'.gsf:metadata'
317 stop: function(event, ui) {
318 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
319 }
320 });
321}
322
323function bind_otherwise_sortable()
324{
325 console.log('function bind_otherwise_sortable()');
326 $('.gsf_otherwise').sortable({
327 'cursor':'pointer',
328 'tolerance': 'pointer',
329 'items':'.leaf',
330 'placeholder':'placeholder',
331 //'nested':'.gsf:metadata'
332 stop: function(event, ui) {
333 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
334 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_text')) { replace_with(ui.item, "<input type=\"text\" name=\"rawtextinput\" size=\"10\"/>"); }
335 }
336 });
337}
338
339function bind_block_mouseover()
340{
341 console.log('function bind_block_mouseover()');
342 $(".block").mouseover(function()
343 {
344 $(this).parents().css("border", "");
345 $(this).css("border", "1px solid blue");
346 return false;
347 }).mouseout(function(){
348 $(this).css("border", "");
349 return false;
350 });
351}
352
353function bind_minmax_remove()
354{
355 console.log('function bind_minmax_remove()');
356 $('a.minmax').bind('click', toggleContent);
357 $('a.remove').bind('click', removeContent);
358};
359
360var removeContent = (function () {
361 console.log('var removeContent = (function ()');
362 // this -> a -> td -> tr -> tbody -> table -> div
363 $(this).parent().parent().parent().parent().parent().remove();
364 });
365
366
367var toggleContent = function(e)
368{
369 console.log('var toggleContent = function(e)');
370 console.log('parent: ' + $(this).html());
371 if ($(this).html() == '[+]'){ //targetContent.css('display') == 'none') {
372 $(this).parent().parent().parent().parent().parent().children(".block,.table").slideDown(300);
373 $(this).html('[-]');
374 $(this).removeClass("ui-icon-plusthick");
375 $(this).addClass("ui-icon-minusthick");
376 } else {
377 $(this).parent().parent().parent().parent().parent().children(".block,.table").slideUp(300);
378 $(this).html('[+]');
379 $(this).removeClass("ui-icon-minusthick");
380 $(this).addClass("ui-icon-plusthick");
381 }
382 return false;
383};
384
385function serialize(s)
386{
387 serial = $.SortSerialize(s);
388 alert(serial.hash);
389};
390
391function equalHeights(item, height) {
392 console.log('function equalHeights(item, height)');
393 (item.parents('.table')).each(function(index) {
394 $(this).children().children().children().each(function() {
395 $(this).height(height);
396 $(this).children().height(height);
397 });
398 });
399};
400
Note: See TracBrowser for help on using the repository browser.