Commit 133113b3 authored by Roque's avatar Roque

erp5_officejs: portal type actions are handle in handle action gadget instead of controller

parent c4c3a11f
......@@ -43,23 +43,6 @@
return result;
}
function getActionReference(view_url_parameters) {
//TODO: check how to properly add a parameter to gadget render option
// and not within the view url-parameter
var parser = document.createElement('a'), urlParams, action_reference;
if (view_url_parameters.indexOf("#!change?") !== -1) {
parser.href = window.location.origin + "/" + view_url_parameters.replace(/#!change?/g, 'change?');
urlParams = new URLSearchParams(parser.search);
action_reference = urlParams.get("n.action");
} else {
action_reference = view_url_parameters;
}
if (action_reference === undefined || action_reference === null || action_reference === "view") {
action_reference = default_view;
}
return action_reference;
}
rJS(window)
/////////////////////////////////////////////////////////////////
......@@ -82,36 +65,6 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("handleAction", function (key, document, view_parameters) {
var gadget = this, jio_key = key, jio_document = document,
action_reference = getActionReference(view_parameters);
// This is the custom code to handle this specific reply action
// it should be somewhere else to keep the controller generic
if (action_reference == "reply") {
var doc, title = document.title;
if (! title.startsWith("Re: ")) {
title = "Re: " + document.title;
}
doc = {
title: title,
//thread parent: same as base post
source_reference: document.source_reference,
portal_type: document.portal_type,
parent_relative_url: document.parent_relative_url
};
return gadget.jio_post(doc)
.push(function (id) {
jio_key = id;
return gadget.jio_get(jio_key);
})
.push(function (created_doc) {
jio_document = created_doc;
return [jio_key, jio_document, action_reference];
});
}
return [jio_key, jio_document, action_reference];
})
.declareMethod("getFormDefinition", function (portal_type, action_reference) {
var gadget = this,
parent = "portal_types/" + portal_type,
......@@ -209,24 +162,18 @@
if (document.portal_type === undefined) {
throw new Error('Can not display document: ' + options.jio_key);
}
return gadget.getUrlParameter("view");
})
.push(function (view_parameters) {
return gadget.handleAction(options.jio_key, document, view_parameters);
})
.push(function (result_list) {
return gadget.getFormDefinition(document.portal_type, result_list[2])
return gadget.getFormDefinition(document.portal_type, options.view)
.push(function (form_definition) {
return gadget.changeState({
jio_key: result_list[0],
doc: result_list[1],
jio_key: options.jio_key,
doc: document,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
editable: options.editable,
view: result_list[2],
view: options.view,
//HARDCODED: following fields should be indicated by the configuration
has_more_views: false,
has_more_actions: result_list[2] == default_view,
has_more_actions: options.view == "view",
is_form_list: false
});
});
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.53016.56105.24149</string> </value>
<value> <string>974.59024.11735.30037</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1554391859.64</float>
<float>1554751815.26</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -225,7 +225,15 @@ gadget_erp5_pt_form_view_editable.html\n
gadget_erp5_pt_form_view_editable.js\n
gadget_erp5_page_action_offline.html\n
gadget_erp5_page_action_offline.js\n
gadget_erp5_page_handle_action.html\n
gadget_erp5_page_handle_action.js\n
gadget_officejs_discussion_tool_router.html\n
gadget_erp5_page_ojs_controller.html\n
gadget_erp5_page_ojs_controller.js\n
gadget_erp5_page_ojs_post_list.html\n
gadget_erp5_page_ojs_post_list.js\n
gadget_erp5_page_ojs_add_post.html\n
gadget_erp5_page_ojs_add_post.js\n
\n
#needed for appcachestorage sync\n
/\n
......@@ -247,13 +255,6 @@ hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%2
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F2&view=view&appcache=1\n
hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_types%2FHTML%20Post%2F3&view=view&appcache=1\n
\n
gadget_erp5_page_ojs_controller.html\n
gadget_erp5_page_ojs_controller.js\n
gadget_erp5_page_ojs_post_list.html\n
gadget_erp5_page_ojs_post_list.js\n
gadget_erp5_page_ojs_add_post.html\n
gadget_erp5_page_ojs_add_post.js\n
\n
gadget_erp5_field_listbox.html\n
gadget_erp5_field_listbox.js\n
\n
......@@ -739,7 +740,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.51832.12674.16708</string> </value>
<value> <string>974.59021.18848.28108</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -757,7 +758,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1554402100.2</float>
<float>1554751524.94</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -153,7 +153,7 @@
header_dict.save_action = true;
}
}
if (true) { //TODO: configuration must indicate if there are more actions
if (false) { //TODO: configuration must indicate if there are more actions
header_dict.actions_url = url_list[1];
}
if (url_list[7]) {
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.49976.5658.27801</string> </value>
<value> <string>974.59028.6381.42171</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1554208935.58</float>
<float>1554752043.96</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -19,22 +19,6 @@
* @param {Array} command_list - array of links obtained from ERP5 HATEOAS
*/
function renderLinkList(gadget, title, icon, erp5_link_list) {
return gadget.getUrlParameter("extended_search")
.push(function (query) {
// obtain RJS links from ERP5 links
return RSVP.all(
erp5_link_list.map(function (erp5_link) {
return gadget.getUrlFor({
"command": 'change',
"options": {
"view": UriTemplate.parse(erp5_link.href).expand({query: query}),
"page": undefined
}
});
})
);
})
.push(function (url_list) {
// prepare links for template (replace @href for RJS link)
return gadget.translateHtml(
table_template({
......@@ -45,12 +29,11 @@
return {
"title": erp5_link.title,
"i18n": erp5_link.title,
"link": url_list[index]
"link": erp5_link_list[index].href
};
})
})
);
});
}
......@@ -92,10 +75,14 @@
})
.push(function (action_document_list) {
var url_for_parameter_list = [], i = 0,
action_key, action_doc;
page, action_key, action_doc;
for (action_key in action_document_list) {
page = "handle_action";
action_doc = action_document_list[action_key];
url_for_parameter_list.push({command: 'change', options: {page: "ojs_controller", action: action_doc.reference}});
if (action_doc.reference == "view" || action_doc.reference == "jio_view") {
page = "ojs_controller";
}
url_for_parameter_list.push({command: 'change', options: {page: page, action: action_doc.reference}});
action_info_list[i] = { reference: action_doc.reference, title: action_doc.title};
i += 1;
}
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.52897.57392.44646</string> </value>
<value> <string>974.58836.59077.24849</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1554384682.86</float>
<float>1554740463.74</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 Handle Action</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_erp5_page_handle_action.js"></script>
</head>
<body>
HANDLE ACTION
</body>
</html>
/*global window, rJS, RSVP */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Blob) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("handleAction", function (jio_key, portal_type) {
var gadget = this, jio_document, action_reference;
return gadget.getUrlParameter("action")
.push(function (action_parameter) {
action_reference = action_parameter;
return gadget.jio_get(jio_key);
})
.push(function (document) {
// This is the custom code to handle this specific reply action
if (action_reference == "reply") {
var doc, title = document.title;
if (! title.startsWith("Re: ")) {
title = "Re: " + document.title;
}
doc = {
title: title,
//thread parent: same as base post
source_reference: document.source_reference,
portal_type: document.portal_type,
parent_relative_url: document.parent_relative_url
};
return gadget.jio_post(doc)
.push(function (id) {
jio_key = id;
return gadget.jio_get(jio_key);
})
.push(function (created_doc) {
jio_document = created_doc;
return [jio_key, jio_document, action_reference];
});
}
return [jio_key, jio_document, action_reference];
});
})
.declareMethod("render", function (options) {
var gadget = this, doc_id;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('portal_type'),
gadget.getSetting('parent_relative_url')
]);
})
.push(function (result) {
return gadget.handleAction(options.jio_key, result[0]);
})
.push(function (action_result) {
return gadget.redirect({
command: 'change',
options: {
page: undefined,
jio_key: action_result[0],
view: action_result[2]
}
});
});
});
}(window, rJS, RSVP, Blob));
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