Commit f772222a authored by Jérome Perrin's avatar Jérome Perrin

GUI: Add a new button to directly create an instance of the default configuration

This uses a symlink ! I am afraid this does not work on windows
parent de4dc365
......@@ -316,7 +316,8 @@ module.exports = function (grunt) {
'**/*.png',
'**/*.jpg',
'**/*.js',
'**/*.css'
'**/*.css',
'**/*.json'
],
dest: '<%= global_config.dest %>/manifest.appcache'
}
......
......@@ -16,5 +16,8 @@
name="dream_import">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-plus ui-btn-icon-right">Import</button>
</form>
<form class="create_new_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-plus ui-btn-icon-right">Create New Empty</button>
</form>
</body>
</html>
\ No newline at end of file
/*global rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin */
initGadgetMixin, prompt */
(function (window, rJS, RSVP, promiseEventListener, promiseReadAsText,
initGadgetMixin) {
"use strict";
......@@ -55,6 +55,41 @@
});
}
function waitForCreateNew(gadget) {
var json_data,
name;
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("create_new_form")[0],
'submit',
false
);
})
.push(function (evt) {
// Prevent double click
evt.target
.getElementsByClassName("ui-btn")[0].disabled = true;
return gadget.aq_ajax({url: "../DefaultConfiguration.json", type:"GET"});
})
.push(function (evt) {
name = prompt("Name for this model");
var data = JSON.parse(evt.target.responseText);
data.general.name = name;
json_data = JSON.stringify(data);
return createDocument(gadget, name);
})
.push(function (jio_document) {
// Add JSON as attachment
return gadget.aq_putAttachment({
"_id": jio_document.id,
"_attachment": "body.json",
"_data": json_data,
"_mimetype": "application/json"
});
});
}
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass
......@@ -62,6 +97,7 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_post", "jio_post")
.declareAcquiredMethod("aq_ajax", "jio_ajax")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantsToDisplayThisDocument",
......@@ -75,7 +111,7 @@
return new RSVP.Queue()
.push(function () {
return waitForImport(gadget);
return RSVP.any([waitForImport(gadget), waitForCreateNew(gadget)]);
})
.push(function (result) {
return gadget.whoWantsToDisplayThisDocument(result.id);
......
../../simulation/Examples/GUI_instances/DefaultConfiguration.json
\ No newline at end of file
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