Commit 6906021e authored by Jonathon Duerig's avatar Jonathon Duerig

Add logic to make sure that the context is loaded before Jacks starts.

parent 2832ea5f
...@@ -37,17 +37,28 @@ function (_, editModalString) ...@@ -37,17 +37,28 @@ function (_, editModalString)
} }
}; };
var waitingInstances = [];
var contextFetched = false;
var contextUrl = 'https://www.emulab.net/protogeni/jacks-context/cloudlab-utah.json'; var contextUrl = 'https://www.emulab.net/protogeni/jacks-context/cloudlab-utah.json';
if (window.ISCLOUD) if (window.ISCLOUD)
{ {
$('#edit_topo_modal_button').prop('disabled', true); $('#edit_topo_modal_button').prop('disabled', true);
$.get(contextUrl).then(contextReady, contextFail); $.get(contextUrl).then(contextReady, contextFail);
} }
else
{
contextFetched = true;
}
function contextReady(data) function contextReady(data)
{ {
$('#edit_topo_modal_button').prop('disabled', false); $('#edit_topo_modal_button').prop('disabled', false);
context = data; context = data;
contextFetched = true;
_.each(waitingInstances, function (f) {
f();
});
} }
function contextFail(fail1, fail2) function contextFail(fail1, fail2)
...@@ -68,7 +79,8 @@ function (_, editModalString) ...@@ -68,7 +79,8 @@ function (_, editModalString)
{ {
this.mode = 'viewer'; this.mode = 'viewer';
} }
this.render(); this.shown = false;
this.render();
} }
JacksEditor.prototype = { JacksEditor.prototype = {
...@@ -83,8 +95,9 @@ function (_, editModalString) ...@@ -83,8 +95,9 @@ function (_, editModalString)
this.root.find('#quickvm_editmodal').on('shown.bs.modal', _.bind(this.handleShown, this)); this.root.find('#quickvm_editmodal').on('shown.bs.modal', _.bind(this.handleShown, this));
this.root.find('#edit-save').click(_.bind(this.fetchXml, this)); this.root.find('#edit-save').click(_.bind(this.fetchXml, this));
this.root.find('#edit-cancel, #edit-dismiss') this.root.find('#edit-cancel, #edit-dismiss')
.click(_.bind(this.cancelEdit, this)); .click(_.bind(this.cancelEdit, this));
this.instance = new window.Jacks({ var makeInstance = function () {
this.instance = new window.Jacks({
mode: this.mode, mode: this.mode,
source: 'rspec', source: 'rspec',
root: '#edit_nopicker', root: '#edit_nopicker',
...@@ -99,7 +112,17 @@ function (_, editModalString) ...@@ -99,7 +112,17 @@ function (_, editModalString)
}, },
canvasOptions: context.canvasOptions, canvasOptions: context.canvasOptions,
constraints: context.constraints constraints: context.constraints
}); });
}.bind(this);
if (contextFetched)
{
makeInstance();
}
else
{
waitingInstances.push(makeInstance);
}
}, },
// Show a modal that lets the user edit their rspec. Callback // Show a modal that lets the user edit their rspec. Callback
......
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