source: MDService2/trunk/MDService2/WebContent/scripts/mdservice2_ui.js @ 741

Last change on this file since 741 was 741, checked in by gaba, 14 years ago

collections indices - name and index is saved; misc errors (WorkspaceProfileServer?.xml loading, $('#querylist .cmd_save'))

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