Commit afa76a0e authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Add download and export gadgets

parent 893e6ce9
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gadget OnlyOffice Upload</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_ojs_download_convert.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_pt_form_dialog.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, jIO, document, URL */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, jIO, document, URL) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('upload_extension'),
gadget.getSetting('file_extension')
]);
})
.push(function (result) {
return gadget.changeState({
jio_key: options.jio_key,
upload_extension: result[0],
file_extension: result[1]
});
});
})
.onStateChange(function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
"_actions": {"put": {}},
"form_id": {},
"dialog_id": {},
"my_format": {
"title": "Format",
"default": gadget.state.upload_extension,
"key": "format",
"first_item": 0,
"items": [gadget.state.upload_extension],
"editable": 1,
"type": "ListField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
title: "Download",
group_list: [[
"center",
[["my_format"]]
]]
}
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: "Download File",
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
});
})
.allowPublicAcquisition('jio_putAttachment', function () {
var gadget = this, format;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (content) {
format = content.format;
return RSVP.all([
gadget.jio_getAttachment(gadget.state.jio_key, 'data?' + format),
gadget.jio_get(gadget.state.jio_key)
]);
})
.push(function (result) {
var a = document.createElement('a'),
url = URL.createObjectURL(result[0]);
a.href = url;
a.download = result[1].filename.split(
gadget.state.file_extension
)[0] + format;
gadget.element.appendChild(a);
a.click();
gadget.element.removeChild(a);
URL.revokeObjectURL(url);
return gadget.notifySubmitted();
})
.push(function () {
return gadget.redirect({
command: "display",
options: {jio_key: gadget.state.jio_key}
});
});
});
}(window, rJS, RSVP, jIO, document, URL));
\ No newline at end of file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gadget OnlyOffice Upload</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_ojs_upload_convert.js"></script>
</head>
<body>
<form class="save_form ui-body-c" novalidate>
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_pt_form_dialog.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, jIO */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, jIO) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('jio_putAttachment', function () {
var gadget = this,
file_name,
jio_key,
data,
format;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return RSVP.all([
form_gadget.getContent(),
gadget.getSetting('portal_type'),
gadget.getSetting('content_type')
]);
})
.push(function (result) {
format = result[0].format;
file_name = result[0].file.file_name.split(format)[0];
data = jIO.util.dataURItoBlob(result[0].file.url);
return gadget.jio_post({
title: file_name,
portal_type: result[1],
content_type: result[2],
filename: file_name
});
})
.push(function (doc_id) {
jio_key = doc_id;
return gadget.jio_putAttachment(jio_key, "data?" + format, data);
})
.push(function () {
return gadget.redirect({command: 'display', options: {jio_key: jio_key}});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function () {
var gadget = this;
return gadget.getSetting('upload_extension')
.push(function (upload_extension) {
return gadget.changeState({
upload_extension: upload_extension
});
});
})
.onStateChange(function () {
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
erp5_document: {
"_embedded": {"_view": {
"_actions": {"put": {}},
"form_id": {},
"dialog_id": {},
"my_file": {
"description": "",
"title": "File",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "file",
"hidden": 0,
"type": "FileField"
},
"my_format": {
"title": "Format",
"default": gadget.state.upload_extension,
"key": "format",
"first_item": 0,
"items": [gadget.state.upload_extension],
"editable": 1,
"type": "ListField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
title: "Upload",
group_list: [[
"center",
[["my_file"], ["my_format"]]
]]
}
});
})
.push(function () {
return gadget.getUrlFor({command: 'display', options: {page: 'ojs_document_list'}});
})
.push(function (url) {
return gadget.updateHeader({
page_title: "Upload File",
selection_url: url
});
});
});
}(window, rJS, RSVP, jIO));
\ 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