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

Last change on this file since 1029 was 1029, checked in by vronk, 13 years ago

changes to columns, terms (unfinished) ; .ui-context-dialog

File size: 47.9 KB
Line 
1// main js-code
2
3var jsonw;
4var params;
5
6var actions = {
7                        base: {
8                        base_uri: "/MDService2/"
9                },
10                collections: {
11                        base_uri: "/MDService2/collections/",                   
12                        current:'olac'},
13                elements: {
14                                base_uri: "/MDService2/element/",                       
15                                current:''},
16                terms: {
17                        base_uri: "/MDService2/terms/",                 
18                        current:'all',
19                        maxdepth: 8},
20                terms_autocomplete: {
21                                base_uri: "/MDService2/terms/",                 
22                                current:''},
23                components: {
24                                base_uri: "/MDService2/comp/",                         
25                                current:''},
26                                /* current:'cmdi-corpus-aac2'}, */             
27                compprofiles: {
28                                base_uri: "/MDService2/compprofile/",                           
29                                        current:''},
30                                        /* current:'cmdi-corpus-aac2'}, */             
31                               
32                recordset: {
33                                base_uri: "/MDService2/recordset/"
34                                },
35
36                isocat: {
37                                base_uri: "/MDService2/datcats/",
38                                current:5
39                                }
40
41        };
42
43
44$(function(){
45
46                init();         
47                loadWelcomeMessage();
48                // Collections and terms loaded after WorkspaceProfile is loaded
49                loadWorkspaceProfiles();
50                //loadCollections();
51                //loadTerms();
52                //handleQueryInput();
53               
54                loadComponentsRegistry();       
55                loadDCR();
56               
57                handleBubble();
58       
59                addFunctionality();
60                addVisuals();
61               
62                //queryuriparams loaded after collections and workspaceprofile are loaded
63                //loadQueryFromUriParams();
64               
65});
66
67
68function init () {
69
70        // turn on debugging (see jquery.xslTransform.js)
71                var DEBUG = false;
72               
73        // check for jQuery and Sarissa
74                try{
75                        jQuery;
76                }catch(e){
77                        alert('You need to include jQuery!');
78                }
79
80//////////////         
81                params = getUrlVars();
82                createSearchClauses();
83}
84
85function update (uri, src_container, target_container,handler) {
86        notifyUser("update-uri:" + uri,'debug');
87        $(target_container).load(uri, handler );       
88}
89// TODO multiple collections
90function submit_query (columns, query, squery) {
91        notifyUser("processing query");
92       
93        if (jQuery.trim(query).length == 0){
94                query = null;
95        }
96        if (jQuery.trim(squery).length == 0){
97                squery = null;
98        }
99       
100        var q = new Query(collections, columns, query, squery); //actions.collections.current, query );
101        q.repository = getSelectedRepository();
102        notifyUser("submit_query:" + q.query_uri(),'debug');
103        queryset.addquery(q);
104        //notifyUser("container" + q.container.attr('id'));
105        //$("#querylist").append("sdfdsf");     
106}
107
108/* OBSOLETE? */
109function handle_result (data, textStatus) {
110        try {
111        $(this).text("done");
112  //$(this).html(data);
113  notifyUser("query processed:" + textStatus);
114        } catch (e) {
115                notifyUser(e,'debug');
116        }
117}
118
119
120function showNotifyMessages(){
121        try {
122                $('#notify-float').html($('#notify').html());
123                var title = "Notify - Messages";
124                $('#notify-float').dialog( "option", "title", title );
125               
126                //ui-state-default
127                $('#notify-float').dialog('open');
128                $('#notify-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default');
129                $('#notify-float').siblings('div.ui-dialog-titlebar').children().remove();
130                var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/><span class="cmd cmd_up ui-dialog-titlebar-up"/><span>' + title +'</span>';
131                $('#notify-float').siblings('div.ui-dialog-titlebar').prepend(x);
132               
133                } catch (e) {
134                        notifyUser(e,'debug');
135                }               
136}
137
138function showDetail(data, textStatus) { 
139        try {
140               
141                if (data ==  null){
142                        var blankdata = "<html><\html>";
143                        var title = "";
144                        $('#detail-float').html(blankdata);
145
146                        if ( $('#detail-float').dialog("isOpen")) {
147                                var up = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-titlebar-up');
148                                up.removeClass('.cmd_up .ui-dialog-titlebar-up');
149                                up.addClass('.cmd_get .ui-dialog-titlebar-get');
150                                var down = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-titlebar-down');
151                                down.removeClass('.cmd_down .ui-dialog-titlebar-down');
152                                down.addClass('.cmd_get .ui-dialog-titlebar-get');
153                               
154                                $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-title').text(title);
155                        } else {
156                                $('#detail-float').dialog('open');
157                                $('#detail-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default');
158                                $('#detail-float').siblings('div.ui-dialog-titlebar').children().remove();
159                                var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/><span class="cmd cmd_get ui-dialog-titlebar-get"/><span class="ui-dialog-title">' + "" +'</span>';
160                                $('#detail-float').siblings('div.ui-dialog-titlebar').prepend(x);
161
162                        }
163
164                } else
165                {
166                        $('#detail-float').html(data);
167                        var title =  $('#detail-float').find('.inner_title').attr("value");
168                        $('#detail-float').dialog( "option", "title", title );
169                       
170                        if ( $('#detail-float').dialog("isOpen")) {
171                                var get = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.cmd_get');
172                                get.removeClass('cmd_get');
173                                get.removeClass('ui-dialog-titlebar-get');
174                                get.addClass('cmd_up');
175                                get.addClass('ui-dialog-titlebar-up');
176                               
177                                $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-title').text(title);
178                        } else {
179                                //ui-state-default
180                                $('#detail-float').dialog('open');
181                                $('#detail-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default');
182                                $('#detail-float').siblings('div.ui-dialog-titlebar').children().remove();
183                                var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/><span class="cmd cmd_up ui-dialog-titlebar-up"/><span class="ui-dialog-title">' + title +'</span>';
184                                $('#detail-float').siblings('div.ui-dialog-titlebar').prepend(x);
185                               
186                                notifyUser("query processed:" + textStatus);                           
187                        }
188                }
189        } catch (e) {
190                        notifyUser(e,'debug');
191        }       
192}
193
194function showDetail2(data, textStatus) {       
195        try {
196                //notifyUser("receiving data:",'debug');
197                //notifyUser(data,'debug');
198                $('#detail').html(data);
199          //$(this).html(data);
200               
201          notifyUser("query processed:" + textStatus);
202                $("#detail .treeview").treeview({
203                        animated: "fast",
204                        collapsed: true
205                });
206
207                } catch (e) {
208                        notifyUser(e,'debug');
209                }       
210}
211
212function getNotifyMessagesText(){
213        var text = "";
214        for(var i=0;i<notify_messages.length;i++){
215                text = text  + "/n" + notify_messages[i].getText();
216        }
217        return text;
218}
219function notifyUser (msg) {
220        var notifymessage = new NotifyMessage(new Date(),msg); 
221        notifyset.add(notifymessage);
222          //notify_messages[notify_messages.length] = new NotifyMessage( new Date(),msg);
223          //$('#notify').text(msg);
224          //$('#notify').text(getNotifyMessagesText());
225          //$('#notify-all').find('textarea').attr("value",$('#notify-all').find('textarea').attr("value") + '\n' + msg);
226}
227
228function notifyUser (msg, type) {       
229       
230                if (type=='debug' & !(typeof console == "undefined")) {
231                        console.log(msg);
232                } else {
233                        var notifymessage = new NotifyMessage(new Date(),msg); 
234                        notifyset.add(notifymessage);
235                        //notify_messages[notify_messages.length] = new NotifyMessage(new Date(),msg);
236                        //$('#notify').text(msg);       
237                        //$('#notify').text(getNotifyMessagesText());
238                        //$('#notify-all').find('textarea').attr("value",$('#notify-all').find('textarea').attr("value") + '\n' + msg);
239          }
240}
241
242
243
244function addToQuerylist (x) {   
245        $("#querylist").prepend(x);     
246}
247
248function addToNotifylist (x) { 
249        $("#notifylist").prepend(x);   
250}
251
252
253function addToSClist (div, i, j, rel) { 
254       
255        var x;
256       
257        //notifyUser(i + "," + j + "," + rel);
258        if (rel == ""){
259                x = $('<div />').addClass("sc-i").addClass("and_level");
260                $(div).appendTo($(x).appendTo($('#searchclauselist')));
261                $(x).attr("id",i);
262        } else {
263                if (rel == "and") {
264                        x = $('<div />').addClass("sc-i").addClass("and_level");
265                        $(x).attr("id",i);
266                        $(div).appendTo($(x).appendTo($('#searchclauselist')));
267                } else {
268                        $(div).appendTo($('#searchclauselist').children()[i]);
269                }
270        }
271       
272        //$('#searchclauselist').append($(li));
273       
274}
275
276var last_bubble_uri;
277
278
279function showBubble (elem) {
280  //get the position of the placeholder element
281        notifyUser($(elem),'debug');
282  var pos = $(elem).offset(); 
283  var width = $(elem).width();
284  //show the menu directly over the placeholder
285  //notifyUser(pos + width,'debug');
286  $("#bubble").css( { "left": (pos.left + width) + "px", "top":pos.top + "px" } );
287  $("#bubble").show();
288}
289
290function link(action,format,params) {
291        var l = actions[action].base_uri + format;
292
293        // default param is q
294        if (params){
295                if ( ! $.isArray(params)) {
296                        l += '/' + params;
297                } else {
298                        l += '?' + $.param(params);
299                }
300        }
301        notifyUser("l:"+ l,'debug');
302        return l;
303}
304
305function  preprocessJSON(json){
306       
307        if (json["WorkspaceProfile"].Querysets[0] == undefined){
308                var jj = json["WorkspaceProfile"]["Querysets"]["item"];
309                delete json["WorkspaceProfile"]["Querysets"]["item"];
310                json["WorkspaceProfile"]["Querysets"] = [{}];
311                json["WorkspaceProfile"]["Querysets"][0] = jj;
312                }
313        if (String(json["WorkspaceProfile"]["Querysets"]) != "null") {
314               
315                $.each(json["WorkspaceProfile"]["Querysets"], function(i,item) {
316                    if (this.Queries[0] == undefined){
317                        var jj = this["Queries"]["item"];
318                                delete this["Queries"]["item"];
319                                this.Queries = [{}];
320                        this.Queries[0] = jj;
321                    }
322                });
323               
324                $.each(json["WorkspaceProfile"]["Querysets"], function(i,item){
325                        if (String(this.Queries) != "null") {
326                                $.each(this.Queries, function(i,item){
327                                        if (this.collections != "null") {
328                                                if (this.collections[0] == undefined){
329                                                var jj = this["collections"]["item"];
330                                                        delete this["collections"]["item"];
331                                                        this.collections = [{}];
332                                                this.collections[0] = jj;
333                                            }
334                                        }
335                                        if (this.columns != "null") {
336                                                if (this.columns[0] == undefined){
337                                                var jj = this["columns"]["item"];
338                                                        delete this["columns"]["item"];
339                                                        this.columns = [{}];
340                                                this.columns[0] = jj;
341                                            }
342                                        }
343                                });
344                        }
345                });
346        }
347       
348        return json;
349       
350}
351function appendQueryUI(json,i, qs){
352        var del = '';
353        var name = '';
354        //var ul;
355        var id = $(qs).parent().attr('id');
356
357        /*
358        if ($(qs).find('ul').size() == 0) {
359                ul = $('<ul></ul>');
360                $(ul).appendTo($(qs));
361        } else {
362                ul = $(qs).children('ul');
363        }       
364         
365        var x = '<li><span class="query_detail_caller" ><a href="'+id + '_'+ i+'" >' +
366        Query.fullformatstring(json) + '</a></span><span class="cmd cmd_load"></span>' +
367        del +
368        '<div class="term_detail" >' +
369        '<ul><li><div class="elem text"><span class="elem_name">query:<span><span class="elem_value">' + Query.simplequerystring(json.querystring)+
370        '</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>';
371        */
372       
373        if (id == 'userqs') {
374                del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>';
375                name = '<div class="cmds-elem-prop"><span class="label">name:</span><input type="text" class="input-name" value="' + json.name + '"></div>';
376        } else {
377                name = '<div class="cmds-elem-prop"><span class="label">name:</span><span class="value">' + json.name +
378                '</span></div>';
379        }
380        var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="detail-caller" ><a href="'+id + '_'+ i+'" >' + 
381        json.name + '</a></span>' + 
382        del +
383        '<div class="detail" >' +
384        name +
385        '<div class="cmds-elem-prop"><span class="label">squery:</span><span class="value">' + json.squerystring +
386        '</span></div>' +
387        '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(json.querystring) +
388        '</span></div><div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' +
389        '</div>';
390       
391        $(qs).append(x);
392       
393       
394        $(qs).find('.input-name').keydown(function(ev){
395                var evStop = function(){ 
396                        ev.stopPropagation(); 
397                        ev.preventDefault(); 
398                };
399                if (ev.which === 13) {
400                        var id = parseInt( $("#qts_select option:selected").val());
401                        $(this).parent().parent().parent().find('a').text($(this).val());
402                        var str = $(this).parent().parent().parent().find('a').attr("href");
403                        var iq = parseInt(str.substring(7));
404                       
405                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq].name = $(this).val();
406                        saveWorkspace("USER");
407                        evStop();
408                }
409        });
410}
411
412function createQueriesUI(json, qs){
413        $(qs).children().remove();
414        if (json.Queries != "null") {
415                $.each(json.Queries, function(i,item) {
416                        if (this != "null"){
417                                appendQueryUI(this,i, qs);
418                        }
419                });
420        }
421       
422}
423
424function loadRepositories(json) {
425       
426        var $select;
427        $select = $('#repositories_select');
428       
429       
430        $select.find("option").remove();
431       
432        if (String(json) != "null") {
433               
434                $.each(json, function(i,item) {
435                    $select.append(new Option(this.name, this.id));
436                });
437               
438        }
439        // select first
440        if (params["repository"] != undefined){
441                var r = parseInt(params["repository"])-1;
442                $($select.find("option")[r]).attr("selected","true");
443        } else {
444                $select.find("option").first().attr("selected","true");
445        }
446
447       
448        $select.change(function(data){
449                loadCollections(false);                         
450                //loadTerms();
451                handleQueryInput();
452                $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository());
453        });
454       
455}
456
457function getSelectedRepository(){
458        //var id = parseInt($('#repositories_select').find("option:selected").val());
459        return $('#repositories_select').find("option:selected").val();
460
461}
462
463function loadQuerysets(json, type) {
464       
465        var $select;
466        if (type == "user") {
467                $select = $('#qts_select');
468        } else {
469                $select = $('#serverqts_select');
470        }
471       
472        $select.find("option").remove();
473       
474        if (String(json) != "null") {
475               
476                $.each(json, function(i,item) {
477                        //notifyUser(i + ',' + this.name + ',' + this.created,'debug');
478                    $select.append(new Option(this.name, i));
479                });
480               
481               
482                // find id of selected
483                if ($select.find("option").size() > 0) {
484                        $select.find("option").first().attr("selected","true");
485                        var id = parseInt($select.find("option:selected").val());
486                        var jsonq = json[id];
487                       
488                        if (type == "user") {
489                                $('#qts_input').val(jsonq["name"]);
490                                qs = $("#userqueries");
491                        } else {
492                                qs = $("#serverqueries");
493                        }
494                        createQueriesUI(jsonq, qs);
495                }
496               
497                $select.change(function(data){
498                        if ($select.find("option").size() > 0) {
499                                // find id of selected
500                                var id = parseInt($select.find("option:selected").val());
501                                var jsonq = json[id];
502                               
503                                if (type == "user") {
504                                        $('#qts_input').val(jsonq["name"]);
505                                        qs = $("#userqueries");
506                                } else {
507                                        qs = $("#serverqueries");
508                                }
509                                createQueriesUI(jsonq, qs);
510                               
511/*                      $('#qs_select').find("option").remove();
512                               
513                                if (String(jsonw["WorkspaceProfile"].Querysets[id].Queries) != "null") {
514                                        $.each(jsonw["WorkspaceProfile"].Querysets[id].Queries, function(i,item) {
515                                       
516                                                notifyUser(i + ',' + this.querystring + ',' + this.collections[0],'debug');
517                                                $('#qs_select').append(new Option(Query.simplequerystring(this.querystring) , i));
518                                        });
519                                }
520                                */
521                        }
522             });
523        }
524       
525
526}
527
528function saveWorkspace(type){
529        var JSONText = JSON.stringify(jsonw["WorkspaceProfile"]);
530        //var JSONText = JSON.stringify({"aa.a":"r"});
531        //notifyUser(JSONText,'debug');
532        $.post("/MDService2/workspaceprofilesave/" + type,{"data":JSONText});
533       
534}
535////////////////////////////////////////////////
536function loadWelcomeMessage(){ 
537        $('#detail').load("/MDService2/static/welcome.xml", function() { //profile.collections.base_uri,
538                $('#welcome').addClass("ui-helper-reset ui-corner-all ui-widget-content");
539                if ($("#querylist").children().size() > 0) {
540                        hideWelcomeMessage();
541                }
542        });
543}
544
545function hideWelcomeMessage(){
546        // kick the welcome message on first submit
547        notifyUser("hiding welcome");
548        if( $('#welcome').is(':visible') ) {
549                $('#welcome').hide();
550        }
551}
552
553function loadWorkspaceProfiles(){
554        //empty json
555        jsonw = {'WorkspaceProfile':{'Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};
556        $('#qts_input').val("");
557       
558       
559        jQuery.getJSON("/MDService2/workspaceprofile/server",function(data){
560                notifyUser(data['WorkspaceProfile'],'debug');
561                                var json = preprocessJSON(data);
562                                $("#serverqs").attr("data",JSON.stringify(json));
563                                loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server");
564                                loadRepositories(json["WorkspaceProfile"]["Repositories"]);
565                               
566                                loadCollections(true);                         
567                                loadTerms();
568                                handleQueryInput();
569                });
570
571        // USER WORKSPACEPROFILE
572        jQuery.getJSON("/MDService2/workspaceprofile/user",function(data){
573                notifyUser(data['WorkspaceProfile'],'debug');
574                                jsonw = preprocessJSON(data);
575                                loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
576        });
577
578}
579function loadCollections(ini){
580       
581        $('#collections').load(link('collections','htmllist?repository=' + getSelectedRepository()), //profile.collections.base_uri,
582                        function() {
583               
584                                        if (ini) {
585                                                loadQueryFromUriParams();
586                                        }
587                                       
588                                       
589                                        $("#collections .treeview").treeview({
590                                                animated: "fast",
591                                                collapsed: true
592                                        });
593                                       
594                                        $(".treeview","#collections").find(".showselection").css("color","white");
595       
596                                        // handle treeview click
597                                        $(".treeview","#collections").find(".selection").click(function() {
598                                                var checked_status = this.checked;
599                                               
600                                                // select or deselect all children according to parent
601                                                $(this).next().next().next().find(".selection").attr("checked",checked_status);
602                                                $(this).next().next().next().find(".selection").attr("child","undefined");     
603                                       
604                                                // deselect parents
605                                                if (checked_status===false){
606                                                        $(this).parent().parents("li").each(function(){
607                                                                $(this).children(".selection").attr("checked",false);
608                                                        });
609                                                }
610                                       
611                                               
612                                                // refresh sign of existent selection
613                                                // first reset childrens settings
614                                                $(this).next().next().next().find(".showselection").css("color","white");
615                                                $(this).next().next().next().find(".showselection").attr("some_selection","0");
616                                               
617                                                // then refresh selections
618                                                $(this).parents("li").each(function(){
619                                                        var count_selected = $(this).find("ul li .selection:checked").size();
620                                                        if (count_selected > 0){
621                                                                $(this).children(".showselection").attr("some_selection","1");//css("color","red");
622                                                    } else {
623                                                                $(this).children(".showselection").attr("some_selection","0");//css("color","white");
624                                                    }
625                                                        //TODO move into .css
626                                                        if (count_selected > 0){
627                                                                        $(this).children(".showselection").css("color","red");
628                                                        } else {
629                                                                        $(this).children(".showselection").css("color","white");
630                                                        }
631                                                        $(this).children(".showselection").attr("count",count_selected);
632                                                });
633                                                       
634                                                // uncheck parents node + param settings
635                                                $(this).parent().parents("li").each(function(){
636                                                                $(this).find(".selection").attr("child","undefined");
637                                                                $(this).children(".selection").attr("checked",false);
638                                                });
639
640                                                // sett the parent_selection attr
641                                                $(this).parents("li").each(function(){
642                                                        $(this).find(".selection").each(function(){
643                                                                if (($(this).attr("checked")===true) &&
644                                                                        (($(this).parent().parent().parent().children(".selection").attr("checked")===false) ||
645                                                                                        ($(this).parent().parent().parent().children(".treeview").size() == 1))
646                                                                        ){
647                                                                        $(this).attr("child","parent_selection");
648                                                                        }
649                                                        });                                     
650                                                });
651                                               
652                                                // update collection_selection
653                                                var $treeview = $(".treeview","#collections");
654                                                //var collection = $("li",$treeview).find("input:checked[child='parent_selection']").next().text();
655                                                //notifyUser("collection:" + collection,'debug');
656                                               
657
658                                                var collection_text = "";
659                                                var coll;
660                                                collections.splice(0, collections.length);
661                                                $("li",$treeview).find("input:checked[child='parent_selection']").next().each(function(index){
662                                                        notifyUser("selection...:" + index + ":" + this.textContent  + $(this).attr("handle"),'debug'); 
663                                                        coll = new Collection($(this).attr("handle"), this.textContent);
664                                                        collections[collections.length] = coll;
665                                                        /*
666                                                        if (index == 0) {
667                                                                collection_text = this.textContent;
668                                                        } else {
669                                                                collection_text = collection_text + ", " + this.textContent;
670                                                        }
671                                                        */
672                                               
673                                                });
674                                                //$('#collection_list').attr("value",collection_text);
675                                                collections_widget.load(collections);
676                                               
677                                        });// end of treeview click
678        });// end of collection callback       
679}
680function loadTerms(){
681       
682        //$('#model_profiles').load(link('terms','htmlselect',actions.terms.current));// + '?repository=' + getSelectedRepository());
683        $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository());
684       
685        $('#terms-select').live('change', function(event) {
686                //notifyUser(this.value,'debug');
687                update(link('terms', 'htmllist', this.value)+ '?maxdepth=' + actions.terms.maxdepth + '&repository=' + getSelectedRepository(), 
688                                '#terms-select', '#model_terms',
689                                        function() {
690                                                $("#model_terms .treeview").treeview({
691                                                        animated: "fast",
692                                                        collapsed: false
693                                                });
694                                                //notifyUser($("#model_terms .treeview"),'debug');
695                                                notifyUser("loaded: #model_terms .treeview",'debug');
696                                                }       
697                        );     
698                }
699        );
700       
701        $('#terms .cmd_filter').live('click',  function(event) {                       
702                //var term = $(this).parent().find('span.term_detail_caller a').text();
703                var term = $(this).parent().children('span.data').text();               
704                if ($('.searchtype_text','#search').size()> 0 ) {
705                        var t = $('#query_area').text();
706                        $('#query_area').val(t + " " + term);
707                } else {
708                        searchclauseset.updatedata(term);
709                       
710                }
711                //$('#srquery').val(term);
712        });
713       
714        $('#terms .cmd_columns').live('click',  function(event) {       
715                //var term = $(this).parent().find('span.term_detail_caller a').text();
716                var term = $(this).parent().children('span.data').text();
717                // old method
718                /*
719                var columns_text = $('#columns_list').attr("value");
720                if (columns_text.length > 0){
721                        columns_text = columns_text + ",";
722                }
723                columns_text = columns_text + term;
724                $('#columns_list').attr("value",columns_text);
725                */
726                //
727                columns_widget.add(new ListItem(term));
728//              columnset.addcolumn(new Column(term));
729               
730        });     
731       
732        /*
733         * deactivated -> obsolete?
734         *
735        $('#terms .cmd_detail').live('click',  function(event) {
736                //showTermDetail($(this).parent().text());                     
737//                      notifyUser($(this).parent().find('span.term_detail_caller a').text(),'debug');
738                var term =      $(this).parent().find('span.term_detail_caller a').text();
739                var uri = link('terms', 'htmltable', term); // + " body";               
740               
741        //       $.ajax({
742        //              url: uri,
743        //              success: showDetail
744        //              });
745                $.get(uri, showDetail,'html');
746               
747        });
748        */
749}
750function loadComponentsRegistry(){
751        $('#profiles').load(link('compprofiles','htmlselect'));
752       
753        $('#components a').live('click', function (event) {
754                event.preventDefault();         
755                update($(this).attr('href'), '#components', '#components');
756        });
757
758        $('#profile-select').live('change', function(event) {
759                //notifyUser(this.value,'debug');
760                update(link('compprofiles', 'htmllist', this.value), 
761                                '#profile-select', '#components',
762                                        function() {
763                                                $("#components .treeview").treeview({
764                                                        animated: "fast",
765                                                        collapsed: false
766                                                });
767                                                notifyUser($("#components .treeview"),'debug');
768                                                }       
769                        );     
770                }
771        );
772       
773        $('#components .cmd_filter').live('click',  function(event) {   
774                var term = $(this).prev().text();
775                if ($('.searchtype_text','#search').size()> 0 ) {
776                        var t = $('#query_area').text();
777                        $('#query_area').val(t + " " + term);
778                } else {
779                        searchclauseset.updatedata(term);
780                        //$('.focused','#searchclauselist').find('.index_input').val(term);
781                }
782                //$('#srquery').val($(this).parent().children('a').attr('href'));
783        });
784       
785        $('#compreg .cmd_detail').live('click',  function(event) {
786                //showTermDetail($(this).parent().text());
787               
788                var uri = $(this).parent().children('a').attr('href'); // + " body";           
789                // $.ajax({
790                //      url: uri,
791                //      success: showDetail2
792                //      });
793                       
794                $.get(uri, showDetail2,'html');
795
796        });
797
798}
799function loadDCR(){
800       
801        // ISOCAT DCR
802         $('#dcr').load(link('isocat', 'htmllist', actions.isocat.current) );
803
804         // display minimal info in a bubble next to the calling anchor
805         $("#dcr a, .comp_detail a").live('click', 
806                                function (event) {
807                                        event.preventDefault();
808                               
809                                        var uri = $(this).attr('href');
810                                        $('#bubble').empty();
811                                        // weirdly not functioning
812                                        var isVisible = $('#bubble').is(':visible');
813                                        if (uri==last_bubble_uri) {                                             
814                                                $('#bubble').hide();
815                                                last_bubble_uri = '';
816                                        } else {                                               
817                                                notifyUser("conceptlink_uri: " + uri,'debug');                                         
818                                                $('#bubble').load(uri);
819                                                last_bubble_uri = uri;
820                                                showBubble($(this));   
821                                        }
822                                        notifyUser('last_bubble_uri:' + last_bubble_uri,'debug');
823                                       
824                                        //TODO filter, read isocat:nr
825                                        // use in query clause
826                                        var term = $(this).val();
827                                        var x = uri.split("/");
828                                        var category = x[x.length-1];
829                                        notifyUser(term);
830                                        searchclauseset.updatedata(term, true, category);
831                                }); 
832}
833
834function handleQueryInput(){
835       
836        var elem;
837        $('#terms_autocomplete').children().remove();
838        $('#terms_autocomplete').css('display','none');
839        $('#terms_autocomplete').load(link('terms_autocomplete','autocomplete/?q=all&repository='+ getSelectedRepository()),function(){
840                $(this).find('term').each(function(index){
841                        elem = $(this).attr("name");
842                        element_autocomplete[index] = elem;
843                        elements_hashtable[elem] = $(this).html();
844                });
845                // add autocomplete 's
846                searchclauseset.initAutocomplete();
847                columns_widget.initAutocomplete(element_autocomplete);
848                /*
849                createSearchClauses();
850                $('#query_list').css('display', 'none');
851                 $('<div id="searchclauselist"/>').insertAfter($('#query_list'));
852
853                var sc = new SearchClause("","","");
854                searchclauseset.addsearchclause(sc,"",0,0);
855
856                 // $('#query_area').hide();
857                 $('#searchclauselist').show();
858                 $('#toggle_inputmode_cmd').addClass("searchtype_clauses");
859                 
860                 $('#toggle_inputmode_cmd').live('click',function(){
861                         if ($(this).text() == "TEXT") {
862                                 searchclauseset.buildsctext();
863                                 $('#query_area').val(searchclauseset.sctext);
864                                 $('#query_area').show();
865                                 $('#searchclauselist').hide();
866                                 $(this).toggleClass('searchtype_text searchtype_clauses');     
867                                 $(this).text("FORM");
868                         } else {
869                                 $('#query_area').hide();
870                                 $('#searchclauselist').show();
871                                 $(this).text("TEXT");
872                                 $(this).toggleClass('searchtype_text searchtype_clauses');
873                         }
874                 });
875                 
876                 // load query if exists params
877                 loadQueryFromUriParams();
878                 */
879        });
880       
881         
882
883};
884//create searchclauses, columns and collections
885function createSearchClauses() {
886        $('#query_list').css('display', 'none');
887         $('<div id="searchclauselist"/>').insertAfter($('#query_list'));
888
889        var sc = new SearchClause("","","");
890        searchclauseset.addsearchclause(sc,"",0,0);
891
892         // $('#query_area').hide();
893         $('#searchclauselist').show();
894         $('#toggle_inputmode_cmd').addClass("searchtype_clauses");
895         
896         $('#toggle_inputmode_cmd').live('click',function(){
897                 if ($(this).text() == "TEXT") {
898                         searchclauseset.buildsctext();
899                         $('#query_area').val(searchclauseset.sctext);
900                         $('#query_area').show();
901                         $('#searchclauselist').hide();
902                         $(this).toggleClass('searchtype_text searchtype_clauses');     
903                         $(this).text("FORM");
904                 } else {
905                         $('#query_area').hide();
906                         $('#searchclauselist').show();
907                         $(this).text("TEXT");
908                         $(this).toggleClass('searchtype_text searchtype_clauses');
909                 }
910         });
911         
912         // load query if exists params
913         //loadQueryFromUriParams();
914         
915         // create columnswidget
916         columns_widget = new ListWidget($('#columns-widget'));
917         
918         // create collectionswidget
919         collections_widget = new ListWidget($('#collections-widget'));
920};
921
922function loadQueryFromUriParams(){
923       
924        var q = params["q"];
925        var squery = params["squery"];
926        var collection = params["collection"];
927        var startRecord = params["startRecords"];
928        var numRecords = params["numRecords"];
929        var repository = params["repository"];
930        var columns = params["columns"];
931        if ((q != undefined) || (squery != undefined) || (collection != undefined)) {
932                if (q == undefined) {
933                        q = "";
934                } else {
935                        q = Url.decode(q);
936                }
937                if (squery == undefined) {
938                        squery = "";
939                } 
940                if (columns == undefined) {
941                        columns = "";
942                }
943                if (startRecord == undefined) {
944                        startRecord = 1;
945                }
946                if (numRecords == undefined) {
947                        numRecords = 10;
948                }
949                if (repository == undefined) {
950                        repository = 1;
951                }
952                if (collection == undefined){
953                        collection = "";
954                }
955                var collections = [];
956                if (collection.length > 0 ){
957                        var coll = collection.split(",");
958                        $.each(coll,function(i,item){
959                                        var n;
960                                        n = $('#collections').find(".folder:[handle='"+item+"']").text();
961                                        var simple_collection = new Collection(item, n);
962                                        collections[i] = simple_collection;
963                        });
964                }
965               
966                var query = new Query(collections, columns, q, squery);
967                query.startRecord = startRecord;
968                query.numRecords = numRecords;
969                query.repository = repository;
970               
971               
972                queryset.addquery(query);
973               
974                searchclauseset.sctext = query.query;
975                notifyUser(searchclauseset.sctext,'debug');
976               
977                searchclauseset.buildfromquerystring();
978
979                $('#collection_list').attr("value",query.getcollectiontext("name"));
980                columns_widget.load(query.columns);
981                //$('#columns_list').attr("value",query.columns);
982                $('#input-simplequery').attr("value",query.squery);     
983
984                $('#query-input .content').show();
985                                                                         
986                hideWelcomeMessage();
987        }
988       
989}
990
991function handleBubble(){
992        // this is dangerous workaround
993        // actually I want it only for context-paths in #terms,
994        // but they are moved out of the '.term_detail' context into the #bubble
995        // so I have to use the generic..
996        // well, dangerous - you might wonder, why the links don't work..
997        $('#bubble a').live('click',  function(event) {
998                //showTermDetail($(this).parent().text());
999                event.preventDefault();
1000        } );
1001       
1002       
1003        $('#bubble .cmd_filter').live('click',  function(event) {       
1004                var term = $(this).next().next().attr("href");
1005                if ($('.searchtype_text','#search').size()> 0 ) {
1006                        var t = $('#query_area').text();
1007                        $('#query_area').val(t + " " + term);
1008                } else {
1009                        $('.focused','#searchclauselist').find('.index-input').val(term);
1010                }
1011                //$('#srquery').val(term);
1012        });
1013       
1014        /* obsolete: ? */
1015        /* $(".term_detail_caller a, .query-detail-caller a").live('click',
1016                                // function(event) {
1017                                //      //notifyUser("term_detail_caller_live_click",'debug');                                 
1018                                //      event.preventDefault();
1019                                //      $(this).parents('li').find('div.term_detail').toggle();
1020                        //});
1021                        function (event) {
1022                                        event.preventDefault();
1023                                        var uri = $(this).attr('href');
1024                                        $('#bubble').empty();
1025                                        // weirdly not functioning
1026//                                      var isVisible = $('#bubble').is(':visible');
1027                                        if (uri==last_bubble_uri) {                                             
1028                                                $('#bubble').hide();
1029                                                last_bubble_uri = '';
1030                                        } else {               
1031                                               
1032                                                notifyUser("term_uri: " + uri,'debug');                                         
1033                                                var detail_info = $(this).parents('li').find('div.term_detail').html();
1034                                                $('#bubble').html(detail_info);
1035                                                last_bubble_uri = uri;
1036                                                showBubble($(this));   
1037                                        }
1038                                        notifyUser('last_bubble_uri:' + last_bubble_uri,'debug');
1039                                });
1040                        */
1041
1042}
1043
1044function addFunctionality(){
1045         
1046/*      $('.cmds-elem-plus').live('click',  function(event) {
1047                $(this).children('.detail').toggle();
1048        });
1049        */ 
1050        $('.autocomplete-select-caller').live('click',  function(event) {
1051               
1052                $(this).closest(".index-context").prev().parent().find(".autocomplete-input").val($(this).text()).change();             
1053                $(this).closest(".index-context").hide();
1054        });
1055        $('.autocomplete-select-caller a').live('click',  function(event) {             
1056                event.preventDefault();
1057        });
1058        $('.detail-caller, .cmd_detail').live('click',  function(event) {               
1059                $(this).parent().children('.detail').toggle();
1060                $(this).children('.cmd_down, .cmd_up').toggleClass('cmd_down cmd_up');         
1061        });
1062       
1063        $('.detail-caller a').live('click',  function(event) {         
1064                event.preventDefault();
1065        });
1066       
1067        $('.comp_detail input').live('keyup',  function(event) {                       
1068                $('#srquery').val(
1069                                $(this).parent().children('span.cmdelem_name').text()
1070                                + "=" + $(this).val() );
1071        });
1072       
1073        // open detail (from result-set, but also already within detail-view (ResourceRef, IsPartOf)   
1074        $('.result a.internal, .mdrecord-detail a.internal').live('click',  function(event) {
1075                event.preventDefault();         
1076               
1077                var uri = $(this).attr('href'); // + " body";
1078                notifyUser('internal-link: ' + uri,'debug' );
1079                $.get(uri, showDetail,'html');
1080        });
1081
1082        $('.result a.external, .mdrecord-detail a.external').live('click',  function(event) {
1083               
1084                //event.preventDefault();               
1085                var uri = $(this).attr('href'); // + " body";
1086                notifyUser('resource-link: ' + uri,'debug' );
1087        //      $.get(uri, showDetail,'html'); */
1088        });
1089       
1090        $('.result .cmd_detail').live('click',  function(event) {       
1091       
1092                var uri = $(this).parent().find("a").attr('href'); // + " body";
1093                $.get(uri, showDetail,'html');
1094        });
1095       
1096// RECORDSET searchRetrieve
1097        $('#searchretrieve').submit( function(event) {
1098                        event.preventDefault();
1099                        hideWelcomeMessage();
1100                        searchclauseset.buildsctext();
1101                        notifyUser(searchclauseset.sctext,'debug');
1102                        //submit_query ($('#columns_list').attr("value"),searchclauseset.sctext, $('#input-simplequery').attr("value"));                       
1103                        submit_query (columns_widget.getColumnsListText(),searchclauseset.sctext, $('#input-simplequery').attr("value"));
1104        });
1105
1106        /*
1107        $('#querylist .query_header').find('.cmd_del').live('click',  function(event) {
1108                //showTermDetail($(this).parent().text());
1109               
1110                queryset.removequery($(this).closest('.query_wrapper').attr('id'));
1111                                       
1112        });
1113*/
1114       
1115        $('#querylist .cmd_up').live('click',  function(event) {
1116                $(this).closest('.query_wrapper').find('.result').hide();
1117                $(this).toggleClass('cmd_down cmd_up');                                 
1118        });
1119
1120       
1121        $('#querylist .cmd_save').live('click',  function(event) {
1122               
1123                var qid = "";
1124                var qstring = "";       
1125                var json_coll = "null";
1126                var json_cols = "null";
1127                var squery = "";
1128                var bookmark = "0";
1129               
1130                if ($(this).parents('.result').length > 0){
1131                        qstring = $(this).parent().find("a").attr('href');
1132                        qstring = qstring.substring(18,qstring.length);
1133                        bookmark = "1";
1134                } else {
1135                        qid = $(this).closest('.query_wrapper').attr("id");
1136                        qstring = queryset.getquerystring(qid); 
1137                        json_coll = queryset.getcollections(qid);
1138                        json_cols = queryset.getcolumns(qid);
1139                        squery = queryset.getsquery(qid);
1140                }
1141                 
1142                // JSON conversion
1143                if (qstring.length == 0){
1144                        qstring = "[NULL]";
1145                }
1146                if (squery.length == 0){
1147                        squery = "[NULL]";
1148                }
1149
1150                var id = parseInt($("#qts_select option:selected").val());
1151                var iq = $('#userqueries').children().size();
1152       
1153                if (iq == 0){
1154                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = [{}];
1155                }
1156                var jsonq = {"name":"", "squerystring":squery, "querystring":qstring,"searchclauses":"null" , "collections" : json_coll, "columns" : json_cols, "bookmark" : bookmark};
1157               
1158                var name;
1159                if (bookmark == "1") {
1160                        qstring = Url.decode(qstring);
1161                        var s = qstring.split(':');
1162                        name = s[s.length - 2] + ":" + s[s.length - 1];
1163                } else {
1164                        name = Query.fullformatstring(jsonq);
1165                }
1166                jsonq.name = name;
1167               
1168                jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = jsonq;
1169                saveWorkspace("USER");
1170                appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries'));
1171               
1172                //$("#qs_select").append(new Option(Query.simplequerystring(qstring),iq));
1173        });
1174       
1175        $('#querylist .cmd-xml').live('click',  function(event) {
1176                var qid = $(this).closest('.query_wrapper').attr("id");
1177
1178                queryset.getQuery(qid).open('xml');
1179        });
1180        $('#querylist .cmd-page').live('click',  function(event) {
1181                var qid = $(this).closest('.query_wrapper').attr("id");
1182
1183                queryset.getQuery(qid).open('htmlpage');
1184        });
1185        /*
1186        $('#querylist .cmd-link').live('click',  function(event) {
1187                /* var qid = $(this).closest('.query_wrapper').attr("id");
1188                var qstring = queryset.getquerystring(qid);     
1189                var json_coll = queryset.getcollections(qid);
1190                var json_cols = queryset.getcolumns(qid);
1191                var squery = queryset.getsquery(qid);
1192                // JSON conversion
1193                if (qstring.length == 0){
1194                        qstring = "[NULL]";
1195                }
1196                if (squery.length == 0){
1197                        squery = "[NULL]";
1198                }               
1199                var jsonq = {"squerystring":squery, "querystring":qstring,"searchclauses":"null" , "collections" : json_coll, "columns" : json_cols};
1200                ///
1201               
1202                queryset.getQuery(qid).open();
1203        });
1204        */
1205        /*
1206        $('.cmd_select').live('click',  function(event) {
1207                var qid = $(this).closest('.query_wrapper').attr("id");
1208                                       
1209                searchclauseset.sctext = queryset.getquerystring(qid);
1210                searchclauseset.buildfromquerystring();
1211        });
1212        */
1213        $('#queryslist .cmd_reload').live('click',  function(event) {
1214                var qid = $(this).closest('.query_wrapper').attr("id");
1215
1216                queryset.resubmit(qid);
1217               
1218        });
1219               
1220       
1221        $('.cmd_down').live('click',  function(event) { 
1222                $(this).closest('.query_wrapper').find('.result').show();
1223                $(this).toggleClass('cmd_down cmd_up');                                 
1224        });
1225        $('.cmd_sc_delete').live('click',  function(event) {
1226                var i = $(this).closest('.sc-i').attr('id');
1227                var j = $(this).closest('.sc-j').attr('id');
1228                //notifyUser(i + j,'debug');
1229                searchclauseset.removesearchclause(i,j);
1230                                       
1231        });
1232        $('.cmd_add_and').live('click',  function(event) {
1233                //showTermDetail($(this).parent().text());
1234                //$(this).next().hide();
1235                $(this).attr("value","AND");
1236                var searchclause = new SearchClause("","","");
1237                var i = $(this).closest('.sc-i').attr('id');
1238                var j = $(this).closest('.sc-j').attr('id');
1239                //notifyUser(i + j,'debug');
1240                searchclauseset.addsearchclause(searchclause,"and",i,j);
1241                                       
1242        });
1243        $('.cmd_add_or').live('click',  function(event) {
1244                //showTermDetail($(this).parent().text());
1245                //$(this).next().hide();
1246                var i,j;
1247                $(this).attr("value","OR");
1248                var searchclause = new SearchClause("","","");
1249                searchclauseset.addsearchclause(searchclause,"or",$(this).closest('.sc-i').attr('id'),$(this).closest('.sc-j').attr('id'));
1250                                       
1251        });
1252
1253        ///// datasets/queries
1254        $('#qts_save').click(function(){
1255                var id = $("#qts_select option:selected").val();
1256                //notifyUser($('#qts_input').val() + $('#qts_input').text(),'debug');
1257                jsonw["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val();
1258                       
1259                $("#qts_select option:selected").text( $('#qts_input').val());
1260                saveWorkspace("USER");
1261        });
1262        $('#qts_add').click(function(){
1263                var new_name = "new_queryset";
1264               
1265                var id = $('#qts_select option').size();
1266                var dt = new Date();
1267                var str_time = dt.toString("yyyy-MM-dd HH:mm:ss");
1268               
1269                if (id == 0){
1270                        jsonw["WorkspaceProfile"]["Querysets"] = [{}];
1271                }
1272       
1273                jsonw["WorkspaceProfile"]["Querysets"][id] = {"name":new_name,"created":str_time , "Queries" : "null"};
1274               
1275                saveWorkspace("USER");
1276                //todo
1277               
1278                //loadWorkspace(jsonw["WorkspaceProfile"]["Querysets"]);
1279                $("#qts_select").append(new Option(new_name, id));
1280                $("#qts_select").find('option').attr("selected","false");
1281                $("#qts_select").find('option').last().attr("selected","true");
1282                $('#qts_input').val(new_name);
1283        });
1284        $('#qts_delete').click(function(){
1285                var count = $("#qts_select option").size();
1286               
1287                //if (count > 1){
1288                        var id = parseInt($("#qts_select option:selected").val());
1289                        var size = jsonw["WorkspaceProfile"].Querysets.length;
1290               
1291                        for (var i=id;i<size-1;i++){
1292                                jsonw["WorkspaceProfile"].Querysets[i] = jsonw["WorkspaceProfile"].Querysets[i+1];
1293                        }
1294               
1295                        delete jsonw["WorkspaceProfile"].Querysets[size-1];
1296                        jsonw["WorkspaceProfile"]["Querysets"].length = size-1;
1297                        // set null string , if 0 querysets
1298                        if (count == 1) {
1299                                jsonw["WorkspaceProfile"]["Querysets"] = "null";
1300                        }
1301                        saveWorkspace("USER");
1302                        //$("#qts_select option").remove();
1303                        loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
1304                       
1305                //}
1306        });
1307       
1308        $('#collections .cmd_load').live('click',function(event){
1309                hideWelcomeMessage();
1310                var collection_text = "";
1311                var coll = $(this).next().next().next();
1312                collections.splice(0, collections.length);
1313                collections[0] = new Collection($(coll).attr("handle"), $(coll).html());
1314                var columns = columns_widget.getColumnsListText();//$('#columns_list').attr("value");
1315                var query = new Query(collections,columns,"","");
1316                query.repository = getSelectedRepository();
1317       
1318                //searchclauseset.clear();
1319                queryset.addquery(query);
1320                //$('#collection_list').attr("value",query.getcollectiontext("name"));
1321                collections_widget.load(query.collection);
1322       
1323        });
1324        $('#serverqueries .cmd_load').live('click',function(event){
1325               
1326                var id = parseInt( $("#serverqts_select option:selected").val());
1327                var str = $(this).parent().find('a').attr("href");
1328                var iq = parseInt(str.substring(9));
1329                var json = jQuery.parseJSON($("#serverqs").attr("data"));
1330                var q = json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq];
1331               
1332                loadQuery(q);
1333        });
1334        $('#userqueries .cmd_load').live('click',function(event){
1335               
1336                var id = parseInt( $("#qts_select option:selected").val());
1337                var str = $(this).parent().find('a').attr("href");
1338                var iq = parseInt(str.substring(7));
1339                var q = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq];
1340               
1341                loadQuery(q);
1342        });
1343        $('#userqueries .cmd_del').live('click', function(event){
1344                //var count = $("#userqueries li").size();
1345                var id = parseInt($("#qts_select option:selected").val());
1346                var str = $(this).parent().find('a').attr("href");
1347                var iq = parseInt(str.substring(7));
1348                var size = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length;
1349               
1350                for (var i=iq;i<size-1;i++){
1351                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1];
1352                }
1353       
1354                delete jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1];
1355                jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1;
1356               
1357                if (size == 1){
1358                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null";
1359                }
1360               
1361                saveWorkspace("USER");
1362                loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
1363                //$("#qs_select option").remove();
1364                //$("#qs_select option").first().attr("selected","true");
1365        });
1366
1367       
1368        $('.ui-dialog-titlebar-del').live('click', function(event){
1369                //$('#detail-float').dialog('close');
1370                var t = $(this).parents('.ui-widget').children('.ui-dialog-content');
1371                $(t).dialog('close');
1372        });
1373
1374        $('.ui-dialog-titlebar-up').live('click', function(event){
1375                var t = $(this).parents('.ui-widget').children('.ui-dialog-content');
1376               
1377                $(this).parents('.ui-widget').attr("tempheight",$(this).parents('.ui-widget').height());
1378                //notifyUser("up(height):" + $(this).parents('.ui-widget').height(),'debug');
1379                $(this).parents('.ui-widget').height(30);
1380                //notifyUser("up(tempheight):" + $(this).parents('.ui-widget').attr("tempheight"),'debug');
1381               
1382               
1383                //$(t).find(".ui-dialog-buttonpane:first, .ui-dialog-content").stop({clearQueue:true}).fadeOut(300);
1384                //$(t).stop({clearQueue:true}).animate({height:'0px'},300);
1385               
1386                $(this).removeClass('cmd_up ui-dialog-titlebar-up');
1387                $(this).addClass('cmd_down ui-dialog-titlebar-down');   
1388        });
1389        $('.ui-dialog-titlebar-down').live('click', function(event){
1390                var t = $(this).parents('.ui-widget').children('.ui-dialog-content');
1391               
1392                var h = $(this).parents('.ui-widget').attr("tempheight");
1393                //notifyUser("down(tempheight):" + h,'debug');
1394                $(this).parents('.ui-widget').height(parseInt(h));
1395                //notifyUser("down(height):" + $(this).parents('.ui-widget').height(),'debug');
1396               
1397               
1398                //$(this).parents('.ui-widget').attr("tempheight",$(this).parents('.ui-widget').height());
1399                //$(t).find(".ui-dialog-content, .ui-dialog-buttonpane:first").stop({clearQueue:true}).fadeIn(800)
1400                //.end().stop({clearQueue:true}).animate({height:'100%'},300);
1401
1402                $(this).removeClass('cmd_down ui-dialog-titlebar-down');
1403                $(this).addClass('cmd_up ui-dialog-titlebar-up');       
1404        });
1405
1406       
1407
1408}
1409function loadQuery(q){
1410        if (q["bookmark"] == "1") {
1411                var uri = "http://localhost:8080/MDService2/record/htmldetail/" + q["querystring"];
1412                showDetail(null,'html');
1413                $.get(uri, showDetail,'html');
1414        } else {
1415                hideWelcomeMessage();
1416                var query = new Query([],"","","");
1417                query.load(q);
1418                query.repository = getSelectedRepository();
1419                queryset.addquery(query);
1420               
1421                searchclauseset.sctext = query.query;
1422                notifyUser(searchclauseset.sctext,'debug');
1423                searchclauseset.buildfromquerystring();
1424
1425                collections = query.collection;
1426                collections_widget.load(query.collection);
1427                columns_widget.load(query.columns.split(','));
1428                $('#input-simplequery').attr("value",query.squery);
1429        } 
1430
1431}
1432function addVisuals(){
1433////////////VISUALS
1434       
1435//      $('#left-menu').addClass('ui-accordion ui-widget ui-helper-reset ui-accordion-icons'); 
1436        $('.cmds-ui-block').addClass('ui-helper-reset ui-corner-all');
1437        $('.cmds-ui-block .header').addClass('ui-widget-header ui-state-default ui-corner-top');
1438        $('.cmds-ui-block .content').addClass('ui-widget-content ui-corner-bottom');
1439        $('.cmds-ui-block .header').click(function() {
1440                $(this).next().toggle('fast');
1441                return false;
1442        }).next().hide();
1443
1444        $('.cmds-ui-block.init-show .header').next().show();
1445       
1446        /*
1447        // Accordion
1448                        $("#left-menu").accordion({ header: "h2",event: 'click' });                             
1449                        $("#left-menu").accordion('option', 'autoHeight', false);                       
1450                        // hack to open the accordion without scroll-bars on init
1451                        $("#left-menu").accordion('option', 'active', 1);
1452        */             
1453                       
1454                                //$("#main-menu").treeview();
1455                       
1456        // Detail                               
1457        //                      $("#detail").tabs("add", "#components","Tab1");
1458                        $("#detail-float").dialog({ autoOpen: false,
1459                                position: ['right','70px'],
1460                                height: 450,
1461                                width: 300,
1462                                minHeigh: 100});
1463
1464                        //$('#detail-float').dialog( "option", "minHeight", '0px' );
1465                       
1466                        $("#detail-float").dialog();
1467                        $("#detail-float").tabs();
1468                       
1469                        /// notify-messages
1470                        $("#notify-float").dialog({ autoOpen: false,
1471                                position: ['right','10px'],
1472                                height: 200,
1473                                width: 400,
1474                                minHeigh: 100});                       
1475                        $("#notify-float").dialog();
1476                        $("#notify-float").tabs();
1477
1478}
1479
1480function getUrlVars()
1481{
1482    var vars = [], hash;
1483    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
1484    for(var i = 0; i < hashes.length; i++)
1485    {
1486        hash = hashes[i].split('=');
1487        vars.push(hash[0]);
1488        vars[hash[0]] = hash[1];
1489    }
1490    return vars;
1491}
1492
1493String.prototype.beginsWith = function(t, i) { if (i==false) { return 
1494         (t == this.substring(0, t.length)); } else { return (t.toLowerCase() 
1495         == this.substring(0, t.length).toLowerCase()); } } ;
1496
1497
1498String.prototype.endsWith = function(t, i) { if (i==false) { return (t 
1499         == this.substring(this.length - t.length)); } else { return 
1500         (t.toLowerCase() == this.substring(this.length - 
1501         t.length).toLowerCase()); } } ;
1502
1503
1504 var Url = {
1505                 
1506                        // public method for url encoding
1507                encode : function (string) {
1508                        return escape(this._utf8_encode(string));
1509                },
1510         
1511                // public method for url decoding
1512                decode : function (string) {
1513                        return this._utf8_decode(unescape(string));
1514                },
1515         
1516                // private method for UTF-8 encoding
1517                _utf8_encode : function (string) {
1518                        string = string.replace(/\r\n/g,"\n");
1519                        var utftext = "";
1520         
1521                        for (var n = 0; n < string.length; n++) {
1522         
1523                                var c = string.charCodeAt(n);
1524         
1525                                if (c < 128) {
1526                                        utftext += String.fromCharCode(c);
1527                                }
1528                                else if((c > 127) && (c < 2048)) {
1529                                        utftext += String.fromCharCode((c >> 6) | 192);
1530                                        utftext += String.fromCharCode((c & 63) | 128);
1531                                }
1532                                else {
1533                                        utftext += String.fromCharCode((c >> 12) | 224);
1534                                        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
1535                                        utftext += String.fromCharCode((c & 63) | 128);
1536                                }
1537         
1538                        }
1539         
1540                        return utftext;
1541                },
1542         
1543                // private method for UTF-8 decoding
1544                _utf8_decode : function (utftext) {
1545                        var string = "";
1546                        var i = 0;
1547                        var c = c1 = c2 = 0;
1548         
1549                        while ( i < utftext.length ) {
1550         
1551                                c = utftext.charCodeAt(i);
1552         
1553                                if (c < 128) {
1554                                        string += String.fromCharCode(c);
1555                                        i++;
1556                                }
1557                                else if((c > 191) && (c < 224)) {
1558                                        c2 = utftext.charCodeAt(i+1);
1559                                        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1560                                        i += 2;
1561                                }
1562                                else {
1563                                        c2 = utftext.charCodeAt(i+1);
1564                                        c3 = utftext.charCodeAt(i+2);
1565                                        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1566                                        i += 3;
1567                                }
1568         
1569                        }
1570         
1571                        return string;
1572                }
1573         
1574};
Note: See TracBrowser for help on using the repository browser.