Commit 3b41be41 authored by Roque's avatar Roque

erp5_web_project_ui: get project home page by publication section preference

- script to retrieve project related pages
- use global preference to get publication section value
parent 727dac9b
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery
kw.pop('relative_url', None)
kw.pop('follow_up_uid', None)
portal_catalog=context.getPortalObject().portal_catalog
follow_up_related_document_list = portal_catalog(
portal_type=portal_type,
follow_up_uid=context.getUid(), **kw)
kw['query'] = Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_'))
if follow_up_related_document_list:
kw['query'] = ComplexQuery(
kw['query'],
Query(uid=[x.getUid() for x in follow_up_related_document_list]),
logical_operator='or')
return [x.getRelativeUrl() for x in portal_catalog(portal_type=portal_type, limit=limit, **kw)]
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>portal_type= (), limit=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Project_getRelatedDocumentList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -253,7 +253,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: {"project_title":here.getTitle(), "jio_key": here.getRelativeUrl(), "project_reference": here.getReference()}</string> </value>
<value> <string>python: {"project_title":here.getTitle(), "jio_key": here.getRelativeUrl(), "home_page_preference": "project_home_page", "project_pages": [x.replace("web_page_module/", "") for x in here.Project_getRelatedDocumentList("Web Page")]}</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -110,13 +110,16 @@
}));
}
function getWebPageInfo(gadget, project_reference) {
function getWebPageInfo(gadget, home_page_preference, project_pages) {
var id,
content,
edit_view,
redirector_ulr,
i,
query,
query_list = [],
id_query_list = [],
validation_state_query_list = [],
valid_state_list = ["shared_alive", "released_alive", "published_alive"];
query_list.push(new SimpleQuery({
key: "portal_type",
......@@ -124,31 +127,51 @@
type: "simple",
value: "Web Page"
}));
query_list.push(new SimpleQuery({
key: "reference",
operator: "=",
type: "simple",
value: project_reference + '-Home.Page'
for (i = 0; i < valid_state_list.length; i += 1) {
validation_state_query_list.push(new SimpleQuery({
key: "validation_state",
type: "simple",
operator: "=",
value: valid_state_list[i]
}));
}
query_list.push(new ComplexQuery({
operator: "OR",
query_list: validation_state_query_list,
type: "complex"
}));
query = new ComplexQuery({
for (i = 0; i < project_pages.length; i += 1) {
id_query_list.push(new SimpleQuery({
key: "id",
type: "simple",
operator: "=",
value: project_pages[i]
}));
}
query_list.push(new ComplexQuery({
operator: "OR",
query_list: id_query_list,
type: "complex"
}));
query = Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: query_list,
type: "complex"
});
}));
return gadget.getUrlFor({command: 'push_history', options: {page: "project_redirector"}})
.push(function (url) {
redirector_ulr = url;
return gadget.jio_allDocs({
query: Query.objectToSearchText(query),
select_list: ['validation_state', 'text_content']
query: query,
select_list: ['text_content', 'publication_section']
});
})
.push(function (result_list) {
if (result_list.data.rows[0]) {
var i, state, web_page;
var i, web_page, publication_section;
for (i = 0; i < result_list.data.rows.length; i = i + 1) {
state = result_list.data.rows[i].value.validation_state;
if (valid_state_list.includes(state)) {
publication_section = result_list.data.rows[i].value.publication_section;
if (publication_section === home_page_preference) {
web_page = result_list.data.rows[i];
break;
}
......@@ -196,7 +219,8 @@
var state_dict = {
jio_key: options.jio_key || "",
project_title: options.project_title,
project_reference: options.project_reference
home_page_preference: options.home_page_preference,
project_pages: options.project_pages
};
return this.changeState(state_dict);
})
......@@ -208,7 +232,7 @@
return new RSVP.Queue()
.push(function () {
return RSVP.all([
getWebPageInfo(gadget, modification_dict.project_reference),
getWebPageInfo(gadget, modification_dict.home_page_preference, modification_dict.project_pages),
gadget.getDeclaredGadget("editor"),
gadget.getSetting("hateoas_url")
]);
......
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