Commit c5d06b50 authored by Vincent Bechu's avatar Vincent Bechu

[erp5_officejs] Add conversion feature in officejs layout

parent a2568823
......@@ -63,9 +63,7 @@
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -260,7 +258,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>P0</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -274,7 +272,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>961.341.55275.50397</string> </value>
<value> <string>969.7413.51643.45056</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -292,7 +290,7 @@
</tuple>
<state>
<tuple>
<float>1501149490.23</float>
<float>1533639716.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -124,15 +124,21 @@
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: "change", options: {"page": "ojs_add_document"}}),
gadget.getSetting('document_title_plural')
gadget.getSetting('document_title_plural'),
gadget.getUrlFor({command: "change", options: {"page": "ojs_upload_convert"}}),
gadget.getSetting('conversion_dict', false)
]);
})
.push(function (result) {
return gadget.updateHeader({
var header = {
page_title: result[1],
filter_action: true,
add_url: result[0]
});
};
if (result[3]) {
header.upload_url = result[2];
}
return gadget.updateHeader(header);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -16,7 +16,6 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
......@@ -24,6 +23,7 @@
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
......@@ -42,6 +42,8 @@
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
......@@ -56,16 +58,13 @@
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -199,11 +198,11 @@
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish</string> </value>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>P1</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -225,7 +224,7 @@
</tuple>
<state>
<tuple>
<float>1495446491.04</float>
<float>1528899467.3</float>
<string>UTC</string>
</tuple>
</state>
......@@ -234,7 +233,7 @@
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published</string> </value>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
......@@ -256,7 +255,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>P0</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -270,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.41210.1237.18158</string> </value>
<value> <string>969.27633.19787.19507</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -288,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1523022228.16</float>
<float>1533639709.89</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -63,9 +63,7 @@
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -260,7 +258,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>vincent</string> </value>
<value> <string>P0</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -274,7 +272,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.7730.44194.2696</string> </value>
<value> <string>969.7413.51643.45056</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -292,7 +290,7 @@
</tuple>
<state>
<tuple>
<float>1509969877.35</float>
<float>1533639737.77</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -63,9 +63,7 @@
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>contributor/person_module/1</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......@@ -256,7 +254,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>P0</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -270,7 +268,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.50085.12569.53742</string> </value>
<value> <string>969.27633.19787.19507</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -288,7 +286,7 @@
</tuple>
<state>
<tuple>
<float>1523363107.89</float>
<float>1533639731.09</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -8,27 +8,23 @@
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script src="gadget_global.js" ></script>
<script id="page-template" type="text/x-handlebars-template">
<center class="ui-content ui-body-c">
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-refresh">&nbsp;</span>
Synchronize your data
</h3>
</section>
<section class="ui-body-c ui-content-section">
<div class="ui-icon-spinner ui-btn-icon-notext first-loader"></div>
</section>
</center>
</script>
<script src="gadget_erp5_page_ojs_sync.js"></script>
</head>
<body>
<center class="ui-content ui-body-c">
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-refresh">&nbsp;</span>
Synchronize your data
</h3>
</section>
<section class="ui-body-c ui-content-section">
<div class="ui-icon-spinner ui-btn-icon-notext first-loader"></div>
</section>
</center>
<div class="cloudooo"></div>
</body>
</html>
\ No newline at end of file
......@@ -63,6 +63,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
......@@ -228,7 +234,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>P0</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -242,7 +248,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.57151.51816.16622</string> </value>
<value> <string>969.27633.19787.19507</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1501081969.62</float>
<float>1533639762.74</float>
<string>UTC</string>
</tuple>
</state>
......
/*globals window, RSVP, rJS, promiseEventListener, Handlebars*/
/*globals window, RSVP, rJS*/
/*jslint indent: 2, maxlen: 80, nomen: true*/
(function (window, RSVP, rJS, promiseEventListener, Handlebars) {
(function (window, RSVP, rJS) {
"use strict";
var gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
template = Handlebars.compile(
templater.getElementById("page-template").innerHTML
);
var gadget_klass = rJS(window);
function repair_and_redirect(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.getSetting('sync_reload', false);
})
.push(function (sync_reload) {
.push(function (sync_reload) {
if (sync_reload) {
return gadget.setSetting('sync_reload', false)
.push(function () {
......@@ -22,12 +17,17 @@
});
}
return gadget.repair()
.push(function (result) {
if (result !== undefined && result.hasOwnProperty('redirect')) {
return gadget.redirect({
command: "display",
options: result.redirect
});
.push(function () {
if (gadget.state.cloudooo) {
return gadget.getDeclaredGadget('cloudooo')
.push(function (cloudooo) {
return cloudooo.repair();
});
}
})
.push(function () {
if (gadget.state.redirect) {
return gadget.redirect(window.JSON.parse(gadget.state.redirect));
}
return gadget.redirect({command: "display"});
});
......@@ -35,32 +35,32 @@
}
gadget_klass
.ready(function (g) {
g.props = {};
g.props.auto_repair = false;
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareMethod("render", function () {
.declareMethod("render", function (options) {
var gadget = this;
return gadget.getSetting('conversion_dict', false)
.push(function (result) {
return gadget.changeState({
auto_repair: options.auto_repair,
redirect: options.redirect,
cloudooo: result && true
});
});
})
.onStateChange(function (modification_dict) {
var gadget = this;
if (arguments[0].auto_repair === "true") {
gadget.props.auto_repair = true;
}
return gadget.updateHeader({
title: "Synchronize"
})
.push(function () {
return gadget.translateHtml(template());
})
.push(function (html) {
gadget.props.element.innerHTML = html;
if (modification_dict.cloudooo) {
return gadget.declareGadget('gadget_cloudooo.html', {
element: gadget.element.querySelector('.cloudooo'),
scope: "cloudooo"
});
}
});
})
......@@ -73,21 +73,9 @@
.declareService(function () {
var gadget = this;
if (gadget.props.auto_repair === true) {
if (gadget.state.auto_repair) {
return repair_and_redirect(gadget);
}
return new RSVP.Queue()
.push(function () {
return promiseEventListener(
gadget.props.element.querySelector('form.synchro-form'),
'submit',
false
);
})
.push(function () {
return repair_and_redirect(gadget);
});
});
}(window, RSVP, rJS, promiseEventListener, Handlebars));
\ No newline at end of file
}(window, RSVP, rJS));
\ No newline at end of file
......@@ -63,6 +63,12 @@
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
......@@ -224,7 +230,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>P0</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -238,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>960.3847.13096.46165</string> </value>
<value> <string>969.27633.19787.19507</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1500474952.22</float>
<float>1533639756.16</float>
<string>UTC</string>
</tuple>
</state>
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Text Editor List</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_cloudooo.js"></script>
</head>
<body>
<div data-gadget-scope="jio" data-gadget-url="gadget_jio.html"></div>
</body>
</html>
/*global window, rJS, jIO, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, jIO, RSVP) {
"use strict";
rJS(window)
.ready(function (g) {
g.getDeclaredGadget("jio")
.push(function (jio_gadget) {
return jio_gadget.createJio({
type: "cloudooo",
url: "https://cloudooo.erp5.net/",
sub_storage: {
type: "memory"
}
});
});
})
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_get", "jio_get")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("convertFromOperation", function (id) {
var gadget = this;
return gadget.jio_get(id)
.push(function (doc) {
return gadget.convert(doc.id, doc.name, doc.from, doc.to)
.push(function () {
doc.status = "converted";
return gadget.jio_put(id, doc);
}, function (error) {
if (error instanceof jIO.util.jIOError) {
doc.status = "error";
doc.error = jIO.util.stringify(error);
return gadget.jio_put(id, doc);
}
throw error;
});
});
})
.declareMethod("convert", function (id, name, from, to) {
var gadget = this, jio_gadget;
return gadget.getDeclaredGadget("jio")
.push(function (sub_gadget) {
jio_gadget = sub_gadget;
return RSVP.all([
gadget.jio_getAttachment(id, name),
jio_gadget.put(id, {from: from, to: to})
]);
})
.push(function (result) {
return jio_gadget.putAttachment(id, name, result[0]);
})
.push(function () {
return jio_gadget.getAttachment(id, name);
})
.push(function (converted_blob) {
return gadget.jio_putAttachment(id, to, converted_blob);
});
})
.declareMethod('repair', function () {
var gadget = this;
function convertAndPush(rows, i) {
if (i === -1) {
return new RSVP.Queue();
}
return convertAndPush(rows, i - 1)
.push(function () {
return gadget.convertFromOperation(rows[i].id);
});
}
return gadget.jio_allDocs({
'query': 'status: "convert"'
})
.push(function (result) {
var i = result.data.total_rows - 1;
return convertAndPush(result.data.rows, i);
});
});
}(window, rJS, jIO, RSVP));
\ 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_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>
<div data-gadget-url="gadget_ojs_cloudooo.html"
data-gadget-scope="ojs_cloudooo"
data-gadget-sandbox="public">
</div>
</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";
var ATT_NAME = "data";
function downloadFromBlob(gadget, blob, format) {
var element = gadget.element,
a = window.document.createElement("a"),
url = window.URL.createObjectURL(blob),
name_list = gadget.state.doc.filename.split('.');
name_list[name_list.length - 1] = format;
element.appendChild(a);
a.style = "display: none";
a.href = url;
a.download = name_list.join('.');
a.click();
element.removeChild(a);
window.URL.revokeObjectURL(url);
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('submitContent', 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 (result) {
format = result.format;
if (format === gadget.state.format) {
return gadget.jio_getAttachment(gadget.state.jio_key, ATT_NAME);
}
return gadget.getDeclaredGadget('ojs_cloudooo')
.push(function (ojs_cloudooo) {
return ojs_cloudooo.getConvertedBlob({
jio_key: gadget.state.jio_key,
format: format,
mime_type: gadget.state.format
});
});
})
.push(function (result) {
return downloadFromBlob(gadget, result, format);
}, function (error) {
if (error instanceof jIO.util.jIOError &&
error.status_code === 500 &&
error.message === "Not converted") {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true,
'redirect': jIO.util.stringify({
'command': 'display',
'options': {
'page': 'ojs_download_convert',
'jio_key': gadget.state.jio_key
}
})
}
});
}
throw error;
})
.push(function () {
return gadget.notifySubmitted();
}, function (error) {
if (error instanceof jIO.util.jIOError) {
return gadget.notifySubmitted({
message: "Conversion Failed",
status: "error"
});
}
throw error;
})
.push(function () {
return;
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function (options) {
var gadget = this;
return gadget.jio_get(options.jio_key)
.push(function (doc) {
return gadget.changeState({
jio_key: options.jio_key,
doc: doc,
format: doc.filename.split('.').pop()
});
});
})
.onStateChange(function () {
var gadget = this, format_list;
return gadget.getSetting('conversion_dict', {})
.push(function (conversion_dict) {
format_list = window.JSON.parse(conversion_dict)[gadget.state.format];
format_list.push(gadget.state.format);
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 Avaible",
"required": 1,
"editable": 1,
"key": "format",
"value": gadget.state.format,
"items": format_list,
"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: 'display',
options: {'jio_key': gadget.state.jio_key}
}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: "Download",
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
});
});
}(window, rJS, RSVP, jIO));
\ 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>
<div data-gadget-url="gadget_ojs_cloudooo.html"
data-gadget-scope="ojs_cloudooo"></div>
</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";
var ATT_NAME = "data";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition('submitContent', function () {
var gadget = this;
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'),
gadget.getSetting('file_extension')
]);
})
.push(function (result) {
var file_name, from, jio_key, data, to;
if (result[0].file !== undefined) {
file_name = result[0].file.file_name;
from = file_name.split('.').pop();
data = jIO.util.dataURItoBlob(result[0].file.url);
if (gadget.state.upload.hasOwnProperty(from)) {
to = gadget.state.upload[from];
return gadget.jio_post({
title: file_name,
portal_type: result[1],
content_type: result[2],
filename: file_name,
mime_type: from
})
.push(function (doc_id) {
jio_key = doc_id;
return gadget.jio_putAttachment(jio_key, ATT_NAME, data);
})
.push(function () {
if (result[3] === from) {
return;
}
return gadget.getDeclaredGadget('ojs_cloudooo')
.push(function (ojs_cloudooo) {
return ojs_cloudooo.putCloudoooConvertOperation({
status: "convert",
from: from,
to: to,
id: jio_key,
name: ATT_NAME
});
});
})
.push(function () {
return gadget.redirect({
'command': 'display',
'options': {
'page': 'ojs_sync',
'auto_repair': true,
'redirect': jIO.util.stringify({
'command': 'display',
'options': {'jio_key': jio_key}
})
}
});
});
}
return gadget.notifySubmitted({
message: "Can not convert, use format : " +
window.Object.keys(gadget.state.upload).join(', '),
status: "error"
})
.push(function () {
return;
});
}
return gadget.notifySubmitted({
message: "File is required",
status: "error"
})
.push(function () {
return;
});
});
})
.declareMethod("triggerSubmit", function () {
return this.element.querySelector('button[type="submit"]').click();
})
.declareMethod("render", function () {
var gadget = this;
return gadget.getSetting('upload_dict')
.push(function (upload_dict) {
return gadget.changeState({
upload: window.JSON.parse(upload_dict)
});
});
})
.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"
},
"your_format": {
"title": "Format Avaible",
"required": 0,
"editable": 0,
"default": window.Object.keys(gadget.state.upload).join(', '),
"type": "StringField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
title: "Upload",
group_list: [[
"center",
[["my_file"], ["your_format"]]
]]
}
});
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'display'})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: "Upload File",
selection_url: url_list[0]
});
});
});
}(window, rJS, RSVP, jIO));
\ 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>OfficeJS Text Editor List</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_ojs_cloudooo.js"></script>
</head>
<body>
</body>
</html>
/*global window, rJS, jIO, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, jIO, RSVP) {
"use strict";
var ATT_NAME = "data";
function getCloudoooId(key, format) {
return 'CloudoooConversion/' + key + '/' + format;
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("getSetting", "getSetting")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getConvertedBlob", function (options) {
var gadget = this,
mime_type = options.filename.split('.').pop();
if (mime_type === options.format) {
return gadget.jio_getAttachment(options.jio_key, ATT_NAME);
}
return gadget.jio_get(
getCloudoooId(options.jio_key, options.format)
)
.push(function (doc) {
var err, obj;
if (doc.status === "converted") {
return gadget.jio_getAttachment(options.jio_key, options.format);
}
if (doc.status === "error") {
obj = window.JSON.parse(doc.error);
err = new jIO.util.jIOError(obj.message, obj.status_code);
err.detail = obj.detail;
} else {
err = new jIO.util.jIOError("Not converted", 500);
}
throw err;
}, function (error) {
if (error instanceof jIO.util.jIOError && error.status_code === 404) {
return gadget.putAllCloudoooConvertionOperation({
format: options.mime_type,
jio_key: options.jio_key
});
}
throw error;
});
})
.declareMethod("putCloudoooConvertOperation", function (options) {
return this.jio_put(getCloudoooId(options.id, options.to), options);
})
.declareMethod("putAllCloudoooConvertionOperation", function (options) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting("conversion_dict"),
gadget.getSetting("file_extension")
]);
})
.push(function (result) {
var promise_list = [],
format_list = window.JSON.parse(result[0])[options.format],
len = format_list.length,
i;
for (i = 0; i < len; i += 1) {
promise_list.push(gadget.putCloudoooConvertOperation({
status: "convert",
from: options.format,
to: format_list[i],
id: options.jio_key,
name: ATT_NAME
}));
}
return RSVP.all(promise_list);
});
});
}(window, rJS, jIO, RSVP));
\ 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