/**
* @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 = '