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

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

further work on terms/values (layout, behaviour)
fix in repository handling

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