/** * @fileOverview The file contains app load functionality. The load functions actualy used provides client side model building together with * ui building. The load module is independant from app pane-layout and all ui-layout functionality. * * @author * @version */ function loadData(){ //loadWelcomeMessage(); loadTooltiptable(); loadWorkspaceProfiles(); //loadCollections(); // loaded after WorkspaceProfile is loaded //loadTerms(); // loaded after WorkspaceProfile is loaded //loadTermsAutocomplete(); //handleQueryInput(); //createTooltip() //loadComponentsRegistry(); //loadDCR(); } function loadTooltiptable() { var uri = window.location.pathname + "/../../static/info.xml"; $.get(uri,function(data, textStatus){ $(data).find('#commands').find('dt').each(function(){ tooltiptable[$(this).attr("id")] = $(this).text(); //$(this).next('dd').text(); }); },'html'); }; /* function loadAdminFile(){ json_admin = {'Admin':{'maxqid':'0','QueryIndices':'null'}}; jQuery.getJSON("/MDService2/workspaceprofile/admin",function(data){ json_admin = preprocessJSON(data); }); } */ function loadWorkspaceProfiles(){ //empty json workspace.user_json = {'WorkspaceProfile':{'CustomTermsets':'null','Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}}; $('#qts_input').val(""); $.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) { alert(textStatus); alert(errorThrown); alert(XMLHttpRequest.responseText); }}); // server profile first - options needed jQuery.getJSON("/MDService2/workspaceprofile/server?format=json",function(sdata){ //notifyUser(sdata['WorkspaceProfile'],'debug'); var json = preprocessJSON(sdata); workspace.server_json = json; $("#serverqs").attr("data",JSON.stringify(json)); loadQuerysets("server"); loadRepositories(workspace.server_json["WorkspaceProfile"]["Repositories"]); loadCollections(true); loadTerms(); //loadTermsAutocomplete(); loadQueryFromUriParams(); createTooltip(null); // USER WORKSPACEPROFILE jQuery.getJSON("/MDService2/workspaceprofile/user?format=json",function(data){ notifyUser(data['WorkspaceProfile'],'debug'); workspace.user_json = preprocessJSON(data); loadQuerysets("user"); loadBookmarksets(); createTooltip(this); loadTermsAutocomplete(); }); }); } function loadCollections(ini){ var coll_uri = link('collections','htmllist?repository=' + getSelectedRepository()); $("#collections").jstree({ "html_data" : { "ajax" : { "url" : coll_uri, "data" : function (n) { return { //id : n.attr ? n.attr("id") : 0 , collection : n.attr ? n.attr("handle") : "", maxdepth : n.attr ? 2 : 1 }; } } }, types : { // the default type "default" : { "max_children" : -1, "max_depth" : -1, "valid_children": "all" } }, "plugins" : [ "themes", "html_data", "ui" , "checkbox", "types", "search" ] }); $('#collections').bind('loaded.jstree reopen.jstree', function(event, data) { if ((event.type == "loaded") &&(ini)) { loadQueryFromUriParams(); } var dataelems = data.inst.get_container(); createTooltip($(dataelems)); //data.inst.get_container().unblock(); }); $('#collections').bind("change_state.jstree", function (event, data) { var dataelems = data.inst.get_container(); var coll; if (!local_collections){ var collections = []; //collections.splice(0, collections.length); $(this).find('.jstree-checked').each(function(index){ if (!($(this).parent().parent().hasClass("jstree-checked")) ) { //notifyUser("selection...:" + index + ":" + String.trim($(this).children('a').text()) + $(this).attr("handle"),'debug'); coll = new Collection($(this).attr("handle"), String.trim($(this).children('a').text())); collections[collections.length] = coll; } }); collections_widget.load(collections); } }); $('#collections').bind("search.jstree", function (e, data) { if (data.rslt.nodes.length > 0){ $('#collections').jstree("checkbox.check_node",data.rslt.nodes[0]); } //alert("Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'."); }); }; function updateCollectionTree(){ /* local_collections = true; var cc = $('#collections').jstree("get_checked"); $('#collections').jstree("uncheck_all"); $.each(collections, function(){ $('#collections').jstree("search",this.name); }); local_collections = false; */ }; function loadTerms(){ $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository()); $('#terms-select').live('change', function(event) { //notifyUser(this.value,'debug'); update(link('terms', 'htmllist', this.value)+ '?maxdepth=' + actions.terms.maxdepth + '&repository=' + getSelectedRepository(), '#terms-select', '#model_terms', function() { $("#model_terms .treeview").treeview({ animated: "fast", collapsed: false }); //notifyUser($("#model_terms .treeview"),'debug'); notifyUser("loaded: #model_terms .treeview",'debug'); createTooltip(this); } ); } ); $('#terms .cmd_filter').live('click', function(event) { var term = $(this).parent().children('span.data').text(); if ($('.searchtype_text','#search').size()> 0 ) { var t = $('#query_area').text(); $('#query_area').val(t + " " + term); } else { searchclauseset.updatedata(term); } }); $('#terms .cmd_columns').live('click', function(event) { var term = $(this).parent().children('span.data').text(); columns_widget.add(new ListItem(term)); }); } function loadRepositories(json) { var $select; $select = $('#repositories_select'); $select.find("option").remove(); if (String(json) != "null") { $.each(json, function(i,item) { $select.append(new Option(this.name, this.id)); }); } // select first if (url_params["repository"] != undefined){ var r = parseInt(url_params["repository"])-1; $($select.find("option")[r]).attr("selected","true"); } else { $select.find("option").first().attr("selected","true"); } $select.change(function(data){ if (workspace.getRepositoryType(getSelectedRepository())=='md'){ loadCollections(false); loadTerms(); loadTermsAutocomplete(); $('#model_profiles').load(link('terms','htmlselect',actions.terms.current) + '?repository=' + getSelectedRepository()); } }); } function loadTermsAutocompleteExplain(){ element_autocomplete_explain.splice(0, element_autocomplete_explain.length ); $('#termset_autocomplete_explain').children().remove(); $('#termset_autocomplete_explain').css('display','none'); $('#terms_autocomplete_explain').children().remove(); $('#terms_autocomplete_explain').css('display','none'); $('#termset_autocomplete_explain').load(link('fcs','?operation=explain&x-context=' + getSelectedRepository()),function(){ $(this).find("indexInfo").children("set").each(function(index){ //element_autocomplete[index].data[term_index].values[i] = {label:$(this).find('index').children('title').text()}; var _key, _name, _id, _parent, _isleaf = 0; _key = $(this).attr("name"); _name = $(this).children("title").text(); _parent = $(this).parents('indexInfo'); _id = $(this).attr("identifier"); _isleaf = 1;//TODO element_autocomplete_explain[index] = { label:_name, value:_name, key:_key, id:_id, parent:_parent, isleaf:_isleaf, data:[]}; }); // add autocomplete 's //searchclauseset.initAutocomplete(true); //columns_widget.initAutocomplete(element_autocomplete_explain, true); searchclauseset.initAutocomplete(false); }); }; function loadTermsAutocomplete(){ //var elem; $('#termset_autocomplete').children().remove(); $('#termset_autocomplete').css('display','none'); $('#terms_autocomplete').children().remove(); $('#terms_autocomplete').css('display','none'); //$.get(link('smc','list/?context=*'),function(){ $('#termset_autocomplete').load(link('smc','list/?context=*'),function(){ $(this).find('Termset').each(function(index){ var _key, _name, _id, _parent, _isleaf = 0; _key = $(this).children("key").text(); _name = $(this).children("name").text(); _parent = $(this).parents('Termset'); _id = $(this).children("id").text(); if ($(this).children('Termset').length == 0){ _isleaf = 1; } element_autocomplete[index] = { label:_name, value:_name, key:_key, id:_id, parent:_parent, isleaf:_isleaf, data:[]}; // obsolete // create div for each element //elements_hashtable[elem] = new Array();//$(this).html() //$('#terms_autocomplete').append($('
').attr("id","elements_hashtable_" + elem)); }); // add autocomplete 's //searchclauseset.initAutocomplete(false); //columns_widget.initAutocomplete(element_autocomplete); //load explain autocomplete array loadTermsAutocompleteExplain(); }); }; // QUERYSETS UI function appendQueryUI(json,i, qs){ var del = ''; var name = ''; //var ul; var id = $(qs).parent().attr('id'); if (id == 'userqs') { del = ' '; name = '
name:
'; } else { name = '
name:' + json.name + '
'; } var timestr = ""; if (json.time != undefined){ timestr = json.time; } var qq = json.querystring; if (qq == "[NULL]"){ qq = ""; } var x = '
' + json.name + '' + del + '
' + name + '
query:' + Query.simplequerystring(qq) + '
' + '
collections:' + Query.collectiontext(json) + '
' + '
columns:' + Query.columnstext(json) + '
' + '
time:' + timestr + '
' + //'
startItem:' + Query.startItem + '
' + //'
maxItems:' + Query.maximumItems + '
' + //'
repository:' + Query.repository + '
' + '
bookmark:' + json.bookmark + '
' + '
options:' + Query.optionstext(json) + '
' + '
'; //dt = Date.parse('2010-10-18, 10:06 AM'); dt.toString('dd/mm/yyyy HH:mm:ss GMT') $(qs).append(x); var query = new Query([],"",""); query.load(json); $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query); $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json); $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').find('.input-name').data('queryjson',json); $(qs).find('.detail').css({'z-index' : '1000'}); $(qs).find('.input-name').keydown(function(ev){ var evStop = function(){ ev.stopPropagation(); ev.preventDefault(); }; if (ev.which === 13) { $(this).data("queryjson").name = $(this).val(); workspace.savequeryset($(this).data("queryjson"),0); //todo update $(this).parent().parent().parent().find('a').text($(this).val()); //Workspace.save("user"); //var query = new Query(); //query.load($(this).data("queryjson")); //query.save(); /* var id = parseInt( $("#qts_select option:selected").val()); $(this).parent().parent().parent().find('a').text($(this).val()); var str = $(this).parent().parent().parent().find('a').attr("href"); var iq = parseInt(str.substring(7)); jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq].name = $(this).val(); //saveWorkspace("USER"); Workspace.save("USER"); */ evStop(); } }); createTooltip(qs); } function createQueriesUI(json, qs){ $(qs).children().remove(); if (json.Queries != "null") { $.each(json.Queries, function(i,item) { if (this != "null"){ appendQueryUI(this,i, qs); } }); } } function loadQuerysets(type) { var json = workspace.getTypedElement(type, 'queryset'); var $select; if (type == "user") { $select = $('#qts_select'); } else { $select = $('#serverqts_select'); } $select.find("option").remove(); if (String(json) != "null") { $.each(json, function(i,item) { //notifyUser(i + ',' + this.name + ',' + this.created,'debug'); $select.append(new Option(this.name, i)); }); // find id of selected if ($select.find("option").size() > 0) { $select.find("option").first().attr("selected","true"); var id = parseInt($select.find("option:selected").val()); var jsonq = json[id]; //var jsonq = $select.find("option:selected").val(); if (type == "user") { $('#qts_input').val(jsonq["name"]); qs = $("#userqueries"); } else { qs = $("#serverqueries"); } createQueriesUI(jsonq, qs); } $select.change(function(data){ if ($select.find("option").size() > 0) { // find id of selected var id = parseInt($select.find("option:selected").val()); var jsonq = json[id]; //var jsonq = $select.find("option:selected").val(); if (type == "user") { $('#qts_input').val(jsonq["name"]); qs = $("#userqueries"); } else { qs = $("#serverqueries"); } createQueriesUI(jsonq, qs); } }); } } // BOOKMARKS UI function appendBookmarkUI(json,i, bs){ var del = ''; var name = ''; var id = $(bs).parent().attr('id'); del = ' '; name = '
name:
'; var timestr = ""; if (json.time != undefined){ timestr = json.time; } var qq = json.querystring; if (qq = "[NULL]"){ qq = ""; } var x = '
' + json.name + '' + del + '
' + name + '
query:' + Query.simplequerystring(qq) + '
' + '
collections:' + Query.collectiontext(json) + '
' + '
columns:' + Query.columnstext(json) + '
' + '
time:' + timestr + '
' + '
bookmark:' + json.bookmark + '
' + '
options:' + Query.optionstext(json) + '
' + '
'; $(bs).append(x); var query = new Query([],"",""); query.load(json); $(bs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query); $(bs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json); $(bs).find('.input-name').data('queryjson',json); $(bs).find('.detail').css({'z-index' : '1000'}); $(bs).find('.input-name').keydown(function(ev){ var evStop = function(){ ev.stopPropagation(); ev.preventDefault(); }; if (ev.which === 13) { $(this).data("queryjson").name = $(this).val(); $(this).data("query").name = $(this).val(); workspace.save("user"); evStop(); } }); createTooltip(qs); } function createBookmarksUI(json, bs){ $(bs).children().remove(); if (json.Bookmarks != "null") { $.each(json.Bookmarks, function(i,item) { if (this != "null"){ appendBookmarkUI(this,i, bs); } }); } } function loadBookmarksets() { var json = workspace.getTypedElement('user','bookmarkset'); var $select = $('#bts_select'); $select.find("option").remove(); if (String(json) != "null") { $.each(json, function(i,item) { $select.append(new Option(this.name, i)); }); // find id of selected if ($select.find("option").size() > 0) { $select.find("option").first().attr("selected","true"); var id = parseInt($select.find("option:selected").val()); var jsonb = json[id]; $('#bts_input').val(jsonb["name"]); //qs = $("#bookmarks"); createBookmarksUI(jsonb, $("#bookmarks")); } $select.change(function(data){ if ($select.find("option").size() > 0) { // find id of selected var id = parseInt($select.find("option:selected").val()); var jsonq = json[id]; $('#bts_input').val(jsonq["name"]); bs = $("#bookmarks"); createBookmarksUI(jsonq, bs); } }); } } function preprocessJSON(json){ if (json["Admin"] != undefined) { if (json["Admin"]["QueryIndices"] != undefined){ if (String(json["Admin"]["QueryIndices"]) != "null") { if (json["Admin"].QueryIndices[0] == undefined){ var jj = json["Admin"]["QueryIndices"]["item"]; delete json["Admin"]["QueryIndices"]["item"]; json["Admin"]["QueryIndices"] = [{}]; json["Admin"]["QueryIndices"][0] = jj; } } } } if (json["WorkspaceProfile"]["CustomTermsets"] != undefined){ if (String(json["WorkspaceProfile"]["CustomTermsets"]) != "null") { if (json["WorkspaceProfile"].CustomTermsets[0] == undefined){ var jj = json["WorkspaceProfile"]["CustomTermsets"]["item"]; delete json["WorkspaceProfile"]["CustomTermsets"]["item"]; json["WorkspaceProfile"]["CustomTermsets"] = [{}]; json["WorkspaceProfile"]["CustomTermsets"][0] = jj; } $.each(json["WorkspaceProfile"]["CustomTermsets"], function(i,item) { if (this.Terms[0] == undefined){ var jj = this["Terms"]["item"]; delete this["Terms"]["item"]; this.Terms = [{}]; this.Terms[0] = jj; } }); } } if (json["WorkspaceProfile"].Querysets[0] == undefined){ var jj = json["WorkspaceProfile"]["Querysets"]["item"]; delete json["WorkspaceProfile"]["Querysets"]["item"]; json["WorkspaceProfile"]["Querysets"] = [{}]; json["WorkspaceProfile"]["Querysets"][0] = jj; } if (json["WorkspaceProfile"].Bookmarksets[0] == undefined){ var jj = json["WorkspaceProfile"]["Bookmarksets"]["item"]; delete json["WorkspaceProfile"]["Bookmarksets"]["item"]; json["WorkspaceProfile"]["Bookmarksets"] = [{}]; json["WorkspaceProfile"]["Bookmarksets"][0] = jj; } if (String(json["WorkspaceProfile"]["Querysets"]) != "null") { $.each(json["WorkspaceProfile"]["Querysets"], function(i,item) { if (this.Queries[0] == undefined){ var jj = this["Queries"]["item"]; delete this["Queries"]["item"]; this.Queries = [{}]; this.Queries[0] = jj; } }); $.each(json["WorkspaceProfile"]["Querysets"], function(i,item){ if (String(this.Queries) != "null") { $.each(this.Queries, function(i,item){ if (this.collections != "null") { if (this.collections[0] == undefined){ var jj = this["collections"]["item"]; delete this["collections"]["item"]; this.collections = [{}]; this.collections[0] = jj; } } if (this.columns != "null") { if (this.columns[0] == undefined){ var jj = this["columns"]["item"]; delete this["columns"]["item"]; this.columns = [{}]; this.columns[0] = jj; } } }); } }); } if (String(json["WorkspaceProfile"]["Bookmarksets"]) != "null") { $.each(json["WorkspaceProfile"]["Bookmarksets"], function(i,item) { if (this.Bookmarks[0] == undefined){ var jj = this["Bookmarks"]["item"]; delete this["Bookmarks"]["item"]; this.Bookmarks = [{}]; this.Bookmarks[0] = jj; } }); $.each(json["WorkspaceProfile"]["Bookmarksets"], function(i,item){ if (String(this.Bookmarks) != "null") { $.each(this.Bookmarks, function(i,item){ if (this.collections != "null") { if (this.collections[0] == undefined){ var jj = this["collections"]["item"]; delete this["collections"]["item"]; this.collections = [{}]; this.collections[0] = jj; } } if (this.columns != "null") { if (this.columns[0] == undefined){ var jj = this["columns"]["item"]; delete this["columns"]["item"]; this.columns = [{}]; this.columns[0] = jj; } } }); } }); } return json; } function saveTermset(id, name, listwidget) { var terms = [{}]; $.each(listwidget.widgets,function(i,elem){ terms[i] = elem.name; }); var dt = new Date(); var str_time = dateFormat(dt);//dt.toString("dd/mm/yyyy HH:mm:ss"); var jsont = {"name":name, "time" : str_time, "Terms" :terms}; workspace.addelement("customtermset",jsont); workspace.save("user"); /* if (jsonw["WorkspaceProfile"]["CustomTermsets"] == "null") { jsonw["WorkspaceProfile"]["CustomTermsets"] = [{}]; if (id == -1) {id = 0;}; } if (id == -1) {id = jsonw["WorkspaceProfile"]["CustomTermsets"].length;}; jsonw["WorkspaceProfile"]["CustomTermsets"][id] = jsont; //saveWorkspace("USER"); Workspace.save("USER"); */ }; function removeTermset(id){ workspace.removeelement("customtermset",id); workspace.save("user"); /* var size = jsonw["WorkspaceProfile"]["CustomTermsets"].length; for (var i=id;i