Commit 734aabb1 authored by Romain Courteaud's avatar Romain Courteaud Committed by Jérome Perrin

Allow to create empty document.

parent ae60f68f
......@@ -11,6 +11,9 @@
<script src="InputModule_viewAddDocumentDialog.js" type="text/javascript"></script>
</head>
<body>
<form class="new_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-plus ui-btn-icon-right">Empty</button>
</form>
<form class="import_form">
<input id="dream_import" type="file" required=""
name="dream_import">
......
......@@ -4,24 +4,21 @@
initGadgetMixin) {
"use strict";
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_post", "jio_post")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantToDisplayThisDocument",
"whoWantToDisplayThisDocument")
function createDocument(gadget, name) {
var now = new Date();
// Create jIO document
return gadget.aq_post({
title: name,
type: "Dream",
format: "application/json",
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" +
now.getDate()
});
}
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("startService", function () {
var gadget = this,
json_data,
function waitForImport(gadget) {
var json_data,
name;
return new RSVP.Queue()
......@@ -34,7 +31,7 @@
})
.push(function (evt) {
// Prevent double click
gadget.props.element
evt.target
.getElementsByClassName("ui-btn")[0].disabled = true;
var file = evt.target.dream_import.files[0];
......@@ -42,17 +39,8 @@
return promiseReadAsText(file);
})
.push(function (json) {
var now = new Date();
json_data = json;
// Create jIO document
return gadget.aq_post({
title: name,
type: "Dream",
format: "application/json",
modified: now.toUTCString(),
date: now.getFullYear() + "-" + (now.getMonth() + 1) + "-" +
now.getDate()
});
return createDocument(gadget, name);
})
.push(function (jio_document) {
// Add JSON as attachment
......@@ -62,6 +50,84 @@
"_data": json_data,
"_mimetype": "application/json"
});
});
}
function waitForNew(gadget) {
var json_data = {
nodes: {},
edges: {},
preference: {},
general: {},
wip_part_spreadsheet: [[
"Order ID",
"Due Date",
"Priority",
"Project Manager",
"Part",
"Part Type",
"Sequence",
"Processing Times",
"Prerequisites Parts"
]],
shift_spreadsheet: [[
"Day",
"Machines", // XXX more generic name ?
"Start",
"End"
]]
},
name = "FromScratch";
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("new_form")[0],
'submit',
false
);
})
.push(function (evt) {
// Prevent double click
evt.target
.getElementsByClassName("ui-btn")[0].disabled = true;
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.stringify(json_data),
"_mimetype": "application/json"
});
});
}
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_post", "jio_post")
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
.declareAcquiredMethod("whoWantToDisplayThisDocument",
"whoWantToDisplayThisDocument")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("startService", function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.any([
waitForImport(gadget),
waitForNew(gadget)
]);
})
.push(function (result) {
return gadget.whoWantToDisplayThisDocument(result.id);
......
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