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

Allow to save shift spreadsheet

parent 9a8712e0
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Edit Wip Part Spreadsheet</title> <title>Edit Shift Spreadsheet</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script> <script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquery.relative_dest %>" type="text/javascript"></script>
<script src="../<%= curl.jquerymobilejs.relative_dest %>" type="text/javascript"></script>
<script src="mixin_gadget.js" type="text/javascript"></script> <script src="mixin_gadget.js" type="text/javascript"></script>
<script src="Input_viewShiftSpreadsheet.js" type="text/javascript"></script> <script src="Input_viewShiftSpreadsheet.js" type="text/javascript"></script>
...@@ -13,5 +15,9 @@ ...@@ -13,5 +15,9 @@
<body> <body>
<div data-gadget-url="../handsontable/index.html" <div data-gadget-url="../handsontable/index.html"
data-gadget-scope="tableeditor"></div> data-gadget-scope="tableeditor"></div>
<form class="save_form">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right">Save</button>
</form>
</body> </body>
</html> </html>
/*global rJS, RSVP, initGadgetMixin */ /*global rJS, RSVP, initGadgetMixin, loopEventListener */
(function (window, rJS, RSVP, initGadgetMixin) { (function (window, rJS, RSVP, initGadgetMixin, loopEventListener) {
"use strict"; "use strict";
function saveSpreadsheet(evt) {
var gadget = this,
editor_data,
editor_gadget;
return new RSVP.Queue()
.push(function () {
// Prevent double click
evt.target.getElementsByClassName("ui-btn")[0].disabled = true;
return gadget.getDeclaredGadget("tableeditor");
})
.push(function (tablegadget) {
editor_gadget = tablegadget;
return editor_gadget.getData();
})
.push(function (data) {
editor_data = data;
// Always get a fresh version, to prevent deleting spreadsheet & co
return gadget.aq_getAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json"
});
})
.push(function (body) {
var data = JSON.parse(body);
data.shift_spreadsheet = JSON.parse(editor_data);
return gadget.aq_putAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json",
"_data": JSON.stringify(data, null, 2),
"_mimetype": "application/json"
});
})
.push(function () {
evt.target.getElementsByClassName("ui-btn")[0].disabled = false;
});
}
function waitForSave(gadget) {
return loopEventListener(
gadget.props.element.getElementsByClassName("save_form")[0],
'submit',
false,
saveSpreadsheet.bind(gadget)
);
}
var gadget_klass = rJS(window); var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass); initGadgetMixin(gadget_klass);
gadget_klass gadget_klass
...@@ -36,9 +83,13 @@ ...@@ -36,9 +83,13 @@
}) })
.declareMethod("startService", function () { .declareMethod("startService", function () {
var gadget = this;
return this.getDeclaredGadget("tableeditor") return this.getDeclaredGadget("tableeditor")
.push(function (tableeditor) { .push(function (tableeditor) {
return tableeditor.startService(); return RSVP.all([
tableeditor.startService(),
waitForSave(gadget)
]);
}); });
}); });
}(window, rJS, RSVP, initGadgetMixin)); }(window, rJS, RSVP, initGadgetMixin, loopEventListener));
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