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