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

Last change on this file since 1919 was 1919, checked in by gaba, 12 years ago
File size: 23.1 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 loadTermsAutocompleteExplain(){
242        element_autocomplete_explain.splice(0, element_autocomplete_explain.length );
243        $('#termset_autocomplete_explain').children().remove();
244        $('#termset_autocomplete_explain').css('display','none');
245        $('#terms_autocomplete_explain').children().remove();
246        $('#terms_autocomplete_explain').css('display','none');
247
248        $('#termset_autocomplete_explain').load(link('fcs','?operation=explain&x-context=' + getSelectedRepository()),function(){
249                $(this).find("indexInfo").children("set").each(function(index){
250                        //element_autocomplete[index].data[term_index].values[i] = {label:$(this).find('index').children('title').text()};
251                        var _key, _name, _id, _parent, _isleaf = 0; 
252                        _key = $(this).attr("name");
253                        _name = $(this).children("title").text();
254                        _parent = $(this).parents('indexInfo');
255                        _id = $(this).attr("identifier");
256                        _isleaf = 1;//TODO
257                       
258                        element_autocomplete_explain[index] = { label:_name, value:_name, key:_key, id:_id, parent:_parent, isleaf:_isleaf, data:[]};   
259                });
260                // add autocomplete 's
261                //searchclauseset.initAutocomplete(true);
262                //columns_widget.initAutocomplete(element_autocomplete_explain, true);
263                searchclauseset.initAutocomplete(false);
264        });
265
266};
267
268
269function loadTermsAutocomplete(){
270       
271        //var elem;
272        $('#termset_autocomplete').children().remove();
273        $('#termset_autocomplete').css('display','none');
274        $('#terms_autocomplete').children().remove();
275        $('#terms_autocomplete').css('display','none');
276       
277
278        //$.get(link('smc','list/?context=*'),function(){
279        $('#termset_autocomplete').load(link('smc','list/?context=*'),function(){
280                $(this).find('Termset').each(function(index){
281                        var _key, _name, _id, _parent, _isleaf = 0; 
282                        _key = $(this).children("key").text();
283                        _name = $(this).children("name").text();
284                        _parent = $(this).parents('Termset');
285                        _id = $(this).children("id").text();
286                        if ($(this).children('Termset').length == 0){
287                                _isleaf = 1;
288                        }
289                       
290                        element_autocomplete[index] = { label:_name, value:_name, key:_key, id:_id, parent:_parent, isleaf:_isleaf, data:[]};   
291                        // obsolete
292                        // create div for each element
293                        //elements_hashtable[elem] = new Array();//$(this).html()
294                        //$('#terms_autocomplete').append($('<div/>').attr("id","elements_hashtable_" + elem));
295                });
296                // add autocomplete 's
297                //searchclauseset.initAutocomplete(false);
298                //columns_widget.initAutocomplete(element_autocomplete);
299                //load explain autocomplete array
300                loadTermsAutocompleteExplain();
301        });
302       
303       
304};
305
306// QUERYSETS UI
307function appendQueryUI(json,i, qs){
308        var del = '';
309        var name = '';
310        //var ul;
311        var id = $(qs).parent().attr('id');
312       
313        if (id == 'userqs') {
314                del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>';
315                name = '<div class="cmds-elem-prop"><span class="label">name:</span><input type="text" class="input-name" value="' + json.name + '"></div>';
316        } else {
317                name = '<div class="cmds-elem-prop"><span class="label">name:</span><span class="value">' + json.name +
318                '</span></div>';
319        }
320               
321        var timestr = "";
322        if (json.time != undefined){
323                timestr = json.time;
324        }
325        var qq = json.querystring;
326        if (qq == "[NULL]"){
327                qq = "";
328        }
329        var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="detail-caller-inline" ><a href="'+id + '_'+ i+'" >' + 
330        json.name + '</a></span>' + 
331        del +
332        '<span class="cmd cmd_publish"></span><div class="detail" >' +
333        name +
334        '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(qq) + '</span></div>' + 
335        '<div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' +
336        '<div class="cmds-elem-prop"><span class="label">columns:</span><span class="value">' + Query.columnstext(json) + '</span></div>' +
337        '<div class="cmds-elem-prop"><span class="label">time:</span><span class="value">' + timestr + '</span></div>' +
338        //'<div class="cmds-elem-prop"><span class="label">startItem:</span><span class="value">' + Query.startItem + '</span></div>' +
339        //'<div class="cmds-elem-prop"><span class="label">maxItems:</span><span class="value">' + Query.maximumItems + '</span></div>' +
340        //'<div class="cmds-elem-prop"><span class="label">repository:</span><span class="value">' + Query.repository + '</span></div>' +
341        '<div class="cmds-elem-prop"><span class="label">bookmark:</span><span class="value">' + json.bookmark + '</span></div>' +
342        '<div class="cmds-elem-prop"><span class="label">options:</span><span class="value">' + Query.optionstext(json) +  '</span></div>' +
343        '</div>';
344       
345        //dt = Date.parse('2010-10-18, 10:06 AM'); dt.toString('dd/mm/yyyy HH:mm:ss GMT')
346        $(qs).append(x);
347       
348        var query = new Query([],"","");
349        query.load(json);
350        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query);
351        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json);
352        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').find('.input-name').data('queryjson',json);
353        $(qs).find('.detail').css({'z-index' : '1000'});
354       
355        $(qs).find('.input-name').keydown(function(ev){
356                var evStop = function(){ 
357                        ev.stopPropagation(); 
358                        ev.preventDefault(); 
359                };
360                if (ev.which === 13) {
361                        $(this).data("queryjson").name = $(this).val();
362                        workspace.savequeryset($(this).data("queryjson"),0);
363                        //todo update
364                        $(this).parent().parent().parent().find('a').text($(this).val());
365                        //Workspace.save("user");
366                        //var query = new Query();
367                        //query.load($(this).data("queryjson"));
368                        //query.save();
369                        /*
370                        var id = parseInt( $("#qts_select option:selected").val());
371                        $(this).parent().parent().parent().find('a').text($(this).val());
372                        var str = $(this).parent().parent().parent().find('a').attr("href");
373                        var iq = parseInt(str.substring(7));
374                       
375                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq].name = $(this).val();
376                        //saveWorkspace("USER");
377                        Workspace.save("USER");
378                        */
379                        evStop();
380                }
381        });
382        createTooltip(qs);
383}
384
385function createQueriesUI(json, qs){
386        $(qs).children().remove();
387        if (json.Queries != "null") {
388                $.each(json.Queries, function(i,item) {
389                        if (this != "null"){
390                                appendQueryUI(this,i, qs);
391                        }
392                });
393        }
394       
395}
396function loadQuerysets(type) {
397       
398        var json = workspace.getTypedElement(type, 'queryset');
399        var $select;
400        if (type == "user") {
401                $select = $('#qts_select');
402        } else {
403                $select = $('#serverqts_select');
404        }
405       
406        $select.find("option").remove();
407       
408        if (String(json) != "null") {
409               
410                $.each(json, function(i,item) {
411                        //notifyUser(i + ',' + this.name + ',' + this.created,'debug');
412                    $select.append(new Option(this.name, i));
413                });
414               
415               
416                // find id of selected
417                if ($select.find("option").size() > 0) {
418                        $select.find("option").first().attr("selected","true");
419                        var id = parseInt($select.find("option:selected").val());
420                        var jsonq = json[id];
421                        //var jsonq = $select.find("option:selected").val();
422                       
423                        if (type == "user") {
424                                $('#qts_input').val(jsonq["name"]);
425                                qs = $("#userqueries");
426                        } else {
427                                qs = $("#serverqueries");
428                        }
429                        createQueriesUI(jsonq, qs);
430                }
431               
432                $select.change(function(data){
433                        if ($select.find("option").size() > 0) {
434                                // find id of selected
435                                var id = parseInt($select.find("option:selected").val());
436                                var jsonq = json[id];
437                                //var jsonq = $select.find("option:selected").val();
438                                       
439                                if (type == "user") {
440                                        $('#qts_input').val(jsonq["name"]);
441                                        qs = $("#userqueries");
442                                } else {
443                                        qs = $("#serverqueries");
444                                }
445                                createQueriesUI(jsonq, qs);
446                               
447                        }
448             });
449               
450        }
451
452}
453
454// BOOKMARKS UI
455function appendBookmarkUI(json,i, bs){
456        var del = '';
457        var name = '';
458        var id = $(bs).parent().attr('id');
459       
460        del = '<span class="cmd cmd_del" ><xsl:text> </xsl:text></span>';
461        name = '<div class="cmds-elem-prop"><span class="label">name:</span><input type="text" class="input-name" value="' + json.name + '"></div>';
462               
463        var timestr = "";
464        if (json.time != undefined){
465                timestr = json.time;
466        }
467       
468        var qq = json.querystring;
469        if (qq = "[NULL]"){
470                qq = "";
471        }
472        var x = '<div class="cmds-elem-plus" ><span class="cmd cmd_load"></span><span class="detail-caller-inline" ><a href="'+ id + '_'+ i+'" >' + 
473        json.name + '</a></span>' + 
474        del +
475        '<div class="detail" >' +
476        name +
477        '<div class="cmds-elem-prop"><span class="label">query:</span><span class="value">' + Query.simplequerystring(qq) + '</span></div>' + 
478        '<div class="cmds-elem-prop"><span class="label">collections:</span><span class="value">' + Query.collectiontext(json) + '</span></div>' +
479        '<div class="cmds-elem-prop"><span class="label">columns:</span><span class="value">' + Query.columnstext(json) + '</span></div>' +
480        '<div class="cmds-elem-prop"><span class="label">time:</span><span class="value">' + timestr + '</span></div>' +
481        '<div class="cmds-elem-prop"><span class="label">bookmark:</span><span class="value">' + json.bookmark + '</span></div>' +
482        '<div class="cmds-elem-prop"><span class="label">options:</span><span class="value">' + Query.optionstext(json) +  '</span></div>' +
483        '</div>';
484         
485        $(bs).append(x);
486       
487        var query = new Query([],"","");
488        query.load(json);
489        $(bs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query);
490        $(bs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json);
491        $(bs).find('.input-name').data('queryjson',json);
492        $(bs).find('.detail').css({'z-index' : '1000'});
493       
494        $(bs).find('.input-name').keydown(function(ev){
495                var evStop = function(){ 
496                        ev.stopPropagation(); 
497                        ev.preventDefault(); 
498                };
499                if (ev.which === 13) {
500                        $(this).data("queryjson").name = $(this).val();
501                        $(this).data("query").name = $(this).val();
502                        workspace.save("user");
503                       
504                        evStop();
505                }
506        });
507        createTooltip(qs);
508}
509
510function createBookmarksUI(json, bs){
511        $(bs).children().remove();
512        if (json.Bookmarks != "null") {
513                $.each(json.Bookmarks, function(i,item) {
514                        if (this != "null"){
515                                appendBookmarkUI(this,i, bs);
516                        }
517                });
518        }
519       
520}
521function loadBookmarksets() {
522       
523        var json = workspace.getTypedElement('user','bookmarkset');
524        var $select = $('#bts_select');
525       
526        $select.find("option").remove();
527       
528        if (String(json) != "null") {
529               
530                $.each(json, function(i,item) {
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 jsonb = json[id];
540                       
541                        $('#bts_input').val(jsonb["name"]);
542                        //qs = $("#bookmarks");
543                       
544                        createBookmarksUI(jsonb,  $("#bookmarks"));
545                }
546               
547                $select.change(function(data){
548                        if ($select.find("option").size() > 0) {
549                                // find id of selected
550                                var id = parseInt($select.find("option:selected").val());
551                                var jsonq = json[id];
552                                       
553                                $('#bts_input').val(jsonq["name"]);
554                                bs = $("#bookmarks");
555                               
556                                createBookmarksUI(jsonq, bs);
557                               
558                        }
559             });
560               
561        }
562
563}
564
565function  preprocessJSON(json){
566        if (json["Admin"] != undefined) {
567                if (json["Admin"]["QueryIndices"] != undefined){
568                        if (String(json["Admin"]["QueryIndices"]) != "null") {
569                                if (json["Admin"].QueryIndices[0] == undefined){
570                                        var jj = json["Admin"]["QueryIndices"]["item"];
571                                        delete json["Admin"]["QueryIndices"]["item"];
572                                        json["Admin"]["QueryIndices"] = [{}];
573                                        json["Admin"]["QueryIndices"][0] = jj;
574                                }
575                        }
576                }
577        }
578       
579       
580        if (json["WorkspaceProfile"]["CustomTermsets"] != undefined){
581       
582        if (String(json["WorkspaceProfile"]["CustomTermsets"]) != "null") {
583                if (json["WorkspaceProfile"].CustomTermsets[0] == undefined){
584                        var jj = json["WorkspaceProfile"]["CustomTermsets"]["item"];
585                        delete json["WorkspaceProfile"]["CustomTermsets"]["item"];
586                        json["WorkspaceProfile"]["CustomTermsets"] = [{}];
587                        json["WorkspaceProfile"]["CustomTermsets"][0] = jj;
588                }
589       
590               
591                $.each(json["WorkspaceProfile"]["CustomTermsets"], function(i,item) {
592                    if (this.Terms[0] == undefined){
593                        var jj = this["Terms"]["item"];
594                                delete this["Terms"]["item"];
595                                this.Terms = [{}];
596                        this.Terms[0] = jj;
597                    }
598                });
599        }
600        }
601        if (json["WorkspaceProfile"].Querysets[0] == undefined){
602                var jj = json["WorkspaceProfile"]["Querysets"]["item"];
603                delete json["WorkspaceProfile"]["Querysets"]["item"];
604                json["WorkspaceProfile"]["Querysets"] = [{}];
605                json["WorkspaceProfile"]["Querysets"][0] = jj;
606                }
607        if (json["WorkspaceProfile"].Bookmarksets[0] == undefined){
608                var jj = json["WorkspaceProfile"]["Bookmarksets"]["item"];
609                delete json["WorkspaceProfile"]["Bookmarksets"]["item"];
610                json["WorkspaceProfile"]["Bookmarksets"] = [{}];
611                json["WorkspaceProfile"]["Bookmarksets"][0] = jj;
612                }
613
614        if (String(json["WorkspaceProfile"]["Querysets"]) != "null") {
615               
616                $.each(json["WorkspaceProfile"]["Querysets"], function(i,item) {
617                    if (this.Queries[0] == undefined){
618                        var jj = this["Queries"]["item"];
619                                delete this["Queries"]["item"];
620                                this.Queries = [{}];
621                        this.Queries[0] = jj;
622                    }
623                });
624               
625                $.each(json["WorkspaceProfile"]["Querysets"], function(i,item){
626                        if (String(this.Queries) != "null") {
627                                $.each(this.Queries, function(i,item){
628                                        if (this.collections != "null") {
629                                                if (this.collections[0] == undefined){
630                                                var jj = this["collections"]["item"];
631                                                        delete this["collections"]["item"];
632                                                        this.collections = [{}];
633                                                this.collections[0] = jj;
634                                            }
635                                        }
636                                        if (this.columns != "null") {
637                                                if (this.columns[0] == undefined){
638                                                var jj = this["columns"]["item"];
639                                                        delete this["columns"]["item"];
640                                                        this.columns = [{}];
641                                                this.columns[0] = jj;
642                                            }
643                                        }
644                                });
645                        }
646                });
647        }
648       
649       
650        if (String(json["WorkspaceProfile"]["Bookmarksets"]) != "null") {
651               
652                $.each(json["WorkspaceProfile"]["Bookmarksets"], function(i,item) {
653                    if (this.Bookmarks[0] == undefined){
654                        var jj = this["Bookmarks"]["item"];
655                                delete this["Bookmarks"]["item"];
656                                this.Bookmarks = [{}];
657                        this.Bookmarks[0] = jj;
658                    }
659                });
660               
661                $.each(json["WorkspaceProfile"]["Bookmarksets"], function(i,item){
662                        if (String(this.Bookmarks) != "null") {
663                                $.each(this.Bookmarks, function(i,item){
664                                        if (this.collections != "null") {
665                                                if (this.collections[0] == undefined){
666                                                var jj = this["collections"]["item"];
667                                                        delete this["collections"]["item"];
668                                                        this.collections = [{}];
669                                                this.collections[0] = jj;
670                                            }
671                                        }
672                                        if (this.columns != "null") {
673                                                if (this.columns[0] == undefined){
674                                                var jj = this["columns"]["item"];
675                                                        delete this["columns"]["item"];
676                                                        this.columns = [{}];
677                                                this.columns[0] = jj;
678                                            }
679                                        }
680                                });
681                        }
682                });
683        }
684        return json;
685       
686}
687
688
689
690
691function saveTermset(id, name, listwidget) {
692       
693
694        var terms = [{}];       
695       
696        $.each(listwidget.widgets,function(i,elem){
697                terms[i] = elem.name;
698        });
699       
700        var dt = new Date();
701        var str_time = dateFormat(dt);//dt.toString("dd/mm/yyyy HH:mm:ss");
702        var jsont = {"name":name, "time" : str_time, "Terms" :terms};
703
704        workspace.addelement("customtermset",jsont);
705        workspace.save("user");
706/*
707        if (jsonw["WorkspaceProfile"]["CustomTermsets"] == "null") {
708                jsonw["WorkspaceProfile"]["CustomTermsets"] = [{}];
709                if (id == -1) {id = 0;};
710        }
711        if (id == -1) {id = jsonw["WorkspaceProfile"]["CustomTermsets"].length;};
712        jsonw["WorkspaceProfile"]["CustomTermsets"][id] = jsont;
713       
714        //saveWorkspace("USER");
715        Workspace.save("USER");
716*/
717};
718function removeTermset(id){
719        workspace.removeelement("customtermset",id);
720        workspace.save("user");
721        /*
722        var size = jsonw["WorkspaceProfile"]["CustomTermsets"].length;
723
724        for (var i=id;i<size-1;i++){
725                jsonw["WorkspaceProfile"].CustomTermsets[i] = jsonw["WorkspaceProfile"].CustomTermsets[i+1];
726        }
727
728        delete jsonw["WorkspaceProfile"].CustomTermsets[size-1];
729        jsonw["WorkspaceProfile"]["CustomTermsets"].length = size-1;
730        // set null string , if 0
731        if (size == 1) {
732                jsonw["WorkspaceProfile"]["CustomTermsets"] = "null";
733        }
734        //saveWorkspace("USER");
735        Workspace.save("USER");
736        */
737};
738
739/*
740function loadWelcomeMessage(){ 
741        $('#welcomedetail').load("/MDService2/docs/xml/welcome #welcome", function() { //profile.collections.base_uri,
742                $('#welcome').addClass("ui-helper-reset ui-corner-all ui-widget-content");
743        });
744}
745*/
Note: See TracBrowser for help on using the repository browser.