Commit 20f0dae9 authored by Roque's avatar Roque Committed by Roque

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

parent fd45d525
/*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 */
(function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray) {
(function (document, window, rJS, RSVP, Blob, URL, jIO, ensureArray, console) {
"use strict";
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 = {};
for (key in field_definition.values) {
if (field_definition.values.hasOwnProperty(key)) {
......@@ -45,11 +45,16 @@
}
if (result.renderjs_extra && blob_type) {
result["default"] = data;
result.editable = content_editable;
if (!content_editable) {
result.type = "EditorField";
}
}
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,
raw_properties = form_definition.fields_raw_properties,
form_json = {
......@@ -73,7 +78,8 @@
if (element_id && raw_properties.hasOwnProperty(my_element)) {
field_info = raw_properties[my_element];
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] =
rendered_field;
}
......@@ -86,7 +92,7 @@
}
function handleSubmit(gadget, child_gadget, content_dict) {
var data, name_list;
var data;
return gadget.notifySubmitting()
.push(function () {
if (gadget.state.blob_type) {
......@@ -95,7 +101,9 @@
delete content_dict.text_content;
}
return child_gadget.submitContent(
child_gadget.state.jio_key, undefined, content_dict
child_gadget.state.jio_key,
undefined,
content_dict
);
})
.push(function () {
......@@ -227,8 +235,15 @@
.onStateChange(function onStateChange() {
var fragment = document.createElement('div'),
gadget = this,
form_json = renderForm(gadget.state.form_definition, gadget.state.doc,
gadget.state.data, gadget.state.blob_type);
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,
gadget.state.data, gadget.state.blob_type,
content_editable);
while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild);
}
......@@ -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 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>978.46851.17123.15906</string> </value>
<value> <string>978.63202.6561.35293</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1569577593.67</float>
<float>1570539644.03</float>
<string>UTC</string>
</tuple>
</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