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 @@ ...@@ -11,6 +11,9 @@
<script src="InputModule_viewAddDocumentDialog.js" type="text/javascript"></script> <script src="InputModule_viewAddDocumentDialog.js" type="text/javascript"></script>
</head> </head>
<body> <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"> <form class="import_form">
<input id="dream_import" type="file" required="" <input id="dream_import" type="file" required=""
name="dream_import"> name="dream_import">
......
...@@ -4,6 +4,106 @@ ...@@ -4,6 +4,106 @@
initGadgetMixin) { initGadgetMixin) {
"use strict"; "use strict";
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()
});
}
function waitForImport(gadget) {
var json_data,
name;
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("import_form")[0],
'submit',
false
);
})
.push(function (evt) {
// Prevent double click
evt.target
.getElementsByClassName("ui-btn")[0].disabled = true;
var file = evt.target.dream_import.files[0];
name = file.name;
return promiseReadAsText(file);
})
.push(function (json) {
json_data = json;
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"
});
});
}
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); var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass gadget_klass
...@@ -20,48 +120,14 @@ ...@@ -20,48 +120,14 @@
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("startService", function () { .declareMethod("startService", function () {
var gadget = this, var gadget = this;
json_data,
name;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return promiseEventListener( return RSVP.any([
gadget.props.element.getElementsByClassName("import_form")[0], waitForImport(gadget),
'submit', waitForNew(gadget)
false ]);
);
})
.push(function (evt) {
// Prevent double click
gadget.props.element
.getElementsByClassName("ui-btn")[0].disabled = true;
var file = evt.target.dream_import.files[0];
name = file.name;
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()
});
})
.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"
});
}) })
.push(function (result) { .push(function (result) {
return gadget.whoWantToDisplayThisDocument(result.id); 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