1 | // mdservice2_ui.js |
---|
2 | // based on metares_profile_ui.js 2010-03-25 |
---|
3 | var jsonw; |
---|
4 | |
---|
5 | var actions = { |
---|
6 | collections: { |
---|
7 | base_uri: "/MDService2/collections/", |
---|
8 | current:'olac'}, |
---|
9 | elements: { |
---|
10 | base_uri: "/MDService2/element/", |
---|
11 | current:''}, |
---|
12 | terms: { |
---|
13 | base_uri: "/MDService2/model/", |
---|
14 | current:'Components'}, |
---|
15 | components: { |
---|
16 | base_uri: "/MDService2/comp/", |
---|
17 | current:''}, |
---|
18 | /* current:'cmdi-corpus-aac2'}, */ |
---|
19 | compprofiles: { |
---|
20 | base_uri: "/MDService2/compprofile/", |
---|
21 | current:''}, |
---|
22 | /* current:'cmdi-corpus-aac2'}, */ |
---|
23 | |
---|
24 | recordset: { |
---|
25 | base_uri: "/MDService2/recordset/" |
---|
26 | }, |
---|
27 | |
---|
28 | isocat: { |
---|
29 | base_uri: "/MDService2/isocatprofile/", |
---|
30 | current:5 |
---|
31 | } |
---|
32 | |
---|
33 | }; |
---|
34 | |
---|
35 | |
---|
36 | $(function(){ |
---|
37 | |
---|
38 | init(); |
---|
39 | |
---|
40 | // turn on debugging (see jquery.xslTransform.js) |
---|
41 | var DEBUG = false; |
---|
42 | |
---|
43 | // check for jQuery and Sarissa |
---|
44 | try{ |
---|
45 | jQuery; |
---|
46 | }catch(e){ |
---|
47 | alert('You need to include jQuery!'); |
---|
48 | } |
---|
49 | |
---|
50 | ////////////// |
---|
51 | |
---|
52 | // POPULATE/LOAD VIEWS/BOXES; |
---|
53 | |
---|
54 | //SAMPLE WORKSPACEPROFILE |
---|
55 | //empty json |
---|
56 | jsonw = {'WorkspaceProfile':{'Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}}; |
---|
57 | $('#qts_input').val(""); |
---|
58 | |
---|
59 | |
---|
60 | jQuery.getJSON("/MDService2/workspaceprofile/server",function(data){ |
---|
61 | notifyUser(data['WorkspaceProfile'],'debug'); |
---|
62 | var json = preprocessJSON(data); |
---|
63 | $("#serverqs").attr("data",JSON.stringify(json)); |
---|
64 | loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server"); |
---|
65 | }); |
---|
66 | |
---|
67 | // USER WORKSPACEPROFILE |
---|
68 | jQuery.getJSON("/MDService2/workspaceprofile/user",function(data){ |
---|
69 | notifyUser(data['WorkspaceProfile'],'debug'); |
---|
70 | jsonw = preprocessJSON(data); |
---|
71 | loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); |
---|
72 | }); |
---|
73 | |
---|
74 | |
---|
75 | // COLLECTIONS |
---|
76 | |
---|
77 | $('#collections').load(link('collections','htmllist'), //profile.collections.base_uri, |
---|
78 | function() { |
---|
79 | $("#collections .treeview").treeview({ |
---|
80 | animated: "fast", |
---|
81 | collapsed: true |
---|
82 | }); |
---|
83 | |
---|
84 | $(".treeview","#collections").find(".showselection").css("color","white"); |
---|
85 | |
---|
86 | // handle treeview click |
---|
87 | $(".treeview","#collections").find(".selection").click(function() { |
---|
88 | var checked_status = this.checked; |
---|
89 | |
---|
90 | // select or deselect all children according to parent |
---|
91 | $(this).next().next().next().find(".selection").attr("checked",checked_status); |
---|
92 | |
---|
93 | // deselect parents |
---|
94 | if (checked_status===false){ |
---|
95 | $(this).parent().parents("li").each(function(){ |
---|
96 | $(this).children(".selection").attr("checked",false); |
---|
97 | }); |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | // refresh sign of existent selection |
---|
102 | // first reset childrens settings |
---|
103 | $(this).next().next().find(".showselection").css("color","white"); |
---|
104 | $(this).next().next().find(".showselection").attr("some_selection","0"); |
---|
105 | |
---|
106 | // then refresh selections |
---|
107 | $(this).parents("li").each(function(){ |
---|
108 | var count_selected = $(this).find("ul li .selection:checked").size(); |
---|
109 | if (count_selected > 0){ |
---|
110 | $(this).children(".showselection").attr("some_selection","1");//css("color","red"); |
---|
111 | } else { |
---|
112 | $(this).children(".showselection").attr("some_selection","0");//css("color","white"); |
---|
113 | } |
---|
114 | //TODO move into .css |
---|
115 | if (count_selected > 0){ |
---|
116 | $(this).children(".showselection").css("color","red"); |
---|
117 | } else { |
---|
118 | $(this).children(".showselection").css("color","white"); |
---|
119 | } |
---|
120 | $(this).children(".showselection").attr("count",count_selected); |
---|
121 | }); |
---|
122 | |
---|
123 | // uncheck parents node + param settings |
---|
124 | $(this).parent().parents("li").each(function(){ |
---|
125 | $(this).find(".selection").attr("child","undefined"); |
---|
126 | $(this).children(".selection").attr("checked",false); |
---|
127 | }); |
---|
128 | |
---|
129 | // sett the parent_selection attr |
---|
130 | $(this).parents("li").each(function(){ |
---|
131 | $(this).find(".selection").each(function(){ |
---|
132 | if (($(this).attr("checked")===true) && |
---|
133 | (($(this).parent().parent().parent().children(".selection").attr("checked")===false) || |
---|
134 | ($(this).parent().parent().parent().children(".treeview").size() == 1)) |
---|
135 | ){ |
---|
136 | $(this).attr("child","parent_selection"); |
---|
137 | } |
---|
138 | }); |
---|
139 | }); |
---|
140 | |
---|
141 | // update collection_selection |
---|
142 | var $treeview = $(".treeview","#collections"); |
---|
143 | //var collection = $("li",$treeview).find("input:checked[child='parent_selection']").next().text(); |
---|
144 | //notifyUser("collection:" + collection,'debug'); |
---|
145 | |
---|
146 | |
---|
147 | var collection_text = ""; |
---|
148 | var coll; |
---|
149 | collections.splice(0, collections.length); |
---|
150 | $("li",$treeview).find("input:checked[child='parent_selection']").next().each(function(index){ |
---|
151 | notifyUser("selection...:" + index + ":" + this.textContent + $(this).attr("handle"),'debug'); |
---|
152 | coll = new Collection($(this).attr("handle"), this.textContent) |
---|
153 | collections[collections.length] = coll; |
---|
154 | if (index == 0) { |
---|
155 | collection_text = this.textContent; |
---|
156 | } else { |
---|
157 | collection_text = collection_text + ", " + this.textContent; |
---|
158 | } |
---|
159 | |
---|
160 | }); |
---|
161 | $('#collection_list').attr("value",collection_text); |
---|
162 | |
---|
163 | });// end of treeview click |
---|
164 | });// end of collection callback |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | // COMPONENTS ComponentRegistry |
---|
169 | |
---|
170 | $('#profiles').load(link('compprofiles','htmlselect')); |
---|
171 | |
---|
172 | $('#components a').live('click', function (event) { |
---|
173 | event.preventDefault(); |
---|
174 | update($(this).attr('href'), '#components', '#components'); |
---|
175 | }); |
---|
176 | |
---|
177 | $('#profile-select').live('change', function(event) { |
---|
178 | //notifyUser(this.value,'debug'); |
---|
179 | update(link('compprofiles', 'htmllist', this.value), |
---|
180 | '#profile-select', '#components', |
---|
181 | function() { |
---|
182 | $("#components .treeview").treeview({ |
---|
183 | animated: "fast", |
---|
184 | collapsed: false |
---|
185 | }); |
---|
186 | notifyUser($("#components .treeview"),'debug'); |
---|
187 | } |
---|
188 | ); |
---|
189 | } |
---|
190 | ); |
---|
191 | |
---|
192 | // elements |
---|
193 | $('#model_profiles').load(link('terms','htmlselect',actions.terms.current)); |
---|
194 | |
---|
195 | $('#terms-select').live('change', function(event) { |
---|
196 | //notifyUser(this.value,'debug'); |
---|
197 | update(link('terms', 'htmllist', this.value), |
---|
198 | '#terms-select', '#model_terms', |
---|
199 | function() { |
---|
200 | $("#model_terms .treeview").treeview({ |
---|
201 | animated: "fast", |
---|
202 | collapsed: false |
---|
203 | }); |
---|
204 | //notifyUser($("#model_terms .treeview"),'debug'); |
---|
205 | notifyUser("loaded: #model_terms .treeview",'debug'); |
---|
206 | } |
---|
207 | ); |
---|
208 | } |
---|
209 | ); |
---|
210 | |
---|
211 | /* |
---|
212 | $('#terms').load(link('elements','htmllist'),function(){ |
---|
213 | //load autocomplete element after elements are loaded |
---|
214 | // load autocomplete innerText, if (tag.innerHTML) |
---|
215 | $('.term_detail_caller','#terms').each(function(index){ |
---|
216 | element_autocomplete[index]= $(this).children()[0].innerHTML; |
---|
217 | }); |
---|
218 | |
---|
219 | notifyUser("autocomplete loaded",'debug'); |
---|
220 | ////// INITIALIZE QUERYSEARCH after elements are loaded |
---|
221 | }); |
---|
222 | */ |
---|
223 | |
---|
224 | $('#query_list').css('display', 'none'); |
---|
225 | $('<div id="searchclauselist"/>').insertAfter($('#query_list')); |
---|
226 | |
---|
227 | var sc = new SearchClause("","",""); |
---|
228 | searchclauseset.addsearchclause(sc,"",0,0); |
---|
229 | |
---|
230 | // $('#query_area').hide(); |
---|
231 | $('#searchclauselist').show(); |
---|
232 | $('#toggle_inputmode_cmd').addClass("searchtype_clauses"); |
---|
233 | |
---|
234 | $('#toggle_inputmode_cmd').live('click',function(){ |
---|
235 | if ($(this).text() == "TEXT") { |
---|
236 | searchclauseset.buildsctext(); |
---|
237 | $('#query_area').val(searchclauseset.sctext); |
---|
238 | $('#query_area').show(); |
---|
239 | $('#searchclauselist').hide(); |
---|
240 | $(this).toggleClass('searchtype_text searchtype_clauses'); |
---|
241 | $(this).text("FORM"); |
---|
242 | } else { |
---|
243 | $('#query_area').hide(); |
---|
244 | $('#searchclauselist').show(); |
---|
245 | $(this).text("TEXT"); |
---|
246 | $(this).toggleClass('searchtype_text searchtype_clauses'); |
---|
247 | } |
---|
248 | }); |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | |
---|
254 | // this is dangerous workaround |
---|
255 | // actually I want it only for context-paths in #terms, |
---|
256 | // but they are moved out of the '.term_detail' context into the #bubble |
---|
257 | // so I have to use the generic.. |
---|
258 | // well, dangerous - you might wonder, why the links don't work.. |
---|
259 | $('#bubble a').live('click', function(event) { |
---|
260 | //showTermDetail($(this).parent().text()); |
---|
261 | event.preventDefault(); |
---|
262 | } ); |
---|
263 | |
---|
264 | |
---|
265 | $('#bubble .cmd_filter').live('click', function(event) { |
---|
266 | var term = $(this).next().next().attr("href"); |
---|
267 | if ($('.searchtype_text','#search').size()> 0 ) { |
---|
268 | var t = $('#query_area').text(); |
---|
269 | $('#query_area').val(t + " " + term); |
---|
270 | } else { |
---|
271 | $('.focused','#searchclauselist').find('.index_input').val(term); |
---|
272 | } |
---|
273 | //$('#srquery').val(term); |
---|
274 | }); |
---|
275 | $(".term_detail_caller a, .query-detail-caller a").live('click', |
---|
276 | // function(event) { |
---|
277 | // //notifyUser("term_detail_caller_live_click",'debug'); |
---|
278 | // event.preventDefault(); |
---|
279 | // $(this).parents('li').find('div.term_detail').toggle(); |
---|
280 | //}); |
---|
281 | function (event) { |
---|
282 | event.preventDefault(); |
---|
283 | var uri = $(this).attr('href'); |
---|
284 | $('#bubble').empty(); |
---|
285 | // weirdly not functioning |
---|
286 | // var isVisible = $('#bubble').is(':visible'); |
---|
287 | if (uri==last_bubble_uri) { |
---|
288 | $('#bubble').hide(); |
---|
289 | last_bubble_uri = ''; |
---|
290 | } else { |
---|
291 | |
---|
292 | notifyUser("term_uri: " + uri,'debug'); |
---|
293 | var detail_info = $(this).parents('li').find('div.term_detail').html(); |
---|
294 | $('#bubble').html(detail_info); |
---|
295 | last_bubble_uri = uri; |
---|
296 | showBubble($(this)); |
---|
297 | } |
---|
298 | notifyUser('last_bubble_uri:' + last_bubble_uri,'debug'); |
---|
299 | }); |
---|
300 | |
---|
301 | |
---|
302 | |
---|
303 | // MODEL queryModel |
---|
304 | // |
---|
305 | // $('#terms').load(link('terms', 'htmllist', actions.terms.current) ); |
---|
306 | // $('#query_terms').attr('value', actions.terms.current); |
---|
307 | // $('#query_terms').click( function(event) { |
---|
308 | // event.preventDefault(); |
---|
309 | |
---|
310 | // // update(profile.terms.base_uri + 'htmllist/' + this.attr('value'), '#query_terms', '#terms'); |
---|
311 | |
---|
312 | // }); |
---|
313 | |
---|
314 | // $('#terms a').live('click', function (event) { |
---|
315 | // //$('#select-lists li span').click(function (event) { |
---|
316 | // event.preventDefault(); |
---|
317 | //// update(this, '#terms', '#query_terms'); |
---|
318 | |
---|
319 | // update(link('terms', 'htmllist', $(this).attr('href')), '#terms', '#terms'); |
---|
320 | |
---|
321 | // //update(event.currentTarget, '#terms', '#terms'); |
---|
322 | // }); |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | // ISOCAT DCR |
---|
327 | $('#dcr').load(link('isocat', 'htmllist', actions.isocat.current) ); |
---|
328 | |
---|
329 | // display minimal info in a bubble next to the calling anchor |
---|
330 | $("#dcr a, .comp_detail a").live('click', |
---|
331 | function (event) { |
---|
332 | event.preventDefault(); |
---|
333 | |
---|
334 | var uri = $(this).attr('href'); |
---|
335 | $('#bubble').empty(); |
---|
336 | // weirdly not functioning |
---|
337 | var isVisible = $('#bubble').is(':visible'); |
---|
338 | if (uri==last_bubble_uri) { |
---|
339 | $('#bubble').hide(); |
---|
340 | last_bubble_uri = ''; |
---|
341 | } else { |
---|
342 | notifyUser("conceptlink_uri: " + uri,'debug'); |
---|
343 | $('#bubble').load(uri); |
---|
344 | last_bubble_uri = uri; |
---|
345 | showBubble($(this)); |
---|
346 | } |
---|
347 | notifyUser('last_bubble_uri:' + last_bubble_uri,'debug'); |
---|
348 | |
---|
349 | //TODO filter, read isocat:nr |
---|
350 | // use in query clause |
---|
351 | var term = $(this).val(); |
---|
352 | var x = uri.split("/"); |
---|
353 | var category = x[x.length-1]; |
---|
354 | notifyUser(term); |
---|
355 | searchclauseset.updatedata(term, true, category); |
---|
356 | }); |
---|
357 | |
---|
358 | |
---|
359 | ///// DETAIL |
---|
360 | |
---|
361 | // default - component-detail |
---|
362 | |
---|
363 | //$('#result').load(profile.components.base_uri_detail + profile.components.current, |
---|
364 | // function() { |
---|
365 | |
---|
366 | // $("#compviewdetail").treeview({ |
---|
367 | // animated: "fast", |
---|
368 | // collapsed: true |
---|
369 | // }); |
---|
370 | |
---|
371 | // $(".conceptlink").hover( |
---|
372 | // function (event) { |
---|
373 | // event.preventDefault(); |
---|
374 | // var uri = $(this).children('a').attr('href'); |
---|
375 | // notifyUser("conceptlink_uri: " + uri,'debug'); |
---|
376 | // $('#bubble').load(uri); |
---|
377 | // showBubble($(this)); |
---|
378 | // }, |
---|
379 | // function (event) { |
---|
380 | // $('#bubble').hide(); |
---|
381 | // } |
---|
382 | // ); |
---|
383 | |
---|
384 | // } |
---|
385 | // ); |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | ///////// ADD functionality |
---|
390 | |
---|
391 | /// generic functions |
---|
392 | |
---|
393 | $('.cmds-elem-plus').live('click', function(event) { |
---|
394 | $(this).children('.detail').toggle(); |
---|
395 | }); |
---|
396 | |
---|
397 | $('#components .cmd_filter').live('click', function(event) { |
---|
398 | var term = $(this).prev().text(); |
---|
399 | if ($('.searchtype_text','#search').size()> 0 ) { |
---|
400 | var t = $('#query_area').text(); |
---|
401 | $('#query_area').val(t + " " + term); |
---|
402 | } else { |
---|
403 | searchclauseset.updatedata(term); |
---|
404 | //$('.focused','#searchclauselist').find('.index_input').val(term); |
---|
405 | } |
---|
406 | //$('#srquery').val($(this).parent().children('a').attr('href')); |
---|
407 | }); |
---|
408 | |
---|
409 | |
---|
410 | $('#terms .cmd_filter').live('click', function(event) { |
---|
411 | //var term = $(this).parent().find('span.term_detail_caller a').text(); |
---|
412 | var term = $(this).parent().children('span.data').text(); |
---|
413 | if ($('.searchtype_text','#search').size()> 0 ) { |
---|
414 | var t = $('#query_area').text(); |
---|
415 | $('#query_area').val(t + " " + term); |
---|
416 | } else { |
---|
417 | searchclauseset.updatedata(term); |
---|
418 | |
---|
419 | } |
---|
420 | //$('#srquery').val(term); |
---|
421 | }); |
---|
422 | |
---|
423 | $('#terms .cmd_columns').live('click', function(event) { |
---|
424 | //var term = $(this).parent().find('span.term_detail_caller a').text(); |
---|
425 | var term = $(this).parent().children('span.data').text(); |
---|
426 | var columns_text = $('#columns_list').attr("value"); |
---|
427 | if (columns_text.length > 0){ |
---|
428 | columns_text = columns_text + ","; |
---|
429 | } |
---|
430 | columns_text = columns_text + term; |
---|
431 | $('#columns_list').attr("value",columns_text); |
---|
432 | }); |
---|
433 | // $('#compreg .cmd_filter').live('click', function(event) { |
---|
434 | // var term = $(this).parent().children('a').attr('href'); |
---|
435 | // $('#srquery').val($(this).parent().children('a').attr('href')); |
---|
436 | // }); |
---|
437 | |
---|
438 | |
---|
439 | $('.comp_detail input').live('keyup', function(event) { |
---|
440 | $('#srquery').val( |
---|
441 | $(this).parent().children('span.cmdelem_name').text() |
---|
442 | + "=" + $(this).val() ); |
---|
443 | }); |
---|
444 | |
---|
445 | |
---|
446 | $('#terms .cmd_detail').live('click', function(event) { |
---|
447 | //showTermDetail($(this).parent().text()); |
---|
448 | // notifyUser($(this).parent().find('span.term_detail_caller a').text(),'debug'); |
---|
449 | var term = $(this).parent().find('span.term_detail_caller a').text(); |
---|
450 | var uri = link('terms', 'htmltable', term); // + " body"; |
---|
451 | |
---|
452 | // $.ajax({ |
---|
453 | // url: uri, |
---|
454 | // success: showDetail |
---|
455 | // }); |
---|
456 | $.get(uri, showDetail,'html'); |
---|
457 | |
---|
458 | }); |
---|
459 | |
---|
460 | $('#compreg .cmd_detail').live('click', function(event) { |
---|
461 | //showTermDetail($(this).parent().text()); |
---|
462 | |
---|
463 | var uri = $(this).parent().children('a').attr('href'); // + " body"; |
---|
464 | // $.ajax({ |
---|
465 | // url: uri, |
---|
466 | // success: showDetail2 |
---|
467 | // }); |
---|
468 | |
---|
469 | $.get(uri, showDetail2,'html'); |
---|
470 | |
---|
471 | }); |
---|
472 | |
---|
473 | $('.result a').live('click', function(event) { |
---|
474 | //showTermDetail($(this).parent().text()); |
---|
475 | event.preventDefault(); |
---|
476 | |
---|
477 | var uri = $(this).attr('href'); // + " body"; |
---|
478 | // $.ajax({ |
---|
479 | // url: uri, |
---|
480 | // success: showDetail2 |
---|
481 | // }); |
---|
482 | |
---|
483 | $.get(uri, showDetail,'html'); |
---|
484 | |
---|
485 | }); |
---|
486 | |
---|
487 | |
---|
488 | |
---|
489 | // RECORDSET searchRetrieve |
---|
490 | $('#searchretrieve').submit( function(event) { |
---|
491 | event.preventDefault(); |
---|
492 | searchclauseset.buildsctext(); |
---|
493 | notifyUser(searchclauseset.sctext,'debug'); |
---|
494 | submit_query ($('#columns_list').attr("value"),searchclauseset.sctext); |
---|
495 | }); |
---|
496 | |
---|
497 | $('#querylist .cmd_del').live('click', function(event) { |
---|
498 | //showTermDetail($(this).parent().text()); |
---|
499 | |
---|
500 | queryset.removequery($(this).closest('.query_wrapper').attr('id')); |
---|
501 | |
---|
502 | }); |
---|
503 | |
---|
504 | $('.cmd_up').live('click', function(event) { |
---|
505 | $(this).closest('.query_wrapper').find('.result').hide(); |
---|
506 | $(this).toggleClass('cmd_down cmd_up'); |
---|
507 | }); |
---|
508 | |
---|
509 | $('#querylist .cmd_save').live('click', function(event) { |
---|
510 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
511 | var qstring = queryset.getquerystring(qid); |
---|
512 | var json_coll = queryset.getcollections(qid); |
---|
513 | var json_cols = queryset.getcolumns(qid); |
---|
514 | |
---|
515 | var id = parseInt($("#qts_select option:selected").val()); |
---|
516 | var iq = $('#userqueries').children().size(); |
---|
517 | |
---|
518 | if (iq == 0){ |
---|
519 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = [{}]; |
---|
520 | } |
---|
521 | |
---|
522 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = {"querystring":qstring,"searchclauses":"null" , "collections" : json_coll, "columns" : json_cols}; |
---|
523 | saveWorkspace(); |
---|
524 | appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries')); |
---|
525 | |
---|
526 | //$("#qs_select").append(new Option(Query.simplequerystring(qstring),iq)); |
---|
527 | }); |
---|
528 | /* |
---|
529 | $('.cmd_select').live('click', function(event) { |
---|
530 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
531 | |
---|
532 | searchclauseset.sctext = queryset.getquerystring(qid); |
---|
533 | searchclauseset.buildfromquerystring(); |
---|
534 | }); |
---|
535 | */ |
---|
536 | $('#queryslist .cmd_resubmit').live('click', function(event) { |
---|
537 | var qid = $(this).closest('.query_wrapper').attr("id"); |
---|
538 | |
---|
539 | queryset.resubmit(qid); |
---|
540 | |
---|
541 | }); |
---|
542 | |
---|
543 | |
---|
544 | $('.cmd_down').live('click', function(event) { |
---|
545 | $(this).closest('.query_wrapper').find('.result').show(); |
---|
546 | $(this).toggleClass('cmd_down cmd_up'); |
---|
547 | }); |
---|
548 | $('.cmd_sc_delete').live('click', function(event) { |
---|
549 | var i = $(this).closest('.sc-i').attr('id'); |
---|
550 | var j = $(this).closest('.sc-j').attr('id'); |
---|
551 | //notifyUser(i + j,'debug'); |
---|
552 | searchclauseset.removesearchclause(i,j); |
---|
553 | |
---|
554 | }); |
---|
555 | $('.cmd_add_and').live('click', function(event) { |
---|
556 | //showTermDetail($(this).parent().text()); |
---|
557 | //$(this).next().hide(); |
---|
558 | $(this).attr("value","AND"); |
---|
559 | var searchclause = new SearchClause("","",""); |
---|
560 | var i = $(this).closest('.sc-i').attr('id'); |
---|
561 | var j = $(this).closest('.sc-j').attr('id'); |
---|
562 | //notifyUser(i + j,'debug'); |
---|
563 | searchclauseset.addsearchclause(searchclause,"and",i,j); |
---|
564 | |
---|
565 | }); |
---|
566 | $('.cmd_add_or').live('click', function(event) { |
---|
567 | //showTermDetail($(this).parent().text()); |
---|
568 | //$(this).next().hide(); |
---|
569 | var i,j; |
---|
570 | $(this).attr("value","OR"); |
---|
571 | var searchclause = new SearchClause("","",""); |
---|
572 | searchclauseset.addsearchclause(searchclause,"or",$(this).closest('.sc-i').attr('id'),$(this).closest('.sc-j').attr('id')); |
---|
573 | |
---|
574 | }); |
---|
575 | |
---|
576 | ///// datasets/queries |
---|
577 | $('#qts_save').click(function(){ |
---|
578 | var id = $("#qts_select option:selected").val(); |
---|
579 | //notifyUser($('#qts_input').val() + $('#qts_input').text(),'debug'); |
---|
580 | jsonw["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val(); |
---|
581 | |
---|
582 | $("#qts_select option:selected").text( $('#qts_input').val()); |
---|
583 | saveWorkspace(); |
---|
584 | }); |
---|
585 | $('#qts_add').click(function(){ |
---|
586 | var new_name = "new_queryset"; |
---|
587 | |
---|
588 | var id = $('#qts_select option').size(); |
---|
589 | var dt = new Date(); |
---|
590 | var str_time = dt.toString("yyyy-MM-dd HH:mm:ss"); |
---|
591 | |
---|
592 | if (id == 0){ |
---|
593 | jsonw["WorkspaceProfile"]["Querysets"] = [{}]; |
---|
594 | } |
---|
595 | |
---|
596 | jsonw["WorkspaceProfile"]["Querysets"][id] = {"name":new_name,"created":str_time , "Queries" : "null"}; |
---|
597 | |
---|
598 | saveWorkspace(); |
---|
599 | //todo |
---|
600 | |
---|
601 | //loadWorkspace(jsonw["WorkspaceProfile"]["Querysets"]); |
---|
602 | $("#qts_select").append(new Option(new_name, id)); |
---|
603 | $("#qts_select").find('option').attr("selected","false"); |
---|
604 | $("#qts_select").find('option').last().attr("selected","true"); |
---|
605 | $('#qts_input').val(new_name); |
---|
606 | }); |
---|
607 | $('#qts_delete').click(function(){ |
---|
608 | var count = $("#qts_select option").size(); |
---|
609 | |
---|
610 | //if (count > 1){ |
---|
611 | var id = parseInt($("#qts_select option:selected").val()); |
---|
612 | var size = jsonw["WorkspaceProfile"].Querysets.length; |
---|
613 | |
---|
614 | for (var i=id;i<size-1;i++){ |
---|
615 | jsonw["WorkspaceProfile"].Querysets[i] = jsonw["WorkspaceProfile"].Querysets[i+1]; |
---|
616 | } |
---|
617 | |
---|
618 | delete jsonw["WorkspaceProfile"].Querysets[size-1]; |
---|
619 | jsonw["WorkspaceProfile"]["Querysets"].length = size-1; |
---|
620 | // set null string , if 0 querysets |
---|
621 | if (count == 1) { |
---|
622 | jsonw["WorkspaceProfile"]["Querysets"] = "null"; |
---|
623 | } |
---|
624 | saveWorkspace(); |
---|
625 | //$("#qts_select option").remove(); |
---|
626 | loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); |
---|
627 | |
---|
628 | //} |
---|
629 | }); |
---|
630 | |
---|
631 | |
---|
632 | $('#serverqueries .cmd_load').live('click',function(event){ |
---|
633 | |
---|
634 | var id = parseInt( $("#serverqts_select option:selected").val()); |
---|
635 | var str = $(this).parent().find('a').attr("href"); |
---|
636 | var iq = parseInt(str.substring(9)); |
---|
637 | var json = jQuery.parseJSON($("#serverqs").attr("data")); |
---|
638 | var query = new Query([],"",""); |
---|
639 | query.load(json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]); |
---|
640 | queryset.addquery(query); |
---|
641 | |
---|
642 | searchclauseset.sctext = query.query; |
---|
643 | notifyUser(searchclauseset.sctext,'debug'); |
---|
644 | searchclauseset.buildfromquerystring(); |
---|
645 | |
---|
646 | collections = query.collection; |
---|
647 | $('#collection_list').attr("value",query.getcollectiontext("name")); |
---|
648 | $('#columns_list').attr("value",query.columns); |
---|
649 | }); |
---|
650 | $('#userqueries .cmd_load').live('click',function(event){ |
---|
651 | |
---|
652 | var id = parseInt( $("#qts_select option:selected").val()); |
---|
653 | var str = $(this).parent().find('a').attr("href"); |
---|
654 | var iq = parseInt(str.substring(7)); |
---|
655 | |
---|
656 | var query = new Query([],"",""); |
---|
657 | query.load(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]); |
---|
658 | queryset.addquery(query); |
---|
659 | |
---|
660 | searchclauseset.sctext = query.query; |
---|
661 | notifyUser(searchclauseset.sctext,'debug'); |
---|
662 | searchclauseset.buildfromquerystring(); |
---|
663 | |
---|
664 | collections = query.collection; |
---|
665 | $('#collection_list').attr("value",query.getcollectiontext("name")); |
---|
666 | $('#columns_list').attr("value",query.columns); |
---|
667 | }); |
---|
668 | $('#userqueries .cmd_del').live('click', function(event){ |
---|
669 | //var count = $("#userqueries li").size(); |
---|
670 | var id = parseInt($("#qts_select option:selected").val()); |
---|
671 | var str = $(this).parent().find('a').attr("href"); |
---|
672 | var iq = parseInt(str.substring(7)); |
---|
673 | var size = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length; |
---|
674 | |
---|
675 | for (var i=iq;i<size-1;i++){ |
---|
676 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1]; |
---|
677 | } |
---|
678 | |
---|
679 | delete jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1]; |
---|
680 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1; |
---|
681 | |
---|
682 | if (size == 1){ |
---|
683 | jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null"; |
---|
684 | } |
---|
685 | |
---|
686 | saveWorkspace(); |
---|
687 | loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user"); |
---|
688 | //$("#qs_select option").remove(); |
---|
689 | //$("#qs_select option").first().attr("selected","true"); |
---|
690 | }); |
---|
691 | |
---|
692 | |
---|
693 | |
---|
694 | //////////// VISUALS |
---|
695 | |
---|
696 | // Accordion |
---|
697 | $("#left-menu").accordion({ header: "h2",event: 'click' }); |
---|
698 | $("#left-menu").accordion('option', 'autoHeight', false); |
---|
699 | |
---|
700 | // hack to open the accordion without scroll-bars on init |
---|
701 | $("#left-menu").accordion('option', 'active', 1); |
---|
702 | |
---|
703 | |
---|
704 | //$("#main-menu").treeview(); |
---|
705 | |
---|
706 | // Detail |
---|
707 | //$("#detail").dialog(); |
---|
708 | // $("#detail").tabs("add", "#components","Tab1"); |
---|
709 | $("#detail-float").dialog(); |
---|
710 | $("#detail-float").tabs(); |
---|
711 | |
---|
712 | }); |
---|
713 | |
---|
714 | |
---|
715 | function init () { |
---|
716 | } |
---|
717 | |
---|
718 | function update (uri, src_container, target_container,handler) { |
---|
719 | notifyUser("update-uri:" + uri,'debug'); |
---|
720 | $(target_container).load(uri, handler ); |
---|
721 | } |
---|
722 | // TODO multiple collections |
---|
723 | function submit_query (columns, query) { |
---|
724 | notifyUser("processing query"); |
---|
725 | |
---|
726 | var q = new Query(collections, columns, query); //actions.collections.current, query ); |
---|
727 | notifyUser("submit_query:" + q.query_uri(),'debug'); |
---|
728 | queryset.addquery(q); |
---|
729 | //notifyUser("container" + q.container.attr('id')); |
---|
730 | //$("#querylist").append("sdfdsf"); |
---|
731 | } |
---|
732 | |
---|
733 | /* OBSOLETE? */ |
---|
734 | function handle_result (data, textStatus) { |
---|
735 | try { |
---|
736 | $(this).text("done"); |
---|
737 | //$(this).html(data); |
---|
738 | notifyUser("query processed:" + textStatus); |
---|
739 | } catch (e) { |
---|
740 | notifyUser(e,'debug'); |
---|
741 | } |
---|
742 | } |
---|
743 | |
---|
744 | function showDetail(data, textStatus) { |
---|
745 | try { |
---|
746 | //notifyUser("receiving data:",'debug'); |
---|
747 | //notifyUser(data,'debug'); |
---|
748 | $('#detail-float').html(data); |
---|
749 | //$(this).html(data); |
---|
750 | notifyUser("query processed:" + textStatus); |
---|
751 | } catch (e) { |
---|
752 | notifyUser(e,'debug'); |
---|
753 | } |
---|
754 | } |
---|
755 | |
---|
756 | function showDetail2(data, textStatus) { |
---|
757 | try { |
---|
758 | //notifyUser("receiving data:",'debug'); |
---|
759 | //notifyUser(data,'debug'); |
---|
760 | $('#detail').html(data); |
---|
761 | //$(this).html(data); |
---|
762 | notifyUser("query processed:" + textStatus); |
---|
763 | $("#detail .treeview").treeview({ |
---|
764 | animated: "fast", |
---|
765 | collapsed: true |
---|
766 | }); |
---|
767 | |
---|
768 | } catch (e) { |
---|
769 | notifyUser(e,'debug'); |
---|
770 | } |
---|
771 | } |
---|
772 | |
---|
773 | function notifyUser (msg) { |
---|
774 | $('#notify').text(msg); |
---|
775 | } |
---|
776 | |
---|
777 | function notifyUser (msg, type) { |
---|
778 | |
---|
779 | if (type=='debug' & !(typeof console == "undefined")) { |
---|
780 | console.log(msg); |
---|
781 | } else { |
---|
782 | $('#notify').text(msg); |
---|
783 | } |
---|
784 | } |
---|
785 | |
---|
786 | |
---|
787 | function addToQuerylist (x) { |
---|
788 | $("#querylist").prepend(x); |
---|
789 | } |
---|
790 | |
---|
791 | |
---|
792 | function addToSClist (div, i, j, rel) { |
---|
793 | |
---|
794 | var x; |
---|
795 | |
---|
796 | //notifyUser(i + "," + j + "," + rel); |
---|
797 | if (rel == ""){ |
---|
798 | x = $('<div />').addClass("sc-i").addClass("and_level"); |
---|
799 | $(div).appendTo($(x).appendTo($('#searchclauselist'))); |
---|
800 | $(x).attr("id",i); |
---|
801 | } else { |
---|
802 | if (rel == "and") { |
---|
803 | x = $('<div />').addClass("sc-i").addClass("and_level"); |
---|
804 | $(x).attr("id",i); |
---|
805 | $(div).appendTo($(x).appendTo($('#searchclauselist'))); |
---|
806 | } else { |
---|
807 | $(div).appendTo($('#searchclauselist').children()[i]); |
---|
808 | } |
---|
809 | } |
---|
810 | |
---|
811 | //$('#searchclauselist').append($(li)); |
---|
812 | |
---|
813 | } |
---|
814 | |
---|
815 | var last_bubble_uri; |
---|
816 | |
---|
817 | |
---|
818 | function showBubble (elem) { |
---|
819 | //get the position of the placeholder element |
---|
820 | notifyUser($(elem),'debug'); |
---|
821 | var pos = $(elem).offset(); |
---|
822 | var width = $(elem).width(); |
---|
823 | //show the menu directly over the placeholder |
---|
824 | //notifyUser(pos + width,'debug'); |
---|
825 | $("#bubble").css( { "left": (pos.left + width) + "px", "top":pos.top + "px" } ); |
---|
826 | $("#bubble").show(); |
---|
827 | } |
---|
828 | |
---|
829 | function link(action,format,params) { |
---|
830 | var l = actions[action].base_uri + format; |
---|
831 | |
---|
832 | // default param is q |
---|
833 | if (params){ |
---|
834 | if ( ! $.isArray(params)) { |
---|
835 | l += '/' + params; |
---|
836 | } else { |
---|
837 | l += '?' + $.param(params); |
---|
838 | } |
---|
839 | } |
---|
840 | notifyUser("l:"+ l,'debug'); |
---|
841 | return l; |
---|
842 | } |
---|
843 | |
---|
844 | function preprocessJSON(json){ |
---|
845 | |
---|
846 | if (json["WorkspaceProfile"].Querysets[0] == undefined){ |
---|
847 | var jj = json["WorkspaceProfile"]["Querysets"]["item"]; |
---|
848 | delete json["WorkspaceProfile"]["Querysets"]["item"]; |
---|
849 | json["WorkspaceProfile"]["Querysets"] = [{}]; |
---|
850 | json["WorkspaceProfile"]["Querysets"][0] = jj; |
---|
851 | } |
---|
852 | if (String(json["WorkspaceProfile"]["Querysets"]) != "null") { |
---|
853 | |
---|
854 | $.each(json["WorkspaceProfile"]["Querysets"], function(i,item) { |
---|
855 | if (this.Queries[0] == undefined){ |
---|
856 | var jj = this["Queries"]["item"]; |
---|
857 | delete this["Queries"]["item"]; |
---|
858 | this.Queries = [{}]; |
---|
859 | this.Queries[0] = jj; |
---|
860 | } |
---|
861 | }); |
---|
862 | |
---|
863 | $.each(json["WorkspaceProfile"]["Querysets"], function(i,item){ |
---|
864 | if (String(this.Queries) != "null") { |
---|
865 | $.each(this.Queries, function(i,item){ |
---|
866 | if (this.collections != "null") { |
---|
867 | if (this.collections[0] == undefined){ |
---|
868 | var jj = this["collections"]["item"]; |
---|
869 | delete this["collections"]["item"]; |
---|
870 | this.collections = [{}]; |
---|
871 | this.collections[0] = jj; |
---|
872 | } |
---|
873 | } |
---|
874 | if (this.columns != "null") { |
---|
875 | if (this.columns[0] == undefined){ |
---|
876 | var jj = this["columns"]["item"]; |
---|
877 | delete this["columns"]["item"]; |
---|
878 | this.columns = [{}]; |
---|
879 | this.columns[0] = jj; |
---|
880 | } |
---|
881 | } |
---|
882 | }); |
---|
883 | } |
---|
884 | }); |
---|
885 | } |
---|
886 | |
---|
887 | return json; |
---|
888 | |
---|
889 | } |
---|
890 | function appendQueryUI(json,i, qs){ |
---|
891 | var del = ''; |
---|
892 | //var ul; |
---|
893 | var id = $(qs).parent().attr('id'); |
---|
894 | |
---|
895 | /* |
---|
896 | if ($(qs).find('ul').size() == 0) { |
---|
897 | ul = $('<ul></ul>'); |
---|
898 | $(ul).appendTo($(qs)); |
---|
899 | } else { |
---|
900 | ul = $(qs).children('ul'); |
---|
901 | } |
---|
902 | |
---|
903 | var x = '<li><span class="query_detail_caller" ><a href="'+id + '_'+ i+'" >' + |
---|
904 | Query.fullformatstring(json) + '</a></span><span class="cmd cmd_load"></span>' + |
---|
905 | del + |
---|
906 | '<div class="term_detail" >' + |
---|
907 | '<ul><li><div class="elem text"><span class="elem_name">query:<span><span class="elem_value">' + Query.simplequerystring(json.querystring)+ |
---|
908 | '</span></div></li><li><div class="elem text"><span class="elem_name">collections:</span><span class="elem_value">' + Query.collectiontext(json) + '</span></div></li></ul></div></li>'; |
---|
909 | */ |
---|
910 | |
---|
911 | if (id == 'userqs') { |
---|
912 | del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>'; |
---|
913 | } |
---|
914 | var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="query-detail-caller" ><a href="'+id + '_'+ i+'" >' + |
---|
915 | Query.fullformatstring(json) + '</a></span>' + |
---|
916 | del + |
---|
917 | '<div class="detail" >' + |
---|
918 | '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(json.querystring) + |
---|
919 | '</span></div><div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' + |
---|
920 | '</div>'; |
---|
921 | |
---|
922 | $(qs).append(x); |
---|
923 | |
---|
924 | } |
---|
925 | |
---|
926 | function createQueriesUI(json, qs){ |
---|
927 | $(qs).children().remove(); |
---|
928 | if (json.Queries != "null") { |
---|
929 | //$('<ul></ul>').appendTo($(qs)); |
---|
930 | $.each(json.Queries, function(i,item) { |
---|
931 | if (this != "null"){ |
---|
932 | /*if (this.collections == undefined) { |
---|
933 | notifyUser(i + ',' + this.querystring + ',' ,'debug'); |
---|
934 | } else { |
---|
935 | notifyUser(i + ',' + this.querystring + ',' + this.collections[0],'debug'); |
---|
936 | } |
---|
937 | */ |
---|
938 | appendQueryUI(this,i, qs); |
---|
939 | } |
---|
940 | //$('#qs_select').append(new Option(Query.simplequerystring(this.querystring), i)); |
---|
941 | }); |
---|
942 | } |
---|
943 | |
---|
944 | } |
---|
945 | |
---|
946 | function loadQuerysets(json, type) { |
---|
947 | |
---|
948 | var $select; |
---|
949 | if (type == "user") { |
---|
950 | $select = $('#qts_select'); |
---|
951 | } else { |
---|
952 | $select = $('#serverqts_select'); |
---|
953 | } |
---|
954 | |
---|
955 | $select.find("option").remove(); |
---|
956 | |
---|
957 | if (String(json) != "null") { |
---|
958 | |
---|
959 | $.each(json, function(i,item) { |
---|
960 | //notifyUser(i + ',' + this.name + ',' + this.created,'debug'); |
---|
961 | $select.append(new Option(this.name, i)); |
---|
962 | }); |
---|
963 | |
---|
964 | |
---|
965 | // find id of selected |
---|
966 | if ($select.find("option").size() > 0) { |
---|
967 | $select.find("option").first().attr("selected","true"); |
---|
968 | var id = parseInt($select.find("option:selected").val()); |
---|
969 | var jsonq = json[id]; |
---|
970 | |
---|
971 | if (type == "user") { |
---|
972 | $('#qts_input').val(jsonq["name"]); |
---|
973 | qs = $("#userqueries"); |
---|
974 | } else { |
---|
975 | qs = $("#serverqueries"); |
---|
976 | } |
---|
977 | createQueriesUI(jsonq, qs); |
---|
978 | } |
---|
979 | |
---|
980 | $select.change(function(data){ |
---|
981 | if ($select.find("option").size() > 0) { |
---|
982 | // find id of selected |
---|
983 | var id = parseInt($select.find("option:selected").val()); |
---|
984 | var jsonq = json[id]; |
---|
985 | |
---|
986 | if (type == "user") { |
---|
987 | $('#qts_input').val(jsonq["name"]); |
---|
988 | qs = $("#userqueries"); |
---|
989 | } else { |
---|
990 | qs = $("#serverqueries"); |
---|
991 | } |
---|
992 | createQueriesUI(jsonq, qs); |
---|
993 | |
---|
994 | /* $('#qs_select').find("option").remove(); |
---|
995 | |
---|
996 | if (String(jsonw["WorkspaceProfile"].Querysets[id].Queries) != "null") { |
---|
997 | $.each(jsonw["WorkspaceProfile"].Querysets[id].Queries, function(i,item) { |
---|
998 | |
---|
999 | notifyUser(i + ',' + this.querystring + ',' + this.collections[0],'debug'); |
---|
1000 | $('#qs_select').append(new Option(Query.simplequerystring(this.querystring) , i)); |
---|
1001 | }); |
---|
1002 | } |
---|
1003 | */ |
---|
1004 | } |
---|
1005 | }); |
---|
1006 | } |
---|
1007 | |
---|
1008 | |
---|
1009 | } |
---|
1010 | |
---|
1011 | function saveWorkspace(){ |
---|
1012 | |
---|
1013 | var JSONText = JSON.stringify(jsonw["WorkspaceProfile"]); |
---|
1014 | $.post("/MDService2/workspaceprofilesave/1/" + JSONText, ""); |
---|
1015 | } |
---|
1016 | |
---|
1017 | String.prototype.beginsWith = function(t, i) { if (i==false) { return |
---|
1018 | (t == this.substring(0, t.length)); } else { return (t.toLowerCase() |
---|
1019 | == this.substring(0, t.length).toLowerCase()); } } ; |
---|
1020 | |
---|
1021 | |
---|
1022 | String.prototype.endsWith = function(t, i) { if (i==false) { return (t |
---|
1023 | == this.substring(this.length - t.length)); } else { return |
---|
1024 | (t.toLowerCase() == this.substring(this.length - |
---|
1025 | t.length).toLowerCase()); } } ; |
---|
1026 | |
---|