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

Last change on this file since 23405 was 23405, checked in by sjb48, 13 years ago

FormatAction constructs message containing format string that is sent to the collection. The message knows the service, and if it is the browse service, then it also knows the classifer list number.

File size: 32.3 KB
Line 
1
2console.log("Loading gui_div.js\n");
3
4var initialised_iframe = "false";
5
6function createFormatStatement()
7{
8
9 var formatDiv = document.getElementById('formatStatement');
10 var formatStatement = innerXHTML(formatDiv);
11 //console.log(formatStatement);
12
13 // find collection name
14
15 var myurl = document.URL;
16 console.log(myurl);
17 var first = myurl.indexOf("&c")+3;
18 var last = myurl.indexOf("&", first);
19
20 var collection_name = myurl.substring(first,last); ///&c=(.*)&/.exec(myurl);
21 console.log(collection_name);
22
23 first = myurl.indexOf("&s")+3;
24 last = myurl.indexOf("&", first);
25
26 var service_name = myurl.substring(first,last);
27 console.log(service_name);
28
29 var classifier_name = null;
30
31 if(service_name == "ClassifierBrowse")
32 {
33 first = myurl.indexOf("&cl")+4;
34 last = myurl.indexOf("&", first);
35
36 classifier_name = myurl.substring(first,last);
37 console.log(classifier_name);
38 }
39
40 //var myurl = 'http://localhost:8080/greenstone3/format?a=s&sa=s&t='+formatStatement;
41
42 //jQuery.post( url, [ data ], [ success(data, textStatus, XMLHttpRequest) ], [ dataType ] )
43
44 // How do I find out my collection name?
45 var post_url = "http://localhost:8080/greenstone3/format?a=f&c=" + collection_name +"&s=" + service_name;
46
47 if(classifier_name != null)
48 post_url = post_url + "&cl=" + classifier_name;
49
50 $.post(post_url, {data: formatStatement}, function(data) {
51 //$('.result').innerHTML = data; //html(data);
52 console.log("Success, we have received data");
53 console.log(data);
54 }, 'html');
55
56/*
57 $.ajax({
58 type: "POST",
59 url: "http://localhost:8080/greenstone3/format?a=s&sa=s",
60 data: formatStatement,
61 processData: false,
62 success: function(data) {
63 //$('.result').html(data);
64 console.log("Success, we have received data");
65 //console.log(data);
66 }
67 });
68*/
69 /*
70 $.ajax({
71 url: myurl,
72 success: function(data) {
73 //$('.result').html(data);
74 console.log("Success, we have received data");
75 console.log(data);
76 }
77 });
78 */
79 //if(formatStatement.hasChildNodes())
80 //{
81 //var formatstring = traverse(formatStatement, "");
82 //console.log(formatstring);
83
84 // var children = $(formatStatement).children('div');
85 // for(var i=0; i < children.length; i++)
86 // traverse(children[i], formatstring)
87
88 /*
89 var children = formatStatement.childNodes; //[]getChildNodes();
90 var current;
91 for(var i = 0; i < formatStatement.childNodes.length; i++)
92 {
93 current = formatStatement.childNodes[i];
94 //console.log(current.nodeName);
95 //console.log(current.nodeType);
96 if(current.nodeName=='DIV')
97 {
98 //console.log(current);
99 //console.log(current.className);
100 var gsf = find_class(current);
101 console.log(gsf);
102 }
103 }
104 */
105 //}
106}
107
108function traverse(node, formatstring)
109 {
110 //console.log("node=("+node.nodeName+","+node.nodeType+")");
111
112 if(node.nodeName=='DIV')
113 {
114 console.log("Found a div" +node.nodeName+","+node.nodeType);
115 formatstring = formatstring + find_class(node);
116 console.log(formatstring);
117 }
118
119 var children = $(node).children();
120 for(var i=0; i < children.length; i++)
121 formatstring = formatstring + traverse(children[i], formatstring);
122
123 return formatstring;
124 }
125
126
127/*
128 console.log("node=("+node.nodeName+","+node.nodeType+")");
129
130 if(node.children.length == 0) //hasChildNodes())
131 {
132 console.log("No children so return");
133 return "";
134 }
135
136 if(node.nodeName=='DIV')
137 {
138 console.log("Found a div");
139 formatstring = formatstring + find_class(node);
140 }
141
142 for(var i = 0; i < node.children.length; i++)
143 return recursiveTraverse(node.children[i], formatstring);
144
145
146 return formatstring;
147 }
148*/
149
150function find_class(current)
151{
152 var classes = current.className.split(' ');
153 var none = "";
154 for(var i = 0; i < classes.length; i++)
155 {
156 switch(classes[i])
157 {
158 case 'gsf_template':
159 return create_gsf_template(current);
160 default:
161 {
162 console.log("Class not found");
163 return none;
164 }
165 }
166 }
167}
168
169function create_gsf_template(current)
170{
171 // find match text which is an input with class match
172 var match = $(current).find('.match')[0].value;
173 console.log(match);
174
175 // find mode text which is an input with class mode
176 var mode = $(current).find('.mode')[0].value;
177 console.log(mode);
178
179 // "<gsf:template match=\"classifierNode\" mode=\"horizontal\">"
180 var gsf = "<gsf:template match=\"" + match + "\"";
181 if(mode != "vertical")
182 gsf = gsf + " mode=\"" + mode + "\"";
183 gsf = gsf + ">";
184
185 return gsf;
186
187}
188
189/*
190$("#iframe").ready(function(){
191 console.log("iframe is ready ...");
192 var iframe = document.getElementById('iframe');
193 var iframe_document = iframe.document;
194
195 if(iframe.contentDocument)
196 {
197 iframe_document = iframe.contentDocument; // For NS6
198 console.log("Chose content document");
199 }
200 else if(iframe.contentWindow)
201 {
202 iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
203 console.log("Chose content window");
204 }
205
206 console.log(iframe_document.documentElement.innerHTML); //document.documentElement.outerHTML
207
208 $(iframe_document.documentElement.innerHTML).find('a').each(function() {
209 console.log("data "+$(this).data('href'));
210 console.log("getAttribute "+$(this).getAttribute('href'));
211 console.log("attr "+$(this).attr('href'));
212 console.log("this.href "+this.href);
213 var original = this.href; //$(this).attr('href');
214 // check if greenstone link ie. starts with format
215 //var original = $(this).data('href');
216 var modified = original.toString().concat("&excerptid=gs_content");
217 console.log(modified);
218 this.href = modified;
219 //$(this).attr('href',modified);
220 //$(this).data('href', modified);
221 //console.log($(this).attr('href'));
222 console.log("data "+$(this).data('href'));
223 console.log("getAttribute "+$(this).getAttribute('href'));
224 console.log("attr "+$(this).attr('href'));
225 console.log("this.href "+this.href);
226 console.log("**********");
227
228 });
229}); */
230/*
231function loadXMLDoc()
232{
233 if (window.XMLHttpRequest)
234 {// code for IE7+, Firefox, Chrome, Opera, Safari
235 xmlhttp=new XMLHttpRequest();
236 }
237 else
238 {// code for IE6, IE5
239 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
240 }
241
242 xmlhttp.onreadystatechange=function()
243 {
244 console.log("state changed to " + xmlhttp.readyState);
245 console.log("status is " + xmlhttp.status);
246 if (xmlhttp.readyState==4 && xmlhttp.status==200)
247 {
248 console.log("get code");
249 console.log(xmlhttp.responseText);
250 document.getElementById("gs_content").innerHTML=xmlhttp.responseText;
251 }
252 }
253
254 xmlhttp.open("GET","http://localhost:8080/greenstone3/format?a=b&rt=s&s=ClassifierBrowse&c=simpleht&cl=CL1&excerptid=gs_content",true);
255 //xmlhttp.open("GET","http://www.cs.waikato.ac.nz",true);
256 //xmlhttp.open("GET","http://wand.net.nz/~sjb48/index.html",true);
257 xmlhttp.send();
258}
259*/
260$(document).ready(function(){
261
262 console.log("Document ready function\n");
263
264 var CURRENT_SELECT_VALUE = "";
265
266 var iframe = document.getElementById('iframe');
267 var iframe_document = iframe.document;
268
269 if(iframe.contentDocument)
270 {
271 iframe_document = iframe.contentDocument; // For NS6
272 console.log("Chose content document");
273 }
274 else if(iframe.contentWindow)
275 {
276 iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
277 console.log("Chose content window");
278 }
279
280 // Edit the hrefs in preview_html - search for <a href="format?a=b&rt=r&s=ClassifierBrowse&c=simpleht&cl=CL1.2">
281 var start_index = 0;
282 var end_index = 0;
283 while(start_index != -1)
284 {
285 start_index = preview_html.indexOf("href=\"format", start_index);
286 console.log("start index = " + start_index);
287 if(start_index != -1)
288 {
289 end_index = preview_html.indexOf("\">", start_index);
290 console.log("end_index = " + end_index);
291 a = preview_html.substring(0,end_index);
292 b = preview_html.substring(end_index);
293 preview_html = a.concat("&excerptid=results", b);
294 console.log(preview_html);
295 start_index = end_index + "&excerptid=results\">".length;
296 }
297 }
298
299 // Split the html code in to three parts
300 var first_index = preview_html.indexOf("<ul id=\"results\"");
301 console.log("First index is "+first_index);
302 var second_index = preview_html.indexOf("</ul>", first_index) + "</ul>".length;
303 console.log("Second index is "+second_index);
304
305 var first_half = preview_html.substring(0, first_index);
306 var iframe_code = preview_html.substring(first_index, second_index);
307 var second_half = preview_html.substring(second_index);
308
309 //$('#my_categories').innerHTML = first_half.concat(second_half);
310 document.getElementById("my_categories").innerHTML = first_half.concat(second_half);
311
312 // Put the content in the iframe
313 if(initialised_iframe == "false")
314 {
315 console.log("Initialised iframe with preview html");
316 console.log(preview_html);
317 iframe_document.open();
318 iframe_document.writeln(iframe_code); //.concat("&excerptid=gs_content"));
319 iframe_document.close();
320 initialised_iframe = "true";
321 }
322
323 /*
324 $(iframe_document.documentElement.innerHTML).find('a').each(function() {
325 console.log("data "+$(this).data('href'));
326 console.log("getAttribute "+this.getAttribute('href'));
327 console.log("attr "+$(this).attr('href'));
328 console.log("this.href "+this.href);
329 var original = this.href; //$(this).attr('href');
330 // check if greenstone link ie. starts with format
331 //var original = $(this).data('href');
332 var modified = original.toString().concat("&excerptid=gs_content");
333 console.log("* *");
334 console.log(modified);
335 console.log("* *");
336 //this.href = modified;
337 //$(this).attr('href',modified);
338 //$(this).data('href', modified);
339 $(this).attr({ 'href': modified });
340 //console.log($(this).attr('href'));
341 console.log("data "+$(this).data('href'));
342 console.log("getAttribute "+this.getAttribute('href'));
343 console.log("attr "+$(this).attr('href'));
344 console.log("this.href "+this.href);
345 console.log("***********************");
346 });
347 */
348
349 /******************************************/
350 /* DRAGGABLES */
351 /******************************************/
352
353 $(".draggable_gsf_template").draggable({
354 cursor: 'crosshair',
355 connectToSortable: '#formatStatement',
356 helper: 'clone',
357 revert: 'invalid'
358 });
359
360 $(".draggable_table").draggable({
361 cursor: 'crosshair',
362 connectToSortable: '.gsf_template',
363 helper: 'clone',
364 revert: 'invalid'
365 });
366
367 $(".draggable_tr").draggable({
368 cursor: 'crosshair',
369 connectToSortable: '.gsf_table',
370 helper: 'clone',
371 revert: 'invalid'
372 })
373
374 $(".draggable_td").draggable({
375 cursor: 'crosshair',
376 //connectToSortable: '.td',
377 helper: 'clone',
378 revert: 'invalid'
379 })
380
381 $(".draggable_gsf_text").draggable({
382 cursor: 'crosshair',
383 connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link, .gsf_choose_metadata, .gsf_default',
384 helper: 'clone',
385 revert: 'invalid'
386 });
387
388 $(".draggable_gsf_choose_metadata").draggable({
389 cursor: 'crosshair',
390 connectToSortable: '.td-div, .gsf_link, .gsf_when, .gsf_otherwise',
391 helper: 'clone',
392 revert: 'invalid'
393 });
394
395 //$(".element_type_gsf_metadata").draggable({
396 $(".draggable_gsf_metadata").draggable({
397 cursor: 'crosshair',
398 connectToSortable: '.gsf_choose_metadata, .gsf_when, .gsf_otherwise, .gsf_link, .td-div',
399 helper: 'clone',
400 revert: 'invalid'
401 });
402
403 $(".draggable_gsf_link").draggable({
404 cursor: 'crosshair',
405 connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link',
406 helper: 'clone',
407 revert: 'invalid'
408 });
409
410 // switch, when, otherwise, icon
411 $(".draggable_gsf_switch").draggable({
412 cursor: 'crosshair',
413 connectToSortable: '.td-div, .gsf_link',
414 helper: 'clone',
415 revert: 'invalid'
416 });
417
418 $(".draggable_gsf_when").draggable({
419 cursor: 'crosshair',
420 connectToSortable: '.gsf_switch',
421 helper: 'clone',
422 revert: 'invalid'
423 });
424
425 $(".draggable_gsf_otherwise").draggable({
426 cursor: 'crosshair',
427 connectToSortable: '.gsf_switch',
428 helper: 'clone',
429 revert: 'invalid'
430 });
431
432 $(".draggable_gsf_icon").draggable({
433 cursor: 'crosshair',
434 connectToSortable: '.td-div, .gsf_link, .gsf_choose, .gsf_when, .gsf_otherwise',
435 helper: 'clone',
436 revert: 'invalid'
437 });
438
439
440 /******************************************/
441 /* SORTABLES */
442 /******************************************/
443
444 bind_td_sortable();
445 bind_all_sortables();
446
447 $('#formatStatement').sortable({
448 cursor: 'pointer',
449 tolerance: 'pointer',
450 items: '.gsf_template',
451 placeholder:'placeholder',
452 //'nested':'div'
453 stop: function(event, ui) {
454 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_gsf_template')) { replace_with(ui.item,gsf_template_element); }
455 }
456 });
457
458 $('div.gsf_template').children(".block,.table").slideUp(300);
459});
460
461/*******************************************************************************/
462
463function bind_all_sortables()
464{
465 console.log('function bind_all_sortables()');
466 bind_template_sortable();
467 //bind_table_sortable();
468 //bind_tr_sortable();
469 //bind_td_sortable();
470 bind_choose_metadata_sortable();
471 bind_link_sortable();
472 bind_switch_sortable();
473 bind_when_sortable();
474 bind_otherwise_sortable();
475
476 bind_tables();
477
478 bind_block_mouseover();
479 bind_minmax_remove();
480}
481
482function bind_tables()
483{
484 console.log('function bind_tables()');
485 //$('.tr').resize_tables($(this)); //equalHeights();
486
487
488 $('td').click(function () {
489 console.log('td click *');
490 return false;
491 });
492
493 $(".td-div").resizable({
494 alsoResize: 'parent',
495 //containment: 'parent',
496 handles: 'w,e',
497 stop: function(event, ui) {
498 console.log('Resize table on stop');
499 resize_tables($(this));
500 //$(this).parent().parent().equalHeights();
501 }, });
502
503 //$(".droppable").sortable({
504 // 'cursor':'pointer',
505 // 'tolerance': 'pointer',
506 // 'items':'.column, .td-div',
507 // 'placeholder':'placeholder'
508 //});
509
510 $(".droppable").droppable({
511 accept: '.element_type_td',
512 tolerance: 'pointer',
513 activate: function(event, ui) { $(this).addClass("droppable_hl");}, // console.log("droppable activated")},
514 deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); }, // console.log("droppable deactivated")},
515 drop: function(event, ui) {
516 //if ($(this).hasClass("ui-draggable"))
517 //if (ui.helper.hasClass("ui-draggable"))
518 //{
519 var neverempty = document.createElement("div");
520 neverempty.setAttribute("class","neverempty block");
521 neverempty.setAttribute("style","height:50px");
522 neverempty.setAttribute("style","display:block");
523 var text = document.createTextNode('NEVER EMPTY');
524 neverempty.appendChild(text);
525 var td = document.createElement("td");
526 var div = document.createElement("div"); // class=\"td block\" title=\"td-div\"");
527 div.setAttribute("title","td-div");
528 div.setAttribute("class","td-div block");
529 div.setAttribute("style","margin-left:0px");
530 div.setAttribute("width","25px");
531 td.appendChild(div);
532 div.appendChild(neverempty);
533 var sep = document.createElement("td");
534 sep.setAttribute("class","droppable");
535 sep.setAttribute("width","10px");
536 $(this).after(sep);
537 $(this).after(td);
538 bind_tables();
539 resize_tables($(this));
540 bind_td_sortable();
541 bind_block_mouseover();
542 //bind_all_sortables();
543 //}
544 //else
545 //{
546 // console.log("Attempting to add");
547 //$(this).appendTo(ui.draggable[0]);
548 // $(this).prepend(ui.draggable[0]);
549 //$(ui.draggable[0]).appendTo($(this));
550 //}
551 }
552 });
553
554}
555
556function replace_with(item, me)
557{
558 // Search me for select
559 if(me.search("select") != -1)
560 {
561 // If select exists, then find CURRENT_SELECT_VALUE
562 var index = me.search(CURRENT_SELECT_VALUE);
563 if(index == -1)
564 console.log("Did not find " + CURRENT_SELECT_VALUE);
565 else
566 console.log("Found " + CURRENT_SELECT_VALUE + " at index " + index);
567 index = index + CURRENT_SELECT_VALUE.length + 1;
568 console.log("Attempt inserting select at new index "+index);
569 a = me.substring(0,index);
570 b = me.substring(index);
571 me = a.concat("selected",b);
572 }
573
574 //console.log('function replace_with(item, me)');
575 item.replaceWith(me); //'<div class="element element-txt">This text box has been added!</div>');
576 //item.find('select').attr("value", CURRENT_SELECT_VALUE);
577
578
579 //if(select != null){
580 // console.log("Attempting to select " + CURRENT_SELECT_VALUE);
581 // console.log("length = "+select.length);
582 // for(index = 0; index < select.length; index++) {
583 // console.log(select[index].value);
584 // if(select[index].value == CURRENT_SELECT_VALUE)
585 // console.log("Found "+CURRENT_SELECT_VALUE+" at index " + index);
586 // select.selectedIndex = index;
587 // }
588 // }
589
590 resize_tables(item);
591
592 bind_all_sortables();
593}
594
595function resize_tables(item)
596{
597 //console.log('function resize_tables(item)');
598 var max_height = 0;
599 (item.parents('.table')).each(function(index) {
600 $(this).children().children().children().each(function() {
601 var sum_one = 0;
602 var sum_two = 0;
603 $(this).children('.block').each(function() { sum_one = sum_one + $(this).height();
604 $(this).children('.block').each(function() { sum_two = sum_two + $(this).height(); } );
605 console.log("My height is " + $(this).height() + ", sum height 2 is " + sum_two);
606 });
607 console.log("My height is " + $(this).height() + ", sum height 1 is " + sum_one);
608 if (sum_two > max_height)
609 max_height = sum_two;
610 });
611 });
612 equalHeights(item,max_height);
613}
614
615function bind_template_sortable()
616{
617 //console.log('function bind_template_sortable()');
618 $('.gsf_template').sortable({
619 'cursor':'pointer',
620 'tolerance': 'pointer',
621 'items':'.table', //.gsf_choose_metadata, .gsf_metadata',
622 'placeholder':'placeholder',
623 //'nested':'.gsf:metadata'
624 stop: function(event, ui) {
625 //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>"); }
626 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_table')) { replace_with(ui.item, "<table class=\"table\" border=\"2\"></table>"); }
627 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
628 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
629 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
630 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
631 }
632 });
633
634 $('.gsf_template').click(function () {
635 console.log('gsf_template class click');
636 return false;
637 });
638
639}
640
641function bind_td_sortable()
642{
643
644 $('tr').sortable({
645 'cursor':'pointer',
646 'tolerance': 'intersect',
647 'items':'.column',
648 'placeholder':'placeholder_td',
649 'connectWith':'column'});
650
651 //$('.column').sortable({
652 // connectWith:['.column'],
653 // placeholder: 'placeholder',
654 // items:'td-div'
655 //});
656
657
658 //$('.column').sortable({
659 // 'cursor':'pointer',
660 // 'tolerance': 'pointer',
661 // 'items':'.td-div',
662 // 'placeholder':'placeholder',
663 // 'connectWith':'.column'
664 //'nested':'.gsf:metadata'
665 //receive: function(event, ui) { alert("Attempted to receive"); },
666 //stop: function(event, ui) {
667 // if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('element_type_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
668
669 //});
670
671 //console.log('function bind_td_sortable()');
672 $('.td-div').sortable({
673 'cursor':'pointer',
674 'tolerance': 'pointer',
675 'items':'.gsf_metadata, .gsf_choose_metadata, .gsf_link, .gsf_switch',
676 'placeholder':'placeholder',
677 //'connectWith':'.td-div',
678 //'nested':'.gsf:metadata'
679 receive: function(event, ui) { alert("Attempted to receive"); },
680 stop: function(event, ui) {
681 // gsf metadata
682 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
683 // gsf choose metadata
684 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
685 // gsf link
686 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
687 // gsf switch
688 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
689
690 }
691
692 });
693
694 $('.td-div').click(function () {
695 //console.log('td class click');
696 return true;
697 });
698
699
700
701}
702
703
704function bind_choose_metadata_sortable()
705{
706 //console.log('function bind_choose_metadata_sortable()');
707 $('.gsf_choose_metadata').sortable({
708 'cursor':'pointer',
709 'tolerance': 'pointer',
710 'items':'.gsf_metadata, .gsf_text, .gsf_default',
711 'placeholder':'placeholder',
712 'connectWith':'.gsf_choose_metadata',
713 //'nested':'.gsf:metadata'
714 stop: function(event, ui) {
715 // gsf metadata
716 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
717 // gsf text
718 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, gsf_text_element); }
719 // gsf default
720 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_default')) { replace_with(ui.item, gsf_default_element); }
721
722 bind_all_sortables();
723 }
724 });
725}
726
727function bind_link_sortable()
728{
729 //console.log('function bind_link_sortable()');
730 $('.gsf_link').sortable({
731 'cursor':'pointer',
732 'tolerance': 'pointer',
733 'items':'.leaf, .gsf_link, .gsf_switch, .gsf_choose',
734 'placeholder':'placeholder',
735 'connectWith':'.gsf_link',
736 //'nested':'.gsf:metadata'
737 stop: function(event, ui) {
738 // gsf icon
739 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
740 // gsf text
741 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, "<input type=\"text\" name=\"rawtextinput\" size=\"10\"/>"); }
742 // gsf metadata
743 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
744 // gsf link
745 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
746 // gsf switch
747 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
748 // gsf choose
749 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
750 }
751 });
752}
753
754function bind_switch_sortable()
755{
756 //console.log('function bind_switch_sortable()');
757 $('.gsf_switch').sortable({
758 'cursor':'pointer',
759 'tolerance': 'pointer',
760 'items':'.gsf_metadata, .gsf_when, .gsf_otherwise, .gsf_text',
761 'placeholder':'placeholder',
762 'connectWith':'.gsf_switch',
763 //'nested':'.gsf:metadata'
764 stop: function(event, ui) {
765 // gsf when
766 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_when')) { replace_with(ui.item, gsf_when_element); }
767 // gsf otherwise
768 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_otherwise')) { replace_with(ui.item, gsf_otherwise_element); }
769 // gsf metadata
770 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
771 // gsf text
772 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, gsf_text_element); }
773 }
774 });
775}
776
777function bind_when_sortable()
778{
779 //console.log('function bind_when_sortable()');
780 $('.gsf_when').sortable({
781 'cursor':'pointer',
782 'tolerance': 'pointer',
783 'items':'.leaf, .gsf_link, .gsf_choose',
784 'placeholder':'placeholder',
785 //'nested':'.gsf:metadata'
786 stop: function(event, ui) {
787 // gsf metadata
788 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
789 // gsf icon
790 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
791 // gsf text
792 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_text')) { replace_with(ui.item, gsf_text_element); }
793 // gsf link
794 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
795 // gsf choose
796 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose')) { replace_with(ui.item, gsf_choose_element); }
797 }
798 });
799}
800
801function bind_otherwise_sortable()
802{
803 //console.log('function bind_otherwise_sortable()');
804 $('.gsf_otherwise').sortable({
805 'cursor':'pointer',
806 'tolerance': 'pointer',
807 'items':'.leaf, .gsf_link, .gsf_choose',
808 'placeholder':'placeholder',
809 //'nested':'.gsf:metadata'
810 stop: function(event, ui) {
811 // gsf metadata
812 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
813 // gsf text
814 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_text')) { replace_with(ui.item, "<input type=\"text\" name=\"rawtextinput\" size=\"10\"/>"); }
815 // gsf icon
816 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_icon')) { replace_with(ui.item, gsf_icon_element); }
817 // gsf link
818 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
819 // gsf choose
820 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose')) { replace_with(ui.item, gsf_choose_element); }
821 }
822 });
823}
824
825function bind_block_mouseover()
826{
827 //console.log('function bind_block_mouseover()');
828 $(".block").mouseover(function()
829 {
830 $(this).parents().css("border", "");
831 $(this).css("border", "2px solid blue");
832 return false;
833 }).mouseout(function(){
834 $(this).css("border", "");
835 return false;
836 });
837}
838
839function bind_minmax_remove()
840{
841 console.log('function bind_minmax_remove()');
842 $('a.minmax').bind('click', toggleContent);
843 $('a.remove').bind('click', removeContent);
844};
845
846var removeContent = (function () {
847 //console.log('var removeContent = (function ()');
848 // this -> a -> td -> tr -> tbody -> table -> div
849 //$(this).parent().parent().parent().parent().parent().remove();
850 $(this).closest(".block").remove();
851 });
852
853
854var toggleContent = function(e)
855{
856 //console.log('var toggleContent = function(e)');
857 console.log('parent: ' + $(this).html());
858 if ($(this).html() == '[+]'){ //targetContent.css('display') == 'none') {
859 //$(this).parent().parent().parent().parent().parent().children(".block,.table").slideDown(300);
860 //$(this).parents().children(".block,.table").stopPropagation().slideDown(300);
861 //var x = $(this).parent().parent().parent().parent().parent();
862 //var y = $(this).parent().parent().parent().parent().parent().children(".block,.table");
863 //var z = $(this).closest(".block").children(".table, .block");
864 $(this).closest(".block").children(".table, .block").slideDown(300);
865 $(this).html('[-]');
866 $(this).removeClass("ui-icon-plusthick");
867 $(this).addClass("ui-icon-minusthick");
868 } else {
869 //$(this).parent().parent().parent().parent().parent().children(".block,.table").slideUp(300);
870 //$(this).parents().children(".block,.table").slideUp(300);
871 $(this).closest(".block").children(".table, .block").slideUp(300);
872 $(this).html('[+]');
873 $(this).removeClass("ui-icon-minusthick");
874 $(this).addClass("ui-icon-plusthick");
875 }
876 return false;
877};
878
879function serialize(s)
880{
881 serial = $.SortSerialize(s);
882 alert(serial.hash);
883};
884
885function equalHeights(item, height) {
886 //console.log('function equalHeights(item, height)');
887 (item.parents('.table')).each(function(index) {
888 $(this).children().children().children().each(function() {
889 $(this).height(height);
890 $(this).children().height(height);
891 });
892 });
893};
894
Note: See TracBrowser for help on using the repository browser.