Commit d3465cbc authored by Eirik Alvær's avatar Eirik Alvær

Made many of the ajax calls async.

parent 0153d886
function loadFromRestServer(urlEnding) { function loadFromRestServer(urlEnding, successFunction) {
var url = Model.restServerURL + "/" + urlEnding;
robustAjax(url, "json", true, successFunction);
}
function loadSyncFromRestServer(urlEnding) {
return syncAjax(Model.restServerURL + "/" + urlEnding, "json"); return syncAjax(Model.restServerURL + "/" + urlEnding, "json");
} }
function getJSON(urlString) { function getJSON(urlString, successFunction) {
robustAjax(urlString, "json", true, successFunction);
}
function getSyncJSON(urlString) {
return syncAjax(urlString, "json"); return syncAjax(urlString, "json");
} }
function syncAjax(urlString, dataType) { function syncAjax(urlString, dataType)
{
var result = null; var result = null;
robustAjax(urlString, dataType, false, function(data) {
result = data;
});
return result;
}
function robustAjax(urlString, dataType, isAsync, successFunction) {
$.ajax({ $.ajax({
url: urlString, url: urlString,
datatype: dataType, datatype: dataType,
async: false, async: isAsync,
success: function(data) { success: successFunction,
result = data;
},
error: function(jqXHR, textStatus, errorThrown) { error: function(jqXHR, textStatus, errorThrown) {
console.log("Error from model.js -> getJSON:"); console.log("Error from model.js -> getJSON:");
console.log("jqXHR:"); console.log("jqXHR:");
...@@ -24,7 +39,6 @@ function syncAjax(urlString, dataType) { ...@@ -24,7 +39,6 @@ function syncAjax(urlString, dataType) {
console.log("urlString: " + urlString); console.log("urlString: " + urlString);
} }
}); });
return result;
} }
function getTranslation(text) { function getTranslation(text) {
......
...@@ -87,35 +87,44 @@ function saveUrlString(urlString) { ...@@ -87,35 +87,44 @@ function saveUrlString(urlString) {
function showStudies() { function showStudies() {
if (!Model.studies) { if (!Model.studies) {
Model.studies = loadFromRestServer("studies").studies; loadFromRestServer("studies", function(data) {
Model.studies = data.studies;
showStudies();
});
} }
var html = studiesTemplate(Model); else {
$('#nesstarTouchContent').empty(); var html = studiesTemplate(Model);
$('#nesstarTouchContent').append(html); $('#nesstarTouchContent').empty();
$('#nesstarTouchContent').append(html);
}
} }
function showStudyMetadata(studyId) { function showStudyMetadata(studyId) {
var studyMetadata = loadFromRestServer("study/"+studyId); loadFromRestServer("study/"+studyId, function(studyMetadata) {
var templateObject = {} loadFromRestServer("study/"+studyId+"/variables", function(variables) {
templateObject.variables = loadFromRestServer("study/"+studyId+"/variables").variables; var templateObject = {}
templateObject.variables = variables.variables;
$('#nesstarTouchContent').empty();
var html = studyMetadataTemplate(templateObject); $('#nesstarTouchContent').empty();
$('#nesstarTouchContent').append(html); var html = studyMetadataTemplate(templateObject);
$('#nesstarTouchContent').append(html);
html = getMetadataHtml(Model.studyMetadataSelection, studyMetadata);
$('#studyMetadata').append(html); html = getMetadataHtml(Model.studyMetadataSelection, studyMetadata);
$('#studyMetadata').append(html);
});
});
} }
function showVariableMetadata(variableId) { function showVariableMetadata(variableId) {
var variableMetadata = loadFromRestServer("variable/"+variableId); loadFromRestServer("variable/"+variableId, function(variableMetadata) {
var templateObject = {} var templateObject = {}
templateObject.variableId = variableId; templateObject.variableId = variableId;
$('#nesstarTouchContent').empty(); $('#nesstarTouchContent').empty();
var html = variableMetadataTemplate(templateObject); var html = variableMetadataTemplate(templateObject);
$('#nesstarTouchContent').append(html); $('#nesstarTouchContent').append(html);
html = getMetadataHtml(Model.variableMetadataSelection, variableMetadata); html = getMetadataHtml(Model.variableMetadataSelection, variableMetadata);
$('#variableMetadata').append(html); $('#variableMetadata').append(html);
});
} }
\ No newline at end of file
...@@ -58,11 +58,11 @@ function Correlation() { ...@@ -58,11 +58,11 @@ function Correlation() {
this.correlationVariableIds = []; this.correlationVariableIds = [];
} }
Model.studyMetadataSelection = getJSON("/metadata-selection/study-metadata-selection.json"); Model.studyMetadataSelection = getSyncJSON("/metadata-selection/study-metadata-selection.json");
Model.variableMetadataSelection = getJSON("/metadata-selection/variable-metadata-selection.json"); Model.variableMetadataSelection = getSyncJSON("/metadata-selection/variable-metadata-selection.json");
Model.metadataTranslation = getJSON(Model.restServerURL + "/metadata-translation/en").metadataTranslation; Model.metadataTranslation = loadSyncFromRestServer("metadata-translation/en").metadataTranslation;
function initNewTabulation() { function initNewTabulation() {
Model.urlObject.tabulation = new Tabulation(); Model.urlObject.tabulation = new Tabulation();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment