Commit 0303aa51 authored by Jérome Perrin's avatar Jérome Perrin

New gadget to attach a binary document

parent 3d561951
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Create Document</title>
<script src="../<%= copy.rsvp.relative_dest %>" type="text/javascript"></script>
<script src="../<%= copy.renderjs.relative_dest %>" type="text/javascript"></script>
<script src="mixin_gadget.js" type="text/javascript"></script>
<script src="mixin_promise.js" type="text/javascript"></script>
<script src="Input_viewAttachDocument.js" type="text/javascript"></script>
</head>
<body>
<form class="attach_document">
<input type="file" required="" name="import_file">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline ui-icon-plus ui-btn-icon-right">Attach Document</button>
</form>
</body>
</html>
\ No newline at end of file
/*global rJS, RSVP, promiseEventListener, promiseReadAsDataURL,
initGadgetMixin */
(function (window, rJS, RSVP, promiseEventListener, promiseReadAsDataURL,
initGadgetMixin) {
"use strict";
var gadget_klass = rJS(window);
initGadgetMixin(gadget_klass);
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("aq_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("aq_getAttachment", "jio_getAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("startService", function () {
var gadget = this,
encoded_data,
button;
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.getElementsByClassName("attach_document")[0],
'submit',
false
);
})
.push(function (evt) {
button = evt.target.getElementsByClassName("ui-btn")[0];
button.disabled = true;
var file = evt.target.import_file.files[0];
return promiseReadAsDataURL(file);
})
.push(function (filecontent) {
encoded_data = filecontent;
// get fresh version
return gadget.aq_getAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json"
});
})
.push(function (jio_data) {
var data = JSON.parse(jio_data);
data.input[gadget.props.action_definition.input_id] = encoded_data;
return gadget.aq_putAttachment({
"_id": gadget.props.jio_key,
"_attachment": "body.json",
"_data": JSON.stringify(data)
});
}).push(function (){
button.disabled = false;
});
})
.declareMethod("render", function (options) {
var gadget = this;
this.props.jio_key = options.id;
this.props.action_definition = options.action_definition;
});
}(window, rJS, RSVP, promiseEventListener, promiseReadAsDataURL,
initGadgetMixin));
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