Commit fb85639e authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] Refactor of action and export page

parent 1728550c
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
<script src="gadget_erp5_page_action.js" type="text/javascript"></script> <script src="gadget_erp5_page_action.js" type="text/javascript"></script>
<script id="table-template" type="text/x-handlebars-template"> <script id="table-template" type="text/x-handlebars-template">
{{#if document_list}}
<section class="ui-content-header-plain"> <section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c" data-i18n="[last]{{definition_i18n}}"> <h3 class="ui-content-title ui-body-c" data-i18n="[last]{{definition_i18n}}">
<span class="ui-icon ui-icon-custom ui-icon-{{definition_icon}}">&nbsp;</span> <span class="ui-icon ui-icon-custom ui-icon-{{definition_icon}}">&nbsp;</span>
...@@ -28,10 +29,11 @@ ...@@ -28,10 +29,11 @@
</h3> </h3>
</section> </section>
<ul data-role="listview" data-theme="c" data-inset="true" class="document-listview"> <ul data-role="listview" data-theme="c" data-inset="true" class="document-listview">
{{#each documentlist}} {{#each document_list}}
<li><a data-i18n="{{title}}" class="ui-body-inherit" href="{{link}}">{{title}}</a></li> <li><a data-i18n="{{title}}" class="ui-body-inherit" href="{{link}}">{{title}}</a></li>
{{/each}} {{/each}}
</ul> </ul>
{{/if}}
</script> </script>
</head> </head>
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>953.48219.30595.27340</string> </value> <value> <string>962.2453.12386.29235</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1474556323.96</float> <float>1505211775.45</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -12,6 +12,54 @@ ...@@ -12,6 +12,54 @@
.getElementById("table-template") .getElementById("table-template")
.innerHTML); .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, editable) {
return new RSVP.Queue()
.push(function () {
// obtain RJS links from ERP5 links
return RSVP.all(
erp5_link_list.map(function (erp5_link) {
return gadget.getUrlFor({
"command": 'change',
"options": {
"view": erp5_link.href,
"page": undefined,
"editable": editable
}
});
})
);
})
.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]
};
})
})
);
});
}
function asArray(obj) {
if (!obj) {return []; }
if (Array.isArray(obj)) {return obj; }
return [obj];
}
gadget_klass gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -27,97 +75,32 @@ ...@@ -27,97 +75,32 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
erp5_document, erp5_document,
result_list,
view_list, view_list,
action_list; action_list;
return gadget.jio_getAttachment(options.jio_key, "links") return gadget.jio_getAttachment(options.jio_key, "links")
.push(function (result) { .push(function (result) {
var i, i_len,
promise_list = [
gadget.getUrlFor({command: 'change', options: {page: undefined}})
];
erp5_document = result; erp5_document = result;
view_list = erp5_document._links.action_workflow || []; view_list = asArray(erp5_document._links.action_workflow);
action_list = erp5_document._links.action_object_action_jio || []; action_list = asArray(erp5_document._links.action_object_action_jio)
if (view_list.constructor !== Array) { .concat(asArray(erp5_document._links.action_object_clone_action));
view_list = [view_list];
}
if (action_list.constructor !== Array) {
action_list = [action_list];
}
for (i = 0; i < view_list.length; i += 1) {
promise_list.push(
gadget.getUrlFor({
command: 'change',
options: {
view: view_list[i].href,
page: undefined
}
})
);
}
if (erp5_document._links.action_object_clone_action) {
action_list.push(erp5_document._links.action_object_clone_action);
}
for (i = 0, i_len = action_list.length; i < i_len; i += 1) {
promise_list.push(
gadget.getUrlFor({
command: 'change',
options: {
view: action_list[i].href,
page: undefined,
editable: true
}
})
);
}
return RSVP.all(promise_list);
})
.push(function (all_result) {
var i,
tab_list = [],
action_tab_list = [];
result_list = all_result;
for (i = 0; i < view_list.length; i += 1) {
tab_list.push({
title: view_list[i].title,
link: all_result[i + 1],
i18n: view_list[i].title
});
}
for (i = 0; i < action_list.length; i += 1) {
action_tab_list.push({
title: action_list[i].title,
link: all_result[i + 1 + view_list.length],
i18n: action_list[i].title
});
}
return RSVP.all([ return RSVP.all([
gadget.translateHtml( renderLinkList(gadget, "Actions", "gear", view_list, options.editable),
table_template({ renderLinkList(gadget, "Workflow Transitions", "random", action_list, true)
definition_title: "Workflow Transitions", ]);
definition_icon: "random",
documentlist: tab_list,
definition_i18n: "Workflow-Transitions"
}) + table_template({
definition_i18n: "Actions",
definition_title: "Actions",
definition_icon: "gear",
documentlist: action_tab_list
}) })
), .push(function (translated_html_link_list) {
calculatePageTitle(gadget, erp5_document) gadget.element.innerHTML = translated_html_link_list.join("\n");
return RSVP.all([
calculatePageTitle(gadget, erp5_document),
gadget.getUrlFor({command: 'change', options: {page: undefined}})
]); ]);
}) })
.push(function (last_result_list) { .push(function (result_list) {
gadget.element.innerHTML = last_result_list[0];
return gadget.updateHeader({ return gadget.updateHeader({
back_url: result_list[0], page_title: result_list[0],
page_title: last_result_list[1] back_url: result_list[1]
}); });
}); });
}); });
......
...@@ -216,7 +216,7 @@ ...@@ -216,7 +216,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>cedric.le.ninivin</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>960.54321.50792.6877</string> </value> <value> <string>962.4062.25838.43485</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1500456255.01</float> <float>1505824423.08</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<script src="gadget_erp5_page_export.js" type="text/javascript"></script> <script src="gadget_erp5_page_export.js" type="text/javascript"></script>
<script id="table-template" type="text/x-handlebars-template"> <script id="table-template" type="text/x-handlebars-template">
{{#if document_list}}
<section class="ui-content-header-plain"> <section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c" data-i18n="[last]{{definition_i18n}}"> <h3 class="ui-content-title ui-body-c" data-i18n="[last]{{definition_i18n}}">
<span class="ui-icon ui-icon-custom ui-icon-{{definition_icon}}">&nbsp;</span> <span class="ui-icon ui-icon-custom ui-icon-{{definition_icon}}">&nbsp;</span>
...@@ -27,10 +28,11 @@ ...@@ -27,10 +28,11 @@
</h3> </h3>
</section> </section>
<ul data-role="listview" data-theme="c" data-inset="true" class="document-listview"> <ul data-role="listview" data-theme="c" data-inset="true" class="document-listview">
{{#each documentlist}} {{#each document_list}}
<li><a data-i18n="{{title}}" class="ui-body-inherit" href="{{link}}">{{title}}</a></li> <li><a data-i18n="{{title}}" class="ui-body-inherit" href="{{link}}">{{title}}</a></li>
{{/each}} {{/each}}
</ul> </ul>
{{/if}}
</script> </script>
</head> </head>
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>957.58323.64047.9540</string> </value> <value> <string>960.5523.58984.43537</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1489072645.22</float> <float>1505229776.11</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -12,6 +12,54 @@ ...@@ -12,6 +12,54 @@
.getElementById("table-template") .getElementById("table-template")
.innerHTML); .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, editable) {
return new RSVP.Queue()
.push(function () {
// obtain RJS links from ERP5 links
return RSVP.all(
erp5_link_list.map(function (erp5_link) {
return gadget.getUrlFor({
"command": 'change',
"options": {
"view": erp5_link.href,
"page": undefined,
"editable": editable
}
});
})
);
})
.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]
};
})
})
);
});
}
function asArray(obj) {
if (!obj) {return []; }
if (Array.isArray(obj)) {return obj; }
return [obj];
}
gadget_klass gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// Acquired methods // Acquired methods
...@@ -27,69 +75,28 @@ ...@@ -27,69 +75,28 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, var gadget = this,
erp5_document, erp5_document,
result_list,
report_list; report_list;
return gadget.jio_getAttachment(options.jio_key, "links") return gadget.jio_getAttachment(options.jio_key, "links")
.push(function (result) { .push(function (result) {
var i, i_len,
promise_list = [
gadget.getUrlFor({command: 'change', options: {page: undefined}})
];
erp5_document = result; erp5_document = result;
report_list = erp5_document._links.action_object_report_jio || []; report_list = asArray(erp5_document._links.action_object_report_jio);
if (report_list.constructor !== Array) {
report_list = [report_list];
}
for (i = 0; i < report_list.length; i += 1) {
promise_list.push(
gadget.getUrlFor({
command: 'change',
options: {
view: report_list[i].href,
page: undefined,
editable: options.editable
}
})
);
}
return RSVP.all(promise_list);
})
.push(function (all_result) {
var i,
tab_list = [],
report_tab_list = [],
html = "";
result_list = all_result;
for (i = 0; i < report_list.length; i += 1) {
report_tab_list.push({
title: report_list[i].title,
link: all_result[i + 1],
i18n: report_list[i].title
});
}
if (i) {
html += table_template({
definition_i18n: "Report",
definition_title: "Report",
definition_icon: "gear",
documentlist: report_tab_list
});
}
return RSVP.all([ return RSVP.all([
gadget.translateHtml(html), renderLinkList(gadget, "Reports", "bar-chart-o", report_list, true)
calculatePageTitle(gadget, erp5_document)
]); ]);
}) })
.push(function (last_result_list) { .push(function (translated_html_link_list) {
gadget.element.innerHTML = last_result_list[0]; gadget.element.innerHTML = translated_html_link_list.join("\n");
return RSVP.all([
calculatePageTitle(gadget, erp5_document),
gadget.getUrlFor({command: 'change', options: {page: undefined}})
]);
})
.push(function (result_list) {
return gadget.updateHeader({ return gadget.updateHeader({
back_url: result_list[0], page_title: result_list[0],
page_title: last_result_list[1] back_url: result_list[1]
}); });
}); });
}); });
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>958.23104.13268.55347</string> </value> <value> <string>962.12722.31387.26146</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1490968345.34</float> <float>1505824496.49</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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