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

Last change on this file since 24417 was 24417, checked in by sjm84, 13 years ago

Tidied up the format manager and removed the need for a separate format servlet

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