source: MDService2/branches/MDService_simple3/WebContent/scripts/mdservice_ui_load.js @ 1918

Last change on this file since 1918 was 1918, checked in by gaba, 12 years ago

autocomplete - explain.xml

File size: 22.9 KB
Line 
1
2/**
3 * @fileOverview  The file contains app load functionality. The load functions actualy used provides client side model building together with
4 * ui building. The load module is independant from app pane-layout and all ui-layout functionality.
5 *
6 * @author
7 * @version
8 */
9
10function loadData(){
11        //loadWelcomeMessage();
12        loadTooltiptable();
13        loadWorkspaceProfiles();
14        //loadCollections(); // loaded after WorkspaceProfile is loaded
15        //loadTerms();           // loaded after WorkspaceProfile is loaded
16        //loadTermsAutocomplete(); //handleQueryInput();
17        //createTooltip()
18       
19        //loadComponentsRegistry();     
20        //loadDCR();
21}
22
23function loadTooltiptable() {
24         
25         var uri = window.location.pathname + "/../../static/info.xml";
26         
27         $.get(uri,function(data, textStatus){
28                $(data).find('#commands').find('dt').each(function(){
29                        tooltiptable[$(this).attr("id")] = $(this).text();
30                        //$(this).next('dd').text();
31                });
32         },'html');
33
34};
35/*
36function loadAdminFile(){
37        json_admin = {'Admin':{'maxqid':'0','QueryIndices':'null'}};
38       
39        jQuery.getJSON("/MDService2/workspaceprofile/admin",function(data){
40                        json_admin = preprocessJSON(data);
41        });
42}
43*/
44function loadWorkspaceProfiles(){
45        //empty json
46        workspace.user_json  = {'WorkspaceProfile':{'CustomTermsets':'null','Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};
47        $('#qts_input').val("");
48       
49        $.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {   
50              alert(textStatus); 
51              alert(errorThrown); 
52              alert(XMLHttpRequest.responseText); 
53          }}); 
54 
55
56        // server profile first - options needed
57        jQuery.getJSON("/MDService2/workspaceprofile/server?format=json",function(sdata){
58                                //notifyUser(sdata['WorkspaceProfile'],'debug');
59                                var json = preprocessJSON(sdata);
60                                workspace.server_json = json;
61                                $("#serverqs").attr("data",JSON.stringify(json));
62                                loadQuerysets("server");
63                                loadRepositories(workspace.server_json["WorkspaceProfile"]["Repositories"]);
64                                loadCollections(true);                         
65                                loadTerms();
66                                //loadTermsAutocomplete();
67                                loadQueryFromUriParams();
68                                createTooltip(null);
69                               
70                                // USER WORKSPACEPROFILE
71                                jQuery.getJSON("/MDService2/workspaceprofile/user?format=json",function(data){
72                                                        notifyUser(data['WorkspaceProfile'],'debug');
73                                                        workspace.user_json  = preprocessJSON(data);
74                                                        loadQuerysets("user");
75                                                        loadBookmarksets();
76                                                        createTooltip(this);
77                                                        loadTermsAutocomplete();
78                                });
79                               
80                });
81       
82       
83       
84
85}
86
87function loadCollections(ini){
88        var coll_uri = link('collections','htmllist?repository=' + getSelectedRepository());
89               
90        $("#collections").jstree({ 
91                "html_data" : {
92                        "ajax" : {
93                                "url" : coll_uri,
94                                "data" : function (n) { 
95                                        return {  //id : n.attr ? n.attr("id") : 0 ,
96                                                          collection : n.attr ? n.attr("handle") : "",
97                                                          maxdepth : n.attr ? 2 : 1 };
98                                }
99                        }
100                },
101                types : {
102                        // the default type
103                        "default" : {
104                                "max_children"  : -1,
105                                "max_depth"             : -1,
106                                "valid_children": "all"
107
108                }
109                },
110
111                "plugins" : [ "themes", "html_data", "ui" , "checkbox", "types", "search" ]
112        });
113       
114        $('#collections').bind('loaded.jstree reopen.jstree', function(event, data)
115                        {
116                                if ((event.type == "loaded") &&(ini)) {
117                                        loadQueryFromUriParams();
118                                }
119                               
120                                var dataelems = data.inst.get_container();
121                                createTooltip($(dataelems));
122                                        //data.inst.get_container().unblock();         
123                });
124
125        $('#collections').bind("change_state.jstree", function (event, data) {
126                var dataelems = data.inst.get_container();
127                var coll;
128                if (!local_collections){
129                        var collections  = [];
130                        //collections.splice(0, collections.length);
131                       
132                        $(this).find('.jstree-checked').each(function(index){
133                                if (!($(this).parent().parent().hasClass("jstree-checked")) ) {
134                                        //notifyUser("selection...:" + index + ":" + String.trim($(this).children('a').text())  + $(this).attr("handle"),'debug');     
135                                        coll = new Collection($(this).attr("handle"), String.trim($(this).children('a').text()));
136                                        collections[collections.length] = coll;                                         
137                                }
138                        });
139                       
140                        collections_widget.load(collections);
141                }
142    });
143       
144        $('#collections').bind("search.jstree", function (e, data) { 
145               
146                if (data.rslt.nodes.length > 0){
147                        $('#collections').jstree("checkbox.check_node",data.rslt.nodes[0]);
148                }
149                //alert("Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'."); 
150    }); 
151
152};
153
154function updateCollectionTree(){
155        /*
156        local_collections = true;
157        var cc = $('#collections').jstree("get_checked");
158        $('#collections').jstree("uncheck_all");
159        $.each(collections, function(){
160                $('#collections').jstree("search",this.name);
161        });
162        local_collections = false;
163        */
164};
165
166function loadTerms(){
167        $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository());
168       
169        $('#terms-select').live('change', function(event) {
170                //notifyUser(this.value,'debug');
171                update(link('terms', 'htmllist', this.value)+ '?maxdepth=' + actions.terms.maxdepth + '&repository=' + getSelectedRepository(), 
172                                '#terms-select', '#model_terms',
173                                        function() {
174                                                $("#model_terms .treeview").treeview({
175                                                        animated: "fast",
176                                                        collapsed: false
177                                                });
178                                                //notifyUser($("#model_terms .treeview"),'debug');
179                                                notifyUser("loaded: #model_terms .treeview",'debug');
180                                                createTooltip(this);
181                                                }       
182                        );     
183                }
184        );
185       
186        $('#terms .cmd_filter').live('click',  function(event) {                       
187                var term = $(this).parent().children('span.data').text();               
188                if ($('.searchtype_text','#search').size()> 0 ) {
189                        var t = $('#query_area').text();
190                        $('#query_area').val(t + " " + term);
191                } else {
192                        searchclauseset.updatedata(term);
193                       
194                }
195        });
196       
197        $('#terms .cmd_columns').live('click',  function(event) {       
198                var term = $(this).parent().children('span.data').text();
199                columns_widget.add(new ListItem(term)); 
200               
201        });     
202
203}
204
205function loadRepositories(json) {
206       
207        var $select;
208        $select = $('#repositories_select');
209       
210       
211        $select.find("option").remove();
212       
213        if (String(json) != "null") {
214               
215                $.each(json, function(i,item) {
216                    $select.append(new Option(this.name, this.id));
217                });
218               
219        }
220        // select first
221        if (url_params["repository"] != undefined){
222                var r = parseInt(url_params["repository"])-1;
223                $($select.find("option")[r]).attr("selected","true");
224        } else {
225                $select.find("option").first().attr("selected","true");
226        }
227
228       
229        $select.change(function(data){
230                if (workspace.getRepositoryType(getSelectedRepository())=='md'){
231                        loadCollections(false);                         
232                        loadTerms();
233                        loadTermsAutocomplete();
234                        $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository());
235
236                }
237        });
238       
239}
240
241function loadTermAutocompleteExplain(){
242        $('#termset_autocomplete_explain').children().remove();
243        $('#termset_autocomplete_explain').css('display','none');
244        $('#terms_autocomplete_explain').children().remove();
245        $('#terms_autocomplete_explain').css('display','none');
246
247        $('#termset_autocomplete_explain').load(link('fcs','?operation=explain&x-context=' + getSelectedRepository()),function(){
248                $(this).find("indexInfo").children("set").each(function(index){
249                        //element_autocomplete[index].data[term_index].values[i] = {label:$(this).find('index').children('title').text()};
250                        var _key, _name, _id, _parent, _isleaf = 0; 
251                        _key = $(this).attr("name");
252                        _name = $(this).children("title").text();
253                        _parent = $(this).parents('indexInfo');
254                        _id = $(this).attr("identifier");
255                        _isleaf = 1;//TODO
256                       
257                        element_autocomplete_explain[index] = { label:_name, value:_name, key:_key, id:_id, parent:_parent, isleaf:_isleaf, data:[]};   
258                });
259                // add autocomplete 's
260                //searchclauseset.initAutocomplete(true);
261                //columns_widget.initAutocomplete(element_autocomplete_explain, true);
262        });
263
264};
265
266function loadTermsAutocomplete(){
267       
268        //var elem;
269        $('#termset_autocomplete').children().remove();
270        $('#termset_autocomplete').css('display','none');
271        $('#terms_autocomplete').children().remove();
272        $('#terms_autocomplete').css('display','none');
273       
274
275        //$.get(link('smc','list/?context=*'),function(){
276        $('#termset_autocomplete').load(link('smc','list/?context=*'),function(){
277                $(this).find('Termset').each(function(index){
278                        var _key, _name, _id, _parent, _isleaf = 0; 
279                        _key = $(this).children("key").text();
280                        _name = $(this).children("name").text();
281                        _parent = $(this).parents('Termset');
282                        _id = $(this).children("id").text();
283                        if ($(this).children('Termset').length == 0){
284                                _isleaf = 1;
285                        }
286                       
287                        element_autocomplete[index] = { label:_name, value:_name, key:_key, id:_id, parent:_parent, isleaf:_isleaf, data:[]};   
288                        // obsolete
289                        // create div for each element
290                        //elements_hashtable[elem] = new Array();//$(this).html()
291                        //$('#terms_autocomplete').append($('<div/>').attr("id","elements_hashtable_" + elem));
292                });
293                // add autocomplete 's
294                searchclauseset.initAutocomplete(false);
295                //columns_widget.initAutocomplete(element_autocomplete);
296                //load explain autocomplete array
297                loadTermAutocompleteExplain();
298        });
299       
300       
301};
302
303// QUERYSETS UI
304function appendQueryUI(json,i, qs){
305        var del = '';
306        var name = '';
307        //var ul;
308        var id = $(qs).parent().attr('id');
309       
310        if (id == 'userqs') {
311                del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>';
312                name = '<div class="cmds-elem-prop"><span class="label">name:</span><input type="text" class="input-name" value="' + json.name + '"></div>';
313        } else {
314                name = '<div class="cmds-elem-prop"><span class="label">name:</span><span class="value">' + json.name +
315                '</span></div>';
316        }
317               
318        var timestr = "";
319        if (json.time != undefined){
320                timestr = json.time;
321        }
322        var qq = json.querystring;
323        if (qq == "[NULL]"){
324                qq = "";
325        }
326        var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="detail-caller-inline" ><a href="'+id + '_'+ i+'" >' + 
327        json.name + '</a></span>' + 
328        del +
329        '<span class="cmd cmd_publish"></span><div class="detail" >' +
330        name +
331        '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(qq) + '</span></div>' + 
332        '<div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' +
333        '<div class="cmds-elem-prop"><span class="label">columns:</span><span class="value">' + Query.columnstext(json) + '</span></div>' +
334        '<div class="cmds-elem-prop"><span class="label">time:</span><span class="value">' + timestr + '</span></div>' +
335        //'<div class="cmds-elem-prop"><span class="label">startItem:</span><span class="value">' + Query.startItem + '</span></div>' +
336        //'<div class="cmds-elem-prop"><span class="label">maxItems:</span><span class="value">' + Query.maximumItems + '</span></div>' +
337        //'<div class="cmds-elem-prop"><span class="label">repository:</span><span class="value">' + Query.repository + '</span></div>' +
338        '<div class="cmds-elem-prop"><span class="label">bookmark:</span><span class="value">' + json.bookmark + '</span></div>' +
339        '<div class="cmds-elem-prop"><span class="label">options:</span><span class="value">' + Query.optionstext(json) +  '</span></div>' +
340        '</div>';
341       
342        //dt = Date.parse('2010-10-18, 10:06 AM'); dt.toString('dd/mm/yyyy HH:mm:ss GMT')
343        $(qs).append(x);
344       
345        var query = new Query([],"","");
346        query.load(json);
347        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query);
348        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json);
349        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').find('.input-name').data('queryjson',json);
350        $(qs).find('.detail').css({'z-index' : '1000'});
351       
352        $(qs).find('.input-name').keydown(function(ev){
353                var evStop = function(){ 
354                        ev.stopPropagation(); 
355                        ev.preventDefault(); 
356                };
357                if (ev.which === 13) {
358                        $(this).data("queryjson").name = $(this).val();
359                        workspace.savequeryset($(this).data("queryjson"),0);
360                        //todo update
361                        $(this).parent().parent().parent().find('a').text($(this).val());
362                        //Workspace.save("user");
363                        //var query = new Query();
364                        //query.load($(this).data("queryjson"));
365                        //query.save();
366                        /*
367                        var id = parseInt( $("#qts_select option:selected").val());
368                        $(this).parent().parent().parent().find('a').text($(this).val());
369                        var str = $(this).parent().parent().parent().find('a').attr("href");
370                        var iq = parseInt(str.substring(7));
371                       
372                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq].name = $(this).val();
373                        //saveWorkspace("USER");
374                        Workspace.save("USER");
375                        */
376                        evStop();
377                }
378        });
379        createTooltip(qs);
380}
381
382function createQueriesUI(json, qs){
383        $(qs).children().remove();
384        if (json.Queries != "null") {
385                $.each(json.Queries, function(i,item) {
386                        if (this != "null"){
387                                appendQueryUI(this,i, qs);
388                        }
389                });
390        }
391       
392}
393function loadQuerysets(type) {
394       
395        var json = workspace.getTypedElement(type, 'queryset');
396        var $select;
397        if (type == "user") {
398                $select = $('#qts_select');
399        } else {
400                $select = $('#serverqts_select');
401        }
402       
403        $select.find("option").remove();
404       
405        if (String(json) != "null") {
406               
407                $.each(json, function(i,item) {
408                        //notifyUser(i + ',' + this.name + ',' + this.created,'debug');
409                    $select.append(new Option(this.name, i));
410                });
411               
412               
413                // find id of selected
414                if ($select.find("option").size() > 0) {
415                        $select.find("option").first().attr("selected","true");
416                        var id = parseInt($select.find("option:selected").val());
417                        var jsonq = json[id];
418                        //var jsonq = $select.find("option:selected").val();
419                       
420                        if (type == "user") {
421                                $('#qts_input').val(jsonq["name"]);
422                                qs = $("#userqueries");
423                        } else {
424                                qs = $("#serverqueries");
425                        }
426                        createQueriesUI(jsonq, qs);
427                }
428               
429                $select.change(function(data){
430                        if ($select.find("option").size() > 0) {
431                                // find id of selected
432                                var id = parseInt($select.find("option:selected").val());
433                                var jsonq = json[id];
434                                //var jsonq = $select.find("option:selected").val();
435                                       
436                                if (type == "user") {
437                                        $('#qts_input').val(jsonq["name"]);
438                                        qs = $("#userqueries");
439                                } else {
440                                        qs = $("#serverqueries");
441                                }
442                                createQueriesUI(jsonq, qs);
443                               
444                        }
445             });
446               
447        }
448
449}
450
451// BOOKMARKS UI
452function appendBookmarkUI(json,i, bs){
453        var del = '';
454        var name = '';
455        var id = $(bs).parent().attr('id');
456       
457        del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>';
458        name = '<div class="cmds-elem-prop"><span class="label">name:</span><input type="text" class="input-name" value="' + json.name + '"></div>';
459               
460        var timestr = "";
461        if (json.time != undefined){
462                timestr = json.time;
463        }
464       
465        var qq = json.querystring;
466        if (qq = "[NULL]"){
467                qq = "";
468        }
469        var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="detail-caller-inline" ><a href="'+ id + '_'+ i+'" >' + 
470        json.name + '</a></span>' + 
471        del +
472        '<div class="detail" >' +
473        name +
474        '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(qq) + '</span></div>' + 
475        '<div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' +
476        '<div class="cmds-elem-prop"><span class="label">columns:</span><span class="value">' + Query.columnstext(json) + '</span></div>' +
477        '<div class="cmds-elem-prop"><span class="label">time:</span><span class="value">' + timestr + '</span></div>' +
478        '<div class="cmds-elem-prop"><span class="label">bookmark:</span><span class="value">' + json.bookmark + '</span></div>' +
479        '<div class="cmds-elem-prop"><span class="label">options:</span><span class="value">' + Query.optionstext(json) +  '</span></div>' +
480        '</div>';
481         
482        $(bs).append(x);
483       
484        var query = new Query([],"","");
485        query.load(json);
486        $(bs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query);
487        $(bs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json);
488        $(bs).find('.input-name').data('queryjson',json);
489        $(bs).find('.detail').css({'z-index' : '1000'});
490       
491        $(bs).find('.input-name').keydown(function(ev){
492                var evStop = function(){ 
493                        ev.stopPropagation(); 
494                        ev.preventDefault(); 
495                };
496                if (ev.which === 13) {
497                        $(this).data("queryjson").name = $(this).val();
498                        $(this).data("query").name = $(this).val();
499                        workspace.save("user");
500                       
501                        evStop();
502                }
503        });
504        createTooltip(qs);
505}
506
507function createBookmarksUI(json, bs){
508        $(bs).children().remove();
509        if (json.Bookmarks != "null") {
510                $.each(json.Bookmarks, function(i,item) {
511                        if (this != "null"){
512                                appendBookmarkUI(this,i, bs);
513                        }
514                });
515        }
516       
517}
518function loadBookmarksets() {
519       
520        var json = workspace.getTypedElement('user','bookmarkset');
521        var $select = $('#bts_select');
522       
523        $select.find("option").remove();
524       
525        if (String(json) != "null") {
526               
527                $.each(json, function(i,item) {
528                    $select.append(new Option(this.name, i));
529                });
530               
531               
532                // find id of selected
533                if ($select.find("option").size() > 0) {
534                        $select.find("option").first().attr("selected","true");
535                        var id = parseInt($select.find("option:selected").val());
536                        var jsonb = json[id];
537                       
538                        $('#bts_input').val(jsonb["name"]);
539                        //qs = $("#bookmarks");
540                       
541                        createBookmarksUI(jsonb,  $("#bookmarks"));
542                }
543               
544                $select.change(function(data){
545                        if ($select.find("option").size() > 0) {
546                                // find id of selected
547                                var id = parseInt($select.find("option:selected").val());
548                                var jsonq = json[id];
549                                       
550                                $('#bts_input').val(jsonq["name"]);
551                                bs = $("#bookmarks");
552                               
553                                createBookmarksUI(jsonq, bs);
554                               
555                        }
556             });
557               
558        }
559
560}
561
562function  preprocessJSON(json){
563        if (json["Admin"] != undefined) {
564                if (json["Admin"]["QueryIndices"] != undefined){
565                        if (String(json["Admin"]["QueryIndices"]) != "null") {
566                                if (json["Admin"].QueryIndices[0] == undefined){
567                                        var jj = json["Admin"]["QueryIndices"]["item"];
568                                        delete json["Admin"]["QueryIndices"]["item"];
569                                        json["Admin"]["QueryIndices"] = [{}];
570                                        json["Admin"]["QueryIndices"][0] = jj;
571                                }
572                        }
573                }
574        }
575       
576       
577        if (json["WorkspaceProfile"]["CustomTermsets"] != undefined){
578       
579        if (String(json["WorkspaceProfile"]["CustomTermsets"]) != "null") {
580                if (json["WorkspaceProfile"].CustomTermsets[0] == undefined){
581                        var jj = json["WorkspaceProfile"]["CustomTermsets"]["item"];
582                        delete json["WorkspaceProfile"]["CustomTermsets"]["item"];
583                        json["WorkspaceProfile"]["CustomTermsets"] = [{}];
584                        json["WorkspaceProfile"]["CustomTermsets"][0] = jj;
585                }
586       
587               
588                $.each(json["WorkspaceProfile"]["CustomTermsets"], function(i,item) {
589                    if (this.Terms[0] == undefined){
590                        var jj = this["Terms"]["item"];
591                                delete this["Terms"]["item"];
592                                this.Terms = [{}];
593                        this.Terms[0] = jj;
594                    }
595                });
596        }
597        }
598        if (json["WorkspaceProfile"].Querysets[0] == undefined){
599                var jj = json["WorkspaceProfile"]["Querysets"]["item"];
600                delete json["WorkspaceProfile"]["Querysets"]["item"];
601                json["WorkspaceProfile"]["Querysets"] = [{}];
602                json["WorkspaceProfile"]["Querysets"][0] = jj;
603                }
604        if (json["WorkspaceProfile"].Bookmarksets[0] == undefined){
605                var jj = json["WorkspaceProfile"]["Bookmarksets"]["item"];
606                delete json["WorkspaceProfile"]["Bookmarksets"]["item"];
607                json["WorkspaceProfile"]["Bookmarksets"] = [{}];
608                json["WorkspaceProfile"]["Bookmarksets"][0] = jj;
609                }
610
611        if (String(json["WorkspaceProfile"]["Querysets"]) != "null") {
612               
613                $.each(json["WorkspaceProfile"]["Querysets"], function(i,item) {
614                    if (this.Queries[0] == undefined){
615                        var jj = this["Queries"]["item"];
616                                delete this["Queries"]["item"];
617                                this.Queries = [{}];
618                        this.Queries[0] = jj;
619                    }
620                });
621               
622                $.each(json["WorkspaceProfile"]["Querysets"], function(i,item){
623                        if (String(this.Queries) != "null") {
624                                $.each(this.Queries, function(i,item){
625                                        if (this.collections != "null") {
626                                                if (this.collections[0] == undefined){
627                                                var jj = this["collections"]["item"];
628                                                        delete this["collections"]["item"];
629                                                        this.collections = [{}];
630                                                this.collections[0] = jj;
631                                            }
632                                        }
633                                        if (this.columns != "null") {
634                                                if (this.columns[0] == undefined){
635                                                var jj = this["columns"]["item"];
636                                                        delete this["columns"]["item"];
637                                                        this.columns = [{}];
638                                                this.columns[0] = jj;
639                                            }
640                                        }
641                                });
642                        }
643                });
644        }
645       
646       
647        if (String(json["WorkspaceProfile"]["Bookmarksets"]) != "null") {
648               
649                $.each(json["WorkspaceProfile"]["Bookmarksets"], function(i,item) {
650                    if (this.Bookmarks[0] == undefined){
651                        var jj = this["Bookmarks"]["item"];
652                                delete this["Bookmarks"]["item"];
653                                this.Bookmarks = [{}];
654                        this.Bookmarks[0] = jj;
655                    }
656                });
657               
658                $.each(json["WorkspaceProfile"]["Bookmarksets"], function(i,item){
659                        if (String(this.Bookmarks) != "null") {
660                                $.each(this.Bookmarks, function(i,item){
661                                        if (this.collections != "null") {
662                                                if (this.collections[0] == undefined){
663                                                var jj = this["collections"]["item"];
664                                                        delete this["collections"]["item"];
665                                                        this.collections = [{}];
666                                                this.collections[0] = jj;
667                                            }
668                                        }
669                                        if (this.columns != "null") {
670                                                if (this.columns[0] == undefined){
671                                                var jj = this["columns"]["item"];
672                                                        delete this["columns"]["item"];
673                                                        this.columns = [{}];
674                                                this.columns[0] = jj;
675                                            }
676                                        }
677                                });
678                        }
679                });
680        }
681        return json;
682       
683}
684
685
686
687
688function saveTermset(id, name, listwidget) {
689       
690
691        var terms = [{}];       
692       
693        $.each(listwidget.widgets,function(i,elem){
694                terms[i] = elem.name;
695        });
696       
697        var dt = new Date();
698        var str_time = dateFormat(dt);//dt.toString("dd/mm/yyyy HH:mm:ss");
699        var jsont = {"name":name, "time" : str_time, "Terms" :terms};
700
701        workspace.addelement("customtermset",jsont);
702        workspace.save("user");
703/*
704        if (jsonw["WorkspaceProfile"]["CustomTermsets"] == "null") {
705                jsonw["WorkspaceProfile"]["CustomTermsets"] = [{}];
706                if (id == -1) {id = 0;};
707        }
708        if (id == -1) {id = jsonw["WorkspaceProfile"]["CustomTermsets"].length;};
709        jsonw["WorkspaceProfile"]["CustomTermsets"][id] = jsont;
710       
711        //saveWorkspace("USER");
712        Workspace.save("USER");
713*/
714};
715function removeTermset(id){
716        workspace.removeelement("customtermset",id);
717        workspace.save("user");
718        /*
719        var size = jsonw["WorkspaceProfile"]["CustomTermsets"].length;
720
721        for (var i=id;i<size-1;i++){
722                jsonw["WorkspaceProfile"].CustomTermsets[i] = jsonw["WorkspaceProfile"].CustomTermsets[i+1];
723        }
724
725        delete jsonw["WorkspaceProfile"].CustomTermsets[size-1];
726        jsonw["WorkspaceProfile"]["CustomTermsets"].length = size-1;
727        // set null string , if 0
728        if (size == 1) {
729                jsonw["WorkspaceProfile"]["CustomTermsets"] = "null";
730        }
731        //saveWorkspace("USER");
732        Workspace.save("USER");
733        */
734};
735
736/*
737function loadWelcomeMessage(){ 
738        $('#welcomedetail').load("/MDService2/docs/xml/welcome #welcome", function() { //profile.collections.base_uri,
739                $('#welcome').addClass("ui-helper-reset ui-corner-all ui-widget-content");
740        });
741}
742*/
Note: See TracBrowser for help on using the repository browser.