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

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

Working on document-level format editting

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