Commit 84cb9ebf authored by Roque's avatar Roque

WIP - erp5_officejs: new action page for offline app

parent 5ee2f559
/*global document, window, rJS, RSVP */ /*global document, window, rJS, RSVP, URLSearchParams */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (document, window, rJS, RSVP) { (function (document, window, rJS, RSVP, URLSearchParams) {
"use strict"; "use strict";
function renderField(field_id, field_definition, document) { function renderField(field_id, field_definition, document) {
...@@ -41,6 +41,21 @@ ...@@ -41,6 +41,21 @@
return result; return result;
} }
function getActionReference(view_url_parameters) {
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 = "jio_view";
}
return action_reference;
}
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -63,12 +78,16 @@ ...@@ -63,12 +78,16 @@
.declareMethod("getFormDefinition", function (portal_type) { .declareMethod("getFormDefinition", function (portal_type) {
var gadget = this, var gadget = this,
parent = "portal_types/" + portal_type, parent = "portal_types/" + portal_type;
query = 'portal_type: "Action Information" AND reference: "jio_view" AND parent_relative_url: "' + parent + '"'; return gadget.getUrlParameter("view")
return gadget.jio_allDocs({query: query}) .push(function (view_parameters) {
var action_reference = getActionReference(view_parameters),
query = 'portal_type: "Action Information" AND reference: "' + action_reference + '" AND parent_relative_url: "' + parent + '"';
return gadget.jio_allDocs({query: query});
})
.push(function (data) { .push(function (data) {
if (data.data.rows.length === 0) { if (data.data.rows.length === 0) {
throw "Can not find jio_view action for portal type " + portal_type; throw "Can not find action for portal type " + portal_type;
} }
return gadget.jio_get(data.data.rows[0].id); return gadget.jio_get(data.data.rows[0].id);
}) })
...@@ -183,7 +202,7 @@ ...@@ -183,7 +202,7 @@
.push(function () { .push(function () {
var url_for_parameter_list = [ var url_for_parameter_list = [
{command: 'change', options: {page: "tab"}}, {command: 'change', options: {page: "tab"}},
{command: 'change', options: {page: "action"}}, {command: 'change', options: {page: "action_offline"}},
{command: 'history_previous'}, {command: 'history_previous'},
{command: 'selection_previous'}, {command: 'selection_previous'},
{command: 'selection_next'}, {command: 'selection_next'},
...@@ -261,4 +280,4 @@ ...@@ -261,4 +280,4 @@
}); });
}); });
}(document, window, rJS, RSVP)); }(document, window, rJS, RSVP, URLSearchParams));
\ No newline at end of file \ No newline at end of file
...@@ -225,7 +225,7 @@ ...@@ -225,7 +225,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>974.48727.12042.43076</string> </value> <value> <string>974.50403.2705.59170</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -243,7 +243,7 @@ ...@@ -243,7 +243,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1554135448.09</float> <float>1554234823.55</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=Workflows
data-i18n=Actions
data-i18n=Clone
data-i18n=Delete
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Page Action</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_page.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_global.js" type="text/javascript"></script>
<script src="gadget_erp5_page_action_offline.js" type="text/javascript"></script>
<script id="table-template" type="text/x-handlebars-template">
<section class="ui-content-header-plain">
<h3 data-i18n="[last]{{definition_i18n}}">
<span class="ui-icon ui-icon-{{definition_icon}}">&nbsp;</span>
{{definition_title}}
</h3>
</section>
<ul class="document-listview">
{{#each document_list}}
<li><a data-i18n="{{title}}" href="{{link}}">{{title}}</a></li>
{{/each}}
</ul>
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, Handlebars, UriTemplate, calculatePageTitle, ensureArray */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, UriTemplate, calculatePageTitle, ensureArray) {
"use strict";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
table_template = Handlebars.compile(gadget_klass.__template_element
.getElementById("table-template")
.innerHTML);
/** Render translated HTML of title + links
*
* @param {string} title - H3 title of the section with the links
* @param {string} icon - alias used in font-awesome iconset
* @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({
"definition_i18n": title,
"definition_title": title,
"definition_icon": icon,
"document_list": erp5_link_list.map(function (erp5_link, index) {
return {
"title": erp5_link.title,
"i18n": erp5_link.title,
"link": url_list[index]
};
})
})
);
});
}
gadget_klass
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this,
erp5_document,
document_title;
return gadget.jio_get(options.jio_key)
.push(function (document) {
var parent = "portal_types/" + document.portal_type,
query = 'portal_type: "Action Information" AND parent_relative_url: "' + parent + '"';
document_title = document.title;
return gadget.jio_allDocs({query: query});
})
//TODO: build all action urls with corresponding action reference (ignore view, jio_view, etc)
.push(function (action_list) {
return gadget.getUrlFor({command: 'change', options: {page: "ojs_controller", action: "reply"}});
})
.push(function (url) {
//TODO temporarily hardcoded
var action_list = [{ href: url,
icon: null,
name: "reply",
title: "Reply" }];
return RSVP.all([
renderLinkList(gadget, "Actions", "gear", action_list)
]);
})
.push(function (translated_html_link_list) {
gadget.element.innerHTML = translated_html_link_list.join("\n");
return gadget.getUrlFor({command: 'change', options: {page: undefined}});
})
.push(function (back_url) {
return gadget.updateHeader({
page_title: document_title,
back_url: back_url
});
});
})
.declareMethod("triggerSubmit", function () {
return;
});
}(window, rJS, RSVP, Handlebars, UriTemplate, calculatePageTitle, ensureArray));
\ No newline at end of file
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