Commit 7de5f254 authored by Roque's avatar Roque

erp5_officejs: review

parent 2863a960
......@@ -10,16 +10,9 @@
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("isDesktopMedia", "isDesktopMedia")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod('getUrlParameter', 'getUrlParameter')
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
......
/*global document, window, rJS, RSVP, ensureArray */
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(function (document, window, rJS, RSVP, ensureArray) {
"use strict";
function renderField(field_id, field_definition, document) {
function renderField(field_id, field_definition, context_document) {
var key, raw_value, override, final_value, item_list, result = {};
for (key in field_definition.values) {
if (field_definition.values.hasOwnProperty(key)) {
......@@ -15,28 +15,31 @@
if (final_value === undefined) {
if (override !== undefined && override !== null && override !== '') {
final_value = override;
} else if (raw_value !== undefined && raw_value !== null && raw_value !== '') {
} else if (raw_value !== undefined && raw_value !== null &&
raw_value !== '') {
final_value = raw_value;
} else if (document && document.hasOwnProperty(key)) {
final_value = document[key];
} else if (context_document && context_document.hasOwnProperty(key)) {
final_value = context_document[key];
}
}
if (final_value !== undefined && final_value !== null && final_value !== '') {
if (final_value !== undefined && final_value !== null &&
final_value !== '') {
result[key] = final_value;
}
}
}
result.type = field_definition.type;
result.key = field_id;
if (document && document.hasOwnProperty(field_id)) {
if (context_document && context_document.hasOwnProperty(field_id)) {
if (field_definition.type === "ListField") {
item_list = ensureArray(document[field_id]).map(function (item) {
item_list = ensureArray(context_document[field_id])
.map(function (item) {
if (Array.isArray(item)) {return item; }
return [item, item];
});
result.items = item_list;
} else {
result["default"] = document[field_id];
result["default"] = context_document[field_id];
}
}
return result;
......@@ -50,14 +53,7 @@
.declareAcquiredMethod("isDesktopMedia", "isDesktopMedia")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
// XXX Hardcoded for modification_date rendering
.allowPublicAcquisition("jio_allDocs", function (param_list) {
......@@ -100,7 +96,7 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("renderForm", function (form_definition, document) {
.declareMethod("renderForm", function (form_definition, context_document) {
var i, j, fields, field_info, my_element, element_id, rendered_field,
raw_properties = form_definition.fields_raw_properties,
form_json = {
......@@ -123,12 +119,15 @@
}
if (element_id && raw_properties.hasOwnProperty(my_element)) {
field_info = raw_properties[my_element];
rendered_field = renderField(element_id, field_info, document);
form_json.erp5_document._embedded._view[my_element] = rendered_field;
rendered_field = renderField(element_id, field_info,
context_document);
form_json.erp5_document._embedded._view[my_element] =
rendered_field;
}
}
}
form_json.erp5_document._embedded._view._actions = form_definition._actions;
form_json.erp5_document._embedded._view._actions =
form_definition._actions;
form_json.erp5_document._links = form_definition._links;
return form_json;
})
......@@ -141,20 +140,32 @@
})
.declareMethod("render", function (options) {
var state_dict = {
doc: options.doc,
form_definition: options.form_definition,
child_gadget_url: options.child_gadget_url,
options: options
};
return this.changeState(state_dict);
})
.onStateChange(function onStateChange() {
var fragment = document.createElement('div'),
gadget = this,
form_json;
return gadget.renderForm(options.form_definition, options.doc)
return gadget.renderForm(gadget.state.form_definition, gadget.state.doc)
.push(function (json) {
form_json = json;
while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild);
}
gadget.element.appendChild(fragment);
return gadget.declareGadget(options.child_gadget_url, {element: fragment, scope: 'fg'});
return gadget.declareGadget(gadget.state.child_gadget_url,
{element: fragment, scope: 'fg'});
})
.push(function (form_gadget) {
return gadget.renderSubGadget(options, form_gadget, form_json);
return gadget.renderSubGadget(gadget.state.options, form_gadget,
form_json);
});
})
......@@ -175,7 +186,9 @@
.push(function () {
var url_for_parameter_list = [
{command: 'change', options: {page: "tab"}},
{command: 'change', options: {page: "action_officejs", jio_key: options.jio_key, portal_type: options.portal_type}},
{command: 'change', options: {page: "action_officejs",
jio_key: options.jio_key,
portal_type: options.portal_type}},
{command: 'history_previous'},
{command: 'selection_previous'},
{command: 'selection_next'},
......@@ -189,7 +202,15 @@
if (form_json.form_definition.allowed_sub_types_list &&
form_json.form_definition.allowed_sub_types_list.length > 0 &&
!form_json.form_definition.hide_add_button) {
url_for_parameter_list.push({command: 'change', options: {page: "create_document", jio_key: options.jio_key, portal_type: options.portal_type, allowed_sub_types_list: form_json.form_definition.allowed_sub_types_list}});
url_for_parameter_list.push({command: 'change',
options: {page: "create_document",
jio_key: options.jio_key,
portal_type:
options.portal_type,
allowed_sub_types_list:
form_json.form_definition
.allowed_sub_types_list
}});
add_url = true;
}
return RSVP.all([
......@@ -236,7 +257,8 @@
header_dict.save_action = true;
}
}
if (options.form_definition.has_more_actions || options.form_definition.has_more_views) {
if (options.form_definition.has_more_actions ||
options.form_definition.has_more_views) {
header_dict.actions_url = url_list[1];
}
if (add_url) {
......
......@@ -41,13 +41,10 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
/////////////////////////////////////////////////////////////////
// declared methods
......@@ -101,12 +98,12 @@
.push(function (gadget_utils) {
// TODO views are also listed here
// should views be handled in another gadget like "..tab_office.js" ?
return gadget_utils.getAllViewsAndActions(portal_type, options.jio_key);
return gadget_utils.getViewAndActionDict(portal_type, options.jio_key);
})
.push(function (action_info_dict) {
return RSVP.all([
gadget.getHTMLElementList(action_info_dict.views),
gadget.getHTMLElementList(action_info_dict.actions)
gadget.getHTMLElementList(action_info_dict.view_list),
gadget.getHTMLElementList(action_info_dict.action_list)
]);
})
// check other lists like clone or delete? NO. For now, they will be actions
......
......@@ -58,8 +58,13 @@
})
.push(function (portal_type_result) {
portal_type = portal_type_result;
// TODO: somehow (a generic action?) get the path string:${object_url}/Base_viewNewContentDialog
return gadget.jio_get("portal_skins/erp5_hal_json_style/Base_viewNewContentDialog");
return gadget.getSetting("new_content_action");
})
.push(function (new_content_action) {
if (!new_content_action) {
throw new Error("Missing site configuration 'new_content_action'");
}
return gadget.jio_get(new_content_action);
})
.push(function (form_result) {
form_definition = form_result.raw_dict._embedded._view._embedded.form_definition;
......
......@@ -8,7 +8,6 @@
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("notifySubmitted", 'notifySubmitted')
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
......
......@@ -21,6 +21,9 @@
<script data-renderjs-configuration="parent_relative_url" type="text/x-renderjs-configuration">web_page_module</script>
<script data-renderjs-configuration="hide_listbox_buttons" type="text/x-renderjs-configuration">1</script>
<script data-renderjs-configuration="documents_editable" type="text/x-renderjs-configuration">1</script>
<script data-renderjs-configuration="portal_skin_folder" type="text/x-renderjs-configuration">erp5_web_officejs_ui</script>
<!-- TODO: somehow (a generic action?) get the path string:${object_url}/Base_viewNewContentDialog. For now it's in new_content_action -->
<script data-renderjs-configuration="new_content_action" type="text/x-renderjs-configuration">portal_skins/erp5_hal_json_style/Base_viewNewContentDialog</script>
<script data-renderjs-configuration="erp5_attachment_synchro" type="text/x-renderjs-configuration"></script>
<script data-renderjs-configuration="dropbox_app_key" type="text/x-renderjs-configuration">n692ixxhyg9zhqs</script>
<div data-gadget-url="gadget_erp5_router.html" data-gadget-scope="erp5_router"></div>
......
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