Ignore:
Timestamp:
04/27/11 20:37:11 (13 years ago)
Author:
gaba
Message:

workspace object, querysave function
customtermsets corrections

Location:
MDService2/trunk/MDService2/WebContent/scripts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_model.js

    r1235 r1252  
    99var page_record_count = 10;
    1010var formatquerystring_len = 25;
    11 
     11var workspace;
     12
     13function Workspace(){
     14
     15};
     16Workspace.save = function(type){
     17        var JSONText = JSON.stringify(jsonw["WorkspaceProfile"]);
     18        //var JSONText = JSON.stringify({"aa.a":"r"});
     19        //notifyUser(JSONText,'debug');
     20        $.post("/MDService2/workspaceprofilesave/" + type,{"data":JSONText});
     21};
     22Workspace.saveQuery = function(query){
     23        //queryset id
     24        var id = parseInt($("#qts_select option:selected").val());
     25        var iq = 0;
     26        var queries = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"];
     27       
     28        //var iq = $('#userqueries').children().size();
     29        if (queries == "null"){
     30                jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = [{}];
     31        } else {
     32                iq = queries.length;
     33        }
     34        var jsonq = query.toJSON();
     35        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = jsonq;
     36        Workspace.save("USER");
     37        appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries'));
     38       
     39};
    1240function Collection(index, name){
    1341        this.index = index;
     
    162190};
    163191
    164 Query.prototype.query_json = function () {     
    165         var jsonq = {"squerystring":this.squery,
    166                                  "querystring":this.query,                               
    167                                  "collections" : this.getcollectiontext("index"),
    168                                  "columns" : this.columns,
     192Query.prototype.toString = function(){
     193        var str = "";
     194        var coll = (this.getcollectiontext("name") != "" ) ? " in " + this.getcollectiontext("name") : "";
     195        str = Query.queryliststring(this.squery, this.query) + coll + " @" + this.repository.toString();
     196        return str;
     197};
     198
     199Query.prototype.toJSON = function () {
     200//Query.prototype.query_json = function () {   
     201        var dt = new Date();
     202        var str_time = dateFormat(dt);//dt.toString("dd/mm/yyyy HH:mm:ss");
     203        //var jsonq = { "options" : json_options, "bookmark" : bookmark, "time" : str_time};
     204        var json_options = this.options;
     205        if (this.options != null) {
     206                json_opts = [{}];
     207                json_opts[0] = this.options;
     208        }
     209
     210        // collections
     211        var json_coll;
     212               
     213        if (this.collection.length == 0) {
     214                json_coll = {};
     215                json_coll = "null";
     216        } else {
     217                json_coll = [{}];
     218                for (var i = 0; i < this.collection.length; i++) {
     219                        json_coll[i] = {"index" : this.collection[i].index, "name" :this.collection[i].name};
     220                }
     221        }
     222        //columns
     223        var json_cols;
     224        var colls = this.columns;
     225        if (colls == "") {
     226                //json_cols = {};
     227                json_cols = "null";
     228        } else { 
     229                var pos = this.columns.indexOf(",", 0);
     230                var i = 0;
     231               
     232                json_cols = [{}];
     233                while (pos > -1){
     234                        if (pos > -1){
     235                                json_cols[i] = cols.substring(0,pos);
     236                        } else {
     237                                json_cols[i] = cols;
     238                        }
     239                        cols = cols.substring(pos+1);
     240                        pos = cols.indexOf(",", 0);
     241                        i = i+1;
     242                }
     243               
     244                json_cols[i] = cols;
     245        }
     246
     247        var jsonq = {"name":"",
     248                             "squerystring":this.squery,
     249                                 "querystring":this.query,     
     250                                 "searchclauses":"null" ,
     251                                 "collections" : json_coll,
     252                                 "columns" : json_cols,
    169253                                 "startItem" : this.startItem,
    170                                  "maximumItems" : this.maximumItems};
    171         return JSON.stringify(jsonq);
     254                                 "maximumItems" : this.maximumItems,
     255                                 "options" : json_options, "bookmark" : "0", "time" : str_time};
     256       
     257        jsonq.name = Query.fullformatstring(jsonq);
     258       
     259        return jsonq;//JSON.stringify(jsonq);
    172260};
    173261
     
    370458        */
    371459        // FIXME: this is not nice, there should be a function providing the formatted string of the query.
    372         var coll = (this.getcollectiontext("name") != "" ) ? " in " + this.getcollectiontext("name") : ""; 
     460        //var coll = (this.getcollectiontext("name") != "" ) ? " in " + this.getcollectiontext("name") : ""; 
    373461        var x = "<div id='" + this.listid + "' class='query_wrapper ui-widget' name='query' ><div class='query_header ui-widget-header ui-state-default ui-corner-top'>" +
    374462        "<span class='cmd cmd_get'></span><span class='cmd cmd_del'> </span>" +
    375463        "<span class='query_id'>" + this.listid + "</span>: <span class='query'>" +
    376         Query.queryliststring(this.squery, this.query) + coll + " @" + this.repository.toString() + "</span>" +
     464        this.toString() +
     465        //Query.queryliststring(this.squery, this.query) + coll + " @" + this.repository.toString() +
     466        "</span>" +
    377467                        "</div>" +
    378468                        "<div class='result ui-widget-content ui-corner-bottom'></div>";
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui.js

    r1236 r1252  
    299299                jsonw["WorkspaceProfile"]["CustomTermsets"][id] = jsont;
    300300               
    301                 saveWorkspace("USER");
     301                //saveWorkspace("USER");
     302                Workspace.save("USER");
    302303                loadTermsets(jsonw["WorkspaceProfile"]["CustomTermsets"]);
    303304                //createTermsUI(jsonw["WorkspaceProfile"]["CustomTermsets"][id],$('#userterms'));
     
    327328                qid = $(this).data('query').listid;
    328329                notifyUser("here I would save query: " + qid, "debug");
     330                Workspace.saveQuery($(this).data('query'));
    329331        });
    330332
     
    384386               
    385387                jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = jsonq;
    386                 saveWorkspace("USER");
     388                //saveWorkspace("USER");
     389                Workspace.save("USER");
    387390                appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries'));
    388391               
     
    476479                       
    477480                $("#qts_select option:selected").text( $('#qts_input').val());
    478                 saveWorkspace("USER");
     481                //saveWorkspace("USER");
     482                Workspace.save("USER");
    479483        });
    480484        $('#qts_add').click(function(){
     
    491495                jsonw["WorkspaceProfile"]["Querysets"][id] = {"name":new_name,"created":str_time , "Queries" : "null"};
    492496               
    493                 saveWorkspace("USER");
     497                //saveWorkspace("USER");
     498                Workspace.save("USER");
    494499                //todo
    495500               
     
    517522                                jsonw["WorkspaceProfile"]["Querysets"] = "null";
    518523                        }
    519                         saveWorkspace("USER");
     524                        //saveWorkspace("USER");
     525                        Workspace.save("USER");
    520526                        //$("#qts_select option").remove();
    521527                        loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
     
    530536                       
    531537                $("#ts_select option:selected").text( $('#ts_input').val());
    532                 saveWorkspace("USER");
     538                //saveWorkspace("USER");
     539                Workspace.save("USER");
    533540        });
    534541        $('#ts_add').click(function(){
     
    545552                jsonw["WorkspaceProfile"]["CustomTermsets"][id] = {"name":new_name,"created":str_time , "Terms" : "null"};
    546553               
    547                 saveWorkspace("USER");
     554                //saveWorkspace("USER");
     555                Workspace.save("USER");
    548556                //todo
    549557               
     
    553561                $("#ts_select").find('option').last().attr("selected","true");
    554562                $('#ts_input').val(new_name);
    555                 createTermsUI(jsonw["WorkspaceProfile"]["CustomTermsets"][id],$('#userterms'))
     563                createTermsUI(jsonw["WorkspaceProfile"]["CustomTermsets"][id],$('#userterms'));
    556564        });
    557565        $('#ts_delete').click(function(){
     
    572580                                jsonw["WorkspaceProfile"]["CustomTermsets"] = "null";
    573581                        }
    574                         saveWorkspace("USER");
     582                        //saveWorkspace("USER");
     583                        Workspace.save("USER");
    575584                        loadTermsets(jsonw["WorkspaceProfile"]["CustomTermsets"]);
    576585        });
     
    598607                }
    599608               
    600                 saveWorkspace("USER");
     609                //saveWorkspace("USER");
     610                Workspace.save("USER");
    601611                loadTermsets(jsonw["WorkspaceProfile"]["CustomTermsets"]);
    602612                //$("#ts_select option").remove();
     
    660670                }
    661671               
    662                 saveWorkspace("USER");
     672                //saveWorkspace("USER");
     673                Workspace.save("USER");
    663674                loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
    664675                //$("#qs_select option").remove();
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_load.js

    r1233 r1252  
    290290                       
    291291                        jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq].name = $(this).val();
    292                         saveWorkspace("USER");
     292                        //saveWorkspace("USER");
     293                        Workspace.save("USER");
    293294                        evStop();
    294295                }
     
    501502}
    502503
    503 function saveWorkspace(type){
    504         var JSONText = JSON.stringify(jsonw["WorkspaceProfile"]);
    505         //var JSONText = JSON.stringify({"aa.a":"r"});
    506         //notifyUser(JSONText,'debug');
    507         $.post("/MDService2/workspaceprofilesave/" + type,{"data":JSONText});
    508        
    509 }
    510504
    511505function saveTermset(id, name, listwidget) {
     
    519513        var str_time = dateFormat(dt);//dt.toString("dd/mm/yyyy HH:mm:ss");
    520514        var jsont = {"name":name, "time" : str_time, "Terms" :terms};
    521         if (jsonw["WorkspaceProfile"]["CustomTermsets"] == undefined) {
     515        if (jsonw["WorkspaceProfile"]["CustomTermsets"] == "null") {
    522516                jsonw["WorkspaceProfile"]["CustomTermsets"] = [{}];
    523517                if (id == -1) {id = 0;};
     
    526520        jsonw["WorkspaceProfile"]["CustomTermsets"][id] = jsont;
    527521       
    528         saveWorkspace("USER"); 
     522        //saveWorkspace("USER");
     523        Workspace.save("USER");
    529524
    530525};
     
    542537                jsonw["WorkspaceProfile"]["CustomTermsets"] = "null";
    543538        }
    544         saveWorkspace("USER");
     539        //saveWorkspace("USER");
     540        Workspace.save("USER");
    545541}
    546542
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_widgets.js

    r1235 r1252  
    464464                        if (id < 2) {
    465465                                if (id == 1){
    466                                         sl.listwidget.load(this.autolist);
     466                                        sl.listwidget.load(sl.autolist.split(','));
    467467                                }else{
    468468                                        sl.listwidget.clear();
     
    486486        //$select.append(new Option(this.items[0], 0));
    487487        //$select.append(new Option(this.items[1], 1));
    488        
    489         $.each(json, function(i,item) {
    490                 items[items.length] = new ListItem(item.name);
    491                 //$select.append(new Option(item.name, i+2));
    492         });
     488        if (json != "null") {
     489                $.each(json, function(i,item) {
     490                        items[items.length] = new ListItem(item.name);
     491                        //$select.append(new Option(item.name, i+2));
     492                });
     493        }
    493494        /*
    494495        // find id of selected
Note: See TracChangeset for help on using the changeset viewer.