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

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

Oran code for supporting format changes to document.

File size: 32.8 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 /*
384 var iframe = document.getElementById('iframe');
385 var iframe_document = iframe.document;
386
387 if(iframe.contentDocument)
388 {
389 iframe_document = iframe.contentDocument; // For NS6
390 console.log("Chose content document");
391 }
392 else if(iframe.contentWindow)
393 {
394 iframe_document = iframe.contentWindow.document; // For IE5.5 and IE6
395 console.log("Chose content window");
396 }
397
398 // Edit the hrefs in preview_html - search for <a href="format?a=b&rt=r&s=ClassifierBrowse&c=simpleht&cl=CL1.2">
399 var start_index = 0;
400 var end_index = 0;
401 while(start_index != -1)
402 {
403 start_index = preview_html.indexOf("href=\"format", start_index);
404 console.log("start index = " + start_index);
405 if(start_index != -1)
406 {
407 end_index = preview_html.indexOf("\">", start_index);
408 console.log("end_index = " + end_index);
409 a = preview_html.substring(0,end_index);
410 b = preview_html.substring(end_index);
411 preview_html = a.concat("&excerptid=results", b);
412 console.log(preview_html);
413 start_index = end_index + "&excerptid=results\">".length;
414 }
415 }
416
417 // Split the html code in to three parts
418 var first_index = preview_html.indexOf("<ul id=\"results\"");
419 console.log("First index is "+first_index);
420 var second_index = preview_html.indexOf("</ul>", first_index) + "</ul>".length;
421 console.log("Second index is "+second_index);
422
423 var first_half = preview_html.substring(0, first_index);
424 var iframe_code = preview_html.substring(first_index, second_index);
425 var second_half = preview_html.substring(second_index);
426
427 //$('#my_categories').innerHTML = first_half.concat(second_half);
428 document.getElementById("my_categories").innerHTML = first_half.concat(second_half);
429
430 // Put the content in the iframe
431 if(initialised_iframe == "false")
432 {
433 console.log("Initialised iframe with preview html");
434 console.log(preview_html);
435 iframe_document.open();
436 iframe_document.writeln(iframe_code); //.concat("&excerptid=gs_content"));
437 iframe_document.close();
438 initialised_iframe = "true";
439 }
440 */
441
442 /*
443 $(iframe_document.documentElement.innerHTML).find('a').each(function() {
444 console.log("data "+$(this).data('href'));
445 console.log("getAttribute "+this.getAttribute('href'));
446 console.log("attr "+$(this).attr('href'));
447 console.log("this.href "+this.href);
448 var original = this.href; //$(this).attr('href');
449 // check if greenstone link ie. starts with format
450 //var original = $(this).data('href');
451 var modified = original.toString().concat("&excerptid=gs_content");
452 console.log("* *");
453 console.log(modified);
454 console.log("* *");
455 //this.href = modified;
456 //$(this).attr('href',modified);
457 //$(this).data('href', modified);
458 $(this).attr({ 'href': modified });
459 //console.log($(this).attr('href'));
460 console.log("data "+$(this).data('href'));
461 console.log("getAttribute "+this.getAttribute('href'));
462 console.log("attr "+$(this).attr('href'));
463 console.log("this.href "+this.href);
464 console.log("***********************");
465 });
466 */
467
468 /******************************************/
469 /* DRAGGABLES */
470 /******************************************/
471
472 $(".draggable_gsf_template").draggable({
473 cursor: 'crosshair',
474 connectToSortable: '#formatStatement',
475 helper: 'clone',
476 revert: 'invalid'
477 });
478
479 $(".draggable_table").draggable({
480 cursor: 'crosshair',
481 connectToSortable: '.gsf_template',
482 helper: 'clone',
483 revert: 'invalid'
484 });
485
486 $(".draggable_tr").draggable({
487 cursor: 'crosshair',
488 connectToSortable: '.gsf_table',
489 helper: 'clone',
490 revert: 'invalid'
491 })
492
493 $(".draggable_td").draggable({
494 cursor: 'crosshair',
495 //connectToSortable: '.td',
496 helper: 'clone',
497 revert: 'invalid'
498 })
499
500 $(".draggable_gsf_text").draggable({
501 cursor: 'crosshair',
502 connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link, .gsf_choose_metadata, .gsf_default',
503 helper: 'clone',
504 revert: 'invalid'
505 });
506
507 $(".draggable_gsf_choose_metadata").draggable({
508 cursor: 'crosshair',
509 connectToSortable: '.td-div, .gsf_link, .gsf_when, .gsf_otherwise',
510 helper: 'clone',
511 revert: 'invalid'
512 });
513
514 //$(".element_type_gsf_metadata").draggable({
515 $(".draggable_gsf_metadata").draggable({
516 cursor: 'crosshair',
517 connectToSortable: '.gsf_choose_metadata, .gsf_when, .gsf_otherwise, .gsf_link, .td-div',
518 helper: 'clone',
519 revert: 'invalid'
520 });
521
522 $(".draggable_gsf_link").draggable({
523 cursor: 'crosshair',
524 connectToSortable: '.td-div, .gsf_when, .gsf_otherwise, .gsf_link',
525 helper: 'clone',
526 revert: 'invalid'
527 });
528
529 // switch, when, otherwise, icon
530 $(".draggable_gsf_switch").draggable({
531 cursor: 'crosshair',
532 connectToSortable: '.td-div, .gsf_link',
533 helper: 'clone',
534 revert: 'invalid'
535 });
536
537 $(".draggable_gsf_when").draggable({
538 cursor: 'crosshair',
539 connectToSortable: '.gsf_switch',
540 helper: 'clone',
541 revert: 'invalid'
542 });
543
544 $(".draggable_gsf_otherwise").draggable({
545 cursor: 'crosshair',
546 connectToSortable: '.gsf_switch',
547 helper: 'clone',
548 revert: 'invalid'
549 });
550
551 $(".draggable_gsf_icon").draggable({
552 cursor: 'crosshair',
553 connectToSortable: '.td-div, .gsf_link, .gsf_choose, .gsf_when, .gsf_otherwise',
554 helper: 'clone',
555 revert: 'invalid'
556 });
557
558
559 /******************************************/
560 /* SORTABLES */
561 /******************************************/
562
563 bind_td_sortable();
564 bind_all_sortables();
565
566 $('#formatStatement').sortable({
567 cursor: 'pointer',
568 tolerance: 'pointer',
569 items: '.gsf_template',
570 placeholder:'placeholder',
571 //'nested':'div'
572 stop: function(event, ui) {
573 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('css_gsf_template')) { replace_with(ui.item,gsf_template_element); }
574 }
575 });
576
577 $('div.gsf_template').children(".block,.table").slideUp(300);
578});
579
580/*******************************************************************************/
581
582function bind_all_sortables()
583{
584 console.log('function bind_all_sortables()');
585 bind_template_sortable();
586 bind_choose_metadata_sortable();
587 bind_link_sortable();
588 bind_switch_sortable();
589 bind_when_sortable();
590 bind_otherwise_sortable();
591
592 bind_tables();
593
594 bind_block_mouseover();
595 bind_minmax_remove();
596}
597
598function bind_tables()
599{
600 console.log('function bind_tables()');
601
602 $('#sectionHeader').click(function () {
603 console.log('section Header click *');
604 return true;
605 });
606
607 $('#sectionContainer').click(function () {
608 console.log('section Container click *');
609 return true;
610 });
611
612 $(".td-div").resizable({
613 alsoResize: 'parent',
614 handles: 'w,e',
615 stop: function(event, ui) {
616 console.log('Resize table on stop');
617 resize_tables($(this));
618 }, });
619
620 $(".droppable").droppable({
621 accept: '.element_type_td',
622 tolerance: 'pointer',
623 activate: function(event, ui) { $(this).addClass("droppable_hl");},
624 deactivate: function(event, ui) { $(this).removeClass("droppable_hl"); },
625 drop: function(event, ui) {
626 var neverempty = document.createElement("div");
627 neverempty.setAttribute("class","neverempty block");
628 neverempty.setAttribute("style","height:50px");
629 neverempty.setAttribute("style","display:block");
630 var text = document.createTextNode('NEVER EMPTY');
631 neverempty.appendChild(text);
632 var td = document.createElement("td");
633 var div = document.createElement("div");
634 div.setAttribute("title","td-div");
635 div.setAttribute("class","td-div block");
636 div.setAttribute("style","margin-left:0px");
637 div.setAttribute("width","25px");
638 td.appendChild(div);
639 div.appendChild(neverempty);
640 var sep = document.createElement("td");
641 sep.setAttribute("class","droppable");
642 sep.setAttribute("width","10px");
643 $(this).after(sep);
644 $(this).after(td);
645 bind_tables();
646 resize_tables($(this));
647 bind_td_sortable();
648 bind_block_mouseover();
649 }
650 });
651
652}
653
654function replace_with(item, me)
655{
656 // Search me for select
657 if(me.search("select") != -1)
658 {
659 // If select exists, then find CURRENT_SELECT_VALUE
660 var index = me.search(CURRENT_SELECT_VALUE);
661 if(index == -1)
662 console.log("Did not find " + CURRENT_SELECT_VALUE);
663 else
664 console.log("Found " + CURRENT_SELECT_VALUE + " at index " + index);
665 index = index + CURRENT_SELECT_VALUE.length + 1;
666 console.log("Attempt inserting select at new index "+index);
667 a = me.substring(0,index);
668 b = me.substring(index);
669 me = a.concat("selected",b);
670 }
671
672 item.replaceWith(me); //'<div class="element element-txt">This text box has been added!</div>');
673
674 resize_tables(item);
675
676 bind_all_sortables();
677}
678
679function resize_tables(item)
680{
681 var max_height = 0;
682 (item.parents('.table')).each(function(index) {
683 $(this).children().children().children().each(function() {
684 var sum_one = 0;
685 var sum_two = 0;
686 $(this).children('.block').each(function() { sum_one = sum_one + $(this).height();
687 $(this).children('.block').each(function() { sum_two = sum_two + $(this).height(); } );
688 console.log("My height is " + $(this).height() + ", sum height 2 is " + sum_two);
689 });
690 console.log("My height is " + $(this).height() + ", sum height 1 is " + sum_one);
691 if (sum_two > max_height)
692 max_height = sum_two;
693 });
694 });
695 equalHeights(item,max_height);
696}
697
698function bind_template_sortable()
699{
700 //console.log('function bind_template_sortable()');
701 $('.gsf_template').sortable({
702 'cursor':'pointer',
703 'tolerance': 'pointer',
704 'items':'.table', //.gsf_choose_metadata, .gsf_metadata',
705 'placeholder':'placeholder',
706 //'nested':'.gsf:metadata'
707 stop: function(event, ui) {
708 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_table')) { replace_with(ui.item, "<table class=\"table\" border=\"2\"></table>"); }
709 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_choose_metadata')) { replace_with(ui.item, gsf_choose_metadata_element); }
710 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_metadata')) { replace_with(ui.item, gsf_metadata_element); }
711 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_link')) { replace_with(ui.item, gsf_link_element); }
712 if (ui.item.hasClass("ui-draggable") && ui.item.hasClass('draggable_gsf_switch')) { replace_with(ui.item, gsf_switch_element); }
713 }
714 });
715
716 $('.gsf_template').click(function () {
717 console.log('gsf_template class click');
718 return false;
719 });
720
721}
722
723function bind_td_sortable()
724{
725
726 $('tr').sortable({
727 'cursor':'pointer',
728 'tolerance': 'intersect',
729 'items':'.column',
730 'placeholder':'placeholder_td',
731 'connectWith':'column'});
732
733 $('.td-div').sortable({
734 'cursor':'pointer',
735 'tolerance': 'pointer',
736 'items':'.gsf_metadata, .gsf_choose_metadata, .gsf_link, .gsf_switch',
737 'placeholder':'placeholder',
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('parent: ' + $(this).html());
916 if ($(this).html() == '[+]'){ //targetContent.css('display') == 'none') {
917 $(this).closest(".block").children(".table, .block").slideDown(300);
918 $(this).html('[-]');
919 $(this).removeClass("ui-icon-plusthick");
920 $(this).addClass("ui-icon-minusthick");
921 } else {
922 $(this).closest(".block").children(".table, .block").slideUp(300);
923 $(this).html('[+]');
924 $(this).removeClass("ui-icon-minusthick");
925 $(this).addClass("ui-icon-plusthick");
926 }
927 return false;
928};
929
930function serialize(s)
931{
932 serial = $.SortSerialize(s);
933 alert(serial.hash);
934};
935
936function equalHeights(item, height) {
937 //console.log('function equalHeights(item, height)');
938 (item.parents('.table')).each(function(index) {
939 $(this).children().children().children().each(function() {
940 $(this).height(height);
941 $(this).children().height(height);
942 });
943 });
944};
945
Note: See TracBrowser for help on using the repository browser.