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

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