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

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

Working on saving a format statement to the config file. This looks like it should work but changes in FormatAction have caused major issues with Document/Node violations. This is because saving required the format statement as a Document rather than a string (which did work). Added a check to GSXML for xmlNodeToString to check that attrs is not null (attrs will be null unless the node is an element).

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