Commit eccce895 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Use a listbox to display the list of modules

This will allow to use domain tree when implemented
parent 613a4144
......@@ -8,28 +8,16 @@
<!-- 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>
<!-- custom script -->
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_page_front.js" type="text/javascript"></script>
<!-- XXX must set theme here! -->
<script id="table-template" type="text/x-handlebars-template">
<div data-role="collapsible">
<h3 class="ui-bar-inherit" data-i18n="{{definition_title}}">{{definition_title}}</h3>
<ul data-role="listview" data-theme="c" class="document-listview">
<!--<li data-role="list-divider"><h1 data-i18n="{{definition_title}}">{{definition_title}}</h1></li>-->
{{#each documentlist}}
<li><a class="ui-body-inherit" data-i18n="{{title}}" href="{{link}}">{{title}}</a></li>
{{/each}}
</ul>
</div>
</script>
</head>
<body>
<section class="document_list"></section>
<div data-gadget-url="gadget_erp5_pt_form_list.html"
data-gadget-scope="form_list"
data-gadget-sandbox="public">
</div>
</body>
</html>
\ No newline at end of file
......@@ -220,7 +220,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>939.43978.9403.31744</string> </value>
<value> <string>952.43255.60632.47035</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,8 +252,8 @@
</tuple>
<state>
<tuple>
<float>1419417426.65</float>
<string>GMT</string>
<float>1468942516.97</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
/*global window, rJS, RSVP, Handlebars */
/*global window, rJS */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars) {
(function (window, rJS) {
"use strict";
/////////////////////////////////////////////////////////////////
// Handlebars
/////////////////////////////////////////////////////////////////
// Precompile the templates while loading the first gadget instance
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.getElementById("table-template")
.innerHTML,
table_template = Handlebars.compile(source);
var gadget_klass = rJS(window);
gadget_klass
/////////////////////////////////////////////////////////////////
......@@ -33,104 +29,85 @@
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
return gadget.jio_allDocs({
"query": 'meta_type:"ERP5 Folder" AND id:"%_module"',
"select_list": ["title", "business_application_title"],
"limit": 1000
})
.allowPublicAcquisition('updateHeader', function () {
return;
})
.allowPublicAcquisition('getUrlFor', function (argument_list) {
if (argument_list[0].command === 'index') {
return this.getUrlFor({command: 'display_stored_state', options: {jio_key: argument_list[0].options.jio_key}});
}
return this.getUrlFor.apply(this, argument_list);
})
.allowPublicAcquisition('getUrlParameter', function (argument_list) {
return this.getUrlParameter(argument_list)
.push(function (result) {
var result_list = [],
i;
for (i = 0; i < result.data.rows.length; i += 1) {
result_list.push(RSVP.all([
gadget.getUrlFor({command: 'display_stored_state', options: {jio_key: result.data.rows[i].id}}),
result.data.rows[i].value.title || result.data.rows[i].id,
result.data.rows[i].value.business_application_title
]));
}
return RSVP.all(result_list);
})
.push(function (document_list) {
var i,
business_application_dict = {},
business_application_list = [],
business_application,
module_info,
result_html = '<div data-role="collapsible-set" data-theme="c">',
doc;
for (i = 0; i < document_list.length; i += 1) {
doc = document_list[i];
if (doc[2] === undefined) {
doc[2] = "Other";
}
module_info = {
link: doc[0],
title: doc[1]
};
if (business_application_dict[doc[2]] === undefined) {
business_application_dict[doc[2]] = [module_info];
business_application_list.push(doc[2]);
} else {
business_application_dict[doc[2]].push(module_info);
}
}
business_application_list.sort(function (a, b) {
// Push the "Other" value at the end
var result = 0;
if (a === "Other") {
result = 1;
} else if (b === "Other") {
result = -1;
} else if (a < b) {
result = -1;
} else if (a > b) {
result = 1;
}
return result;
});
function sort_module(a, b) {
var result = 0;
if (a.title < b.title) {
result = -1;
} else if (a.title > b.title) {
result = 1;
}
return result;
if ((result === undefined) && (argument_list[0] === 'field_listbox_sort_list:json')) {
return [['title', 'ascending']];
}
return result;
});
})
.declareMethod("triggerSubmit", function () {
var argument_list = arguments;
return this.getDeclaredGadget('form_list')
.push(function (gadget) {
return gadget.triggerSubmit.apply(gadget, argument_list);
});
})
.declareMethod("render", function () {
var gadget = this,
header_dict = {
page_title: 'Modules',
filter_action: true
};
for (i = 0; i < business_application_list.length; i += 1) {
business_application = business_application_list[i];
business_application_dict[business_application].sort(sort_module);
result_html += table_template({
definition_title: business_application,
documentlist: business_application_dict[business_application]
});
}
result_html += '</div>';
return gadget.translateHtml(result_html);
return gadget.updateHeader(header_dict)
.push(function () {
return gadget.getDeclaredGadget('form_list');
})
.push(function (my_translated_html) {
gadget.props.element.querySelector('.document_list').innerHTML =
my_translated_html;
return gadget.updateHeader({
page_title: 'Modules'
.push(function (form_gadget) {
var column_list = [
['title', 'Title']
];
return form_gadget.render({
erp5_document: {"_embedded": {"_view": {
"listbox": {
"column_list": column_list,
"show_anchor": 0,
"default_params": {},
"editable": 1,
"editable_column_list": [],
"key": "field_listbox",
"lines": 1000,
"list_method": "portal_catalog",
"query": "urn:jio:allDocs?query=meta_type%3A%22ERP5%20Folder%22%20AND%20id%3A%22%25_module%22",
"portal_type": [],
"search_column_list": column_list,
"sort_column_list": column_list,
"title": "Modules",
"type": "ListBox"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}},
form_definition: {
group_list: [[
"bottom",
[["listbox"]]
]]
}
});
});
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
}(window, rJS));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>947.821.64587.50432</string> </value>
<value> <string>952.43287.48740.12117</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1447323452.37</float>
<float>1468942890.74</float>
<string>UTC</string>
</tuple>
</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