Commit d4bccb9e authored by Roque's avatar Roque

erp5_officejs: enable readonly view for non-only-office documents

parent d9220ced
/*global document, window, rJS, RSVP, Blob, URL, jIO, ensureArray */ /*global document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray) { (function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console) {
"use strict"; "use strict";
function renderField(field_id, field_definition, function renderField(field_id, field_definition,
context_document, data, blob_type) { context_document, data, blob_type, content_editable) {
var key, raw_value, override, final_value, item_list, result = {}; var key, raw_value, override, final_value, item_list, result = {};
for (key in field_definition.values) { for (key in field_definition.values) {
if (field_definition.values.hasOwnProperty(key)) { if (field_definition.values.hasOwnProperty(key)) {
...@@ -45,11 +45,16 @@ ...@@ -45,11 +45,16 @@
} }
if (result.renderjs_extra && blob_type) { if (result.renderjs_extra && blob_type) {
result["default"] = data; result["default"] = data;
result.editable = content_editable;
if (!content_editable) {
result.type = "EditorField";
}
} }
return result; return result;
} }
function renderForm(form_definition, context_document, data, blob_type) { function renderForm(form_definition, context_document, data, blob_type,
content_editable) {
var i, j, field_list, field_info, my_element, element_id, rendered_field, var i, j, field_list, field_info, my_element, element_id, rendered_field,
raw_properties = form_definition.fields_raw_properties, raw_properties = form_definition.fields_raw_properties,
form_json = { form_json = {
...@@ -73,7 +78,8 @@ ...@@ -73,7 +78,8 @@
if (element_id && raw_properties.hasOwnProperty(my_element)) { if (element_id && raw_properties.hasOwnProperty(my_element)) {
field_info = raw_properties[my_element]; field_info = raw_properties[my_element];
rendered_field = renderField(element_id, field_info, rendered_field = renderField(element_id, field_info,
context_document, data, blob_type); context_document, data, blob_type,
content_editable);
form_json.erp5_document._embedded._view[my_element] = form_json.erp5_document._embedded._view[my_element] =
rendered_field; rendered_field;
} }
...@@ -86,7 +92,7 @@ ...@@ -86,7 +92,7 @@
} }
function handleSubmit(gadget, child_gadget, content_dict) { function handleSubmit(gadget, child_gadget, content_dict) {
var data, name_list; var data;
return gadget.notifySubmitting() return gadget.notifySubmitting()
.push(function () { .push(function () {
if (gadget.state.blob_type) { if (gadget.state.blob_type) {
...@@ -95,7 +101,9 @@ ...@@ -95,7 +101,9 @@
delete content_dict.text_content; delete content_dict.text_content;
} }
return child_gadget.submitContent( return child_gadget.submitContent(
child_gadget.state.jio_key, undefined, content_dict child_gadget.state.jio_key,
undefined,
content_dict
); );
}) })
.push(function () { .push(function () {
...@@ -227,8 +235,15 @@ ...@@ -227,8 +235,15 @@
.onStateChange(function onStateChange() { .onStateChange(function onStateChange() {
var fragment = document.createElement('div'), var fragment = document.createElement('div'),
gadget = this, gadget = this,
content_editable = gadget.state.content_editable,
form_json;
if (content_editable === undefined) {
content_editable = gadget.state.form_definition
.portal_type_dict.editable;
}
form_json = renderForm(gadget.state.form_definition, gadget.state.doc, form_json = renderForm(gadget.state.form_definition, gadget.state.doc,
gadget.state.data, gadget.state.blob_type); gadget.state.data, gadget.state.blob_type,
content_editable);
while (gadget.element.firstChild) { while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild); gadget.element.removeChild(gadget.element.firstChild);
} }
...@@ -338,4 +353,4 @@ ...@@ -338,4 +353,4 @@
}); });
}); });
}(document, window, rJS, RSVP, Blob, URL, jIO, ensureArray)); }(document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console));
...@@ -269,7 +269,7 @@ ...@@ -269,7 +269,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.46851.17123.15906</string> </value> <value> <string>978.63202.6561.35293</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1569577593.67</float> <float>1570539644.03</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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