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");
}
function getJSON(urlString) {
function getJSON(urlString, successFunction) {
robustAjax(urlString, "json", true, successFunction);
}
function getSyncJSON(urlString) {
return syncAjax(urlString, "json");
}
function syncAjax(urlString, dataType) {
function syncAjax(urlString, dataType)
{
var result = null;
robustAjax(urlString, dataType, false, function(data) {
result = data;
});
return result;
}
function robustAjax(urlString, dataType, isAsync, successFunction) {
$.ajax({
url: urlString,
datatype: dataType,
async: false,
success: function(data) {
result = data;
},
async: isAsync,
success: successFunction,
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error from model.js -> getJSON:");
console.log("jqXHR:");
......@@ -24,7 +39,6 @@ function syncAjax(urlString, dataType) {
console.log("urlString: " + urlString);
}
});
return result;
}
function getTranslation(text) {
......
......@@ -87,35 +87,44 @@ function saveUrlString(urlString) {
function showStudies() {
if (!Model.studies) {
Model.studies = loadFromRestServer("studies").studies;
loadFromRestServer("studies", function(data) {
Model.studies = data.studies;
showStudies();
});
}
var html = studiesTemplate(Model);
$('#nesstarTouchContent').empty();
$('#nesstarTouchContent').append(html);
else {
var html = studiesTemplate(Model);
$('#nesstarTouchContent').empty();
$('#nesstarTouchContent').append(html);
}
}
function showStudyMetadata(studyId) {
var studyMetadata = loadFromRestServer("study/"+studyId);
var templateObject = {}
templateObject.variables = loadFromRestServer("study/"+studyId+"/variables").variables;
$('#nesstarTouchContent').empty();
var html = studyMetadataTemplate(templateObject);
$('#nesstarTouchContent').append(html);
html = getMetadataHtml(Model.studyMetadataSelection, studyMetadata);
$('#studyMetadata').append(html);
loadFromRestServer("study/"+studyId, function(studyMetadata) {
loadFromRestServer("study/"+studyId+"/variables", function(variables) {
var templateObject = {}
templateObject.variables = variables.variables;
$('#nesstarTouchContent').empty();
var html = studyMetadataTemplate(templateObject);
$('#nesstarTouchContent').append(html);
html = getMetadataHtml(Model.studyMetadataSelection, studyMetadata);
$('#studyMetadata').append(html);
});
});
}
function showVariableMetadata(variableId) {
var variableMetadata = loadFromRestServer("variable/"+variableId);
var templateObject = {}
templateObject.variableId = variableId;
$('#nesstarTouchContent').empty();
var html = variableMetadataTemplate(templateObject);
$('#nesstarTouchContent').append(html);
html = getMetadataHtml(Model.variableMetadataSelection, variableMetadata);
$('#variableMetadata').append(html);
loadFromRestServer("variable/"+variableId, function(variableMetadata) {
var templateObject = {}
templateObject.variableId = variableId;
$('#nesstarTouchContent').empty();
var html = variableMetadataTemplate(templateObject);
$('#nesstarTouchContent').append(html);
html = getMetadataHtml(Model.variableMetadataSelection, variableMetadata);
$('#variableMetadata').append(html);
});
}
\ No newline at end of file
......@@ -58,11 +58,11 @@ function Correlation() {
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() {
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