Commit 7de5f254 authored by Roque's avatar Roque

erp5_officejs: review

parent 2863a960
......@@ -4,9 +4,9 @@
"use strict";
// TODO: check if there are other categories that are 'views' and find a less hardcoded way to get this
var view_categories = ["object_view", "object_jio_view", "object_web_view", "object_list"];
var view_categorie_list = ["object_view", "object_jio_view", "object_web_view", "object_list"];
function filterViews(views_dict, app_view, default_view) {
function filterViewList(views_dict, app_view, default_view) {
// there must be only one "View" action (title = "View")
// this is for scenarios were the portal type has several "View" (like view, jio_view, custom_view)
// priority: app_view ; default_view ; other
......@@ -29,76 +29,81 @@
return views_dict;
}
function formatSettingList(configuration_list_string, portal_type) {
var i = 0, formatted_list = [], configuration_list, pair;
try {
configuration_list_string = configuration_list_string.replace(/\(/g, '[')
.replace(/\)/g, ']')
.replace(/,\]/g, ']')
.replace(/\'/g, '"');
configuration_list = JSON.parse(configuration_list_string);
for (i = 0; i < configuration_list.length; i += 1) {
pair = configuration_list[i].split(" | ");
if (pair.length !== 2) {
throw new SyntaxError();
}
if (!portal_type || pair[0] === portal_type) {
formatted_list.push(pair);
}
}
} catch (e) {
if (e instanceof SyntaxError) {
console.log("Error while parsing configuration settings. Format error maybe?");
console.log("Please check site configuration 'app_allowed_sub_types'");
console.log(e);
formatted_list = [];
} else {
throw e;
}
}
return formatted_list;
}
function buildSearchQuery(portal_type, action_reference) {
var query_list = [];
query_list.push(new SimpleQuery({
key: "portal_type",
operator: "",
type: "simple",
value: "Action Information"
}));
query_list.push(new SimpleQuery({
key: "parent_relative_url",
operator: "",
type: "simple",
value: "portal_types/" + portal_type
}));
if (action_reference) {
query_list.push(new SimpleQuery({
key: "reference",
operator: "",
type: "simple",
value: action_reference
}));
}
return Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: query_list,
type: "complex"
}));
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.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")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("formatSettingList", function (configuration_list_string, portal_type) {
var i = 0, formatted_list = [], configuration_list, pair;
try {
configuration_list_string = configuration_list_string.replace(/\(/g, '[')
.replace(/\)/g, ']')
.replace(/,\]/g, ']')
.replace(/\'/g, '"');
configuration_list = JSON.parse(configuration_list_string);
for (i = 0; i < configuration_list.length; i += 1) {
pair = configuration_list[i].split(" | ");
if (!portal_type || pair[0] === portal_type) {
formatted_list.push(pair);
}
}
} catch (e) {
console.log("Error while parsing configuration settings. Format error maybe?");
console.log(e);
}
return formatted_list;
})
.declareMethod("getAppActions", function (portal_type) {
var gadget = this;
return gadget.getSetting('app_actions')
.push(function (app_actions_setting) {
return gadget.formatSettingList(app_actions_setting, portal_type);
});
})
.declareMethod("getAllViewsAndActions", function (portal_type, jio_key) {
.declareMethod("getViewAndActionDict", function (portal_type, jio_key) {
var gadget = this,
action_info_dict = {views: {}, actions: {}},
query_type = new SimpleQuery({
key: "portal_type",
operator: "",
type: "simple",
value: "Action Information"
}),
query_parent = new SimpleQuery({
key: "parent_relative_url",
operator: "",
type: "simple",
value: "portal_types/" + portal_type
}),
query = Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: [query_type, query_parent],
type: "complex"
})),
action_info_dict = {view_list: {}, action_list: {}},
query = buildSearchQuery(portal_type),
app_actions,
app_view,
default_view;
......@@ -106,13 +111,14 @@
.push(function () {
return RSVP.all([
gadget.getSetting('app_view_reference'),
gadget.getSetting('default_view_reference')
gadget.getSetting('default_view_reference'),
gadget.getSetting('app_actions')
]);
})
.push(function (result_list) {
app_view = result_list[0];
default_view = result_list[1];
return gadget.getAppActions(portal_type);
return formatSettingList(result_list[2], portal_type);
})
.push(function (app_actions_result) {
app_actions = app_actions_result.map(function (pair) {
......@@ -143,17 +149,17 @@
action_type: action_doc.action_type,
parent_portal_type: portal_type
};
if (view_categories.includes(action_settings.action_type)) {
if (view_categorie_list.includes(action_settings.action_type)) {
action_settings.page = "ojs_local_controller";
action_info_dict.views[action_settings.action] = action_settings;
action_info_dict.view_list[action_settings.action] = action_settings;
} else {
action_settings.page = "handle_action";
action_info_dict.actions[action_settings.action] = action_settings;
action_info_dict.action_list[action_settings.action] = action_settings;
}
}
}
}
action_info_dict.views = filterViews(action_info_dict.views, app_view, default_view);
action_info_dict.view_list = filterViewList(action_info_dict.view_list, app_view, default_view);
return action_info_dict;
});
});
......@@ -185,38 +191,21 @@
.declareMethod("getFormDefinition", function (portal_type, action_reference) {
var gadget = this,
query,
query = buildSearchQuery(portal_type, action_reference),
action_type,
action_title,
form_definition,
query_type,
query_parent,
query_reference,
portal_skin_folder,
error;
query_reference = new SimpleQuery({
key: "reference",
operator: "",
type: "simple",
value: action_reference
});
query_type = new SimpleQuery({
key: "portal_type",
operator: "",
type: "simple",
value: "Action Information"
});
query_parent = new SimpleQuery({
key: "parent_relative_url",
operator: "",
type: "simple",
value: "portal_types/" + portal_type
});
query = Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: [query_type, query_parent, query_reference],
type: "complex"
}));
return gadget.jio_allDocs({query: query})
return gadget.getSetting("portal_skin_folder")
.push(function (result) {
if (!result) {
throw new Error("Missing site configuration 'portal_skin_folder'");
}
result = "portal_skins/" + result;
portal_skin_folder = result;
return gadget.jio_allDocs({query: query});
})
.push(function (data) {
if (data.data.rows.length === 0) {
error = new Error("Can not find action '" + action_reference + "' for portal type '" + portal_type + "'");
......@@ -229,7 +218,7 @@
action_title = action_result.title;
action_type = action_result.action_type;
if (action_result.action.includes("string:${object_url}")) {
action_result.action = action_result.action.replace("string:${object_url}", "portal_skins/erp5_web_officejs_ui");
action_result.action = action_result.action.replace("string:${object_url}", portal_skin_folder);
}
return gadget.jio_get(action_result.action);
})
......@@ -250,18 +239,18 @@
return gadget.getSetting("app_allowed_sub_types");
})
.push(function (allowed_sub_types_setting) {
return gadget.formatSettingList(allowed_sub_types_setting, portal_type);
return formatSettingList(allowed_sub_types_setting, portal_type);
})
.push(function (allowed_sub_types_pairs) {
var allowed_sub_types = allowed_sub_types_pairs.map(function (pair) {
return pair[1];
});
form_definition.allowed_sub_types_list = allowed_sub_types;
return gadget.getAllViewsAndActions(portal_type);
return gadget.getViewAndActionDict(portal_type);
})
.push(function (actions_views_dict) {
form_definition.has_more_views = Object.keys(actions_views_dict.views).length > 1;
form_definition.has_more_actions = Object.keys(actions_views_dict.actions).length > 0;
.push(function (action_view_dict) {
form_definition.has_more_views = Object.keys(action_view_dict.view_list).length > 1;
form_definition.has_more_actions = Object.keys(action_view_dict.action_list).length > 0;
return gadget.getSetting('hide_header_add_button');
})
.push(function (hide_add_button_setting) {
......
......@@ -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) {
if (Array.isArray(item)) {return item; }
return [item, 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