Commit a249d771 authored by Romain Courteaud's avatar Romain Courteaud

Add support for listbox's custom list methods.

This is for now an had-hoc working implementation.

In order to make it more maintainable, it will probably be required to handle attachment's mime type correctly in the JS.
parent 2c0d6e8a
......@@ -69,13 +69,14 @@ return context.ERP5Document_getHateoas(\n
limit=limit,\n
form=form,\n
relative_url=relative_url,\n
list_method=list_method,\n
restricted=1\n
)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None, list_method=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -75,12 +75,16 @@ url_template_dict = {\n
"{&relative_url,view}",\n
"search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"{&query,select_list*,limit*}",\n
"custom_search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"&relative_url=%(relative_url)s" \\\n
"&list_method=%(list_method)s" \\\n
"{&query,select_list*,limit*}",\n
"new_content_action": "%(root_url)s/%(script_id)s?mode=newContent",\n
# XXX View is set by default to empty\n
"document_hal": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n
"&relative_url=%(relative_url)s",\n
"jio_get_template": "urn:jio:get:%(relative_url)s",\n
"jio_search_template": "urn:jio:allDocs?%(query)s",\n
"jio_search_template": "urn:jio:allDocs?%(query)s"\n
}\n
\n
default_document_uri_template = url_template_dict["jio_get_template"]\n
......@@ -180,13 +184,19 @@ def renderField(field, meta_type=None):\n
list_method_query_dict = dict(\n
portal_type=[x[1] for x in portal_types], **default_params\n
)\n
list_method_custom = None\n
\n
if (list_method_name == "portal_catalog"):\n
pass\n
elif (list_method_name in ("searchFolder", "objectValues")):\n
list_method_query_dict["parent_uid"] = traversed_document.getUid()\n
else:\n
list_method_query_dict = None\n
list_method_custom = url_template_dict["custom_search_template"] % {\n
"root_url": site_root.absolute_url(),\n
"script_id": script.id,\n
"relative_url": traversed_document.getRelativeUrl().replace("/", "%2F"),\n
"list_method": list_method_name\n
}\n
\n
\n
# row_list = list_method(limit=lines, portal_type=portal_types,\n
......@@ -221,12 +231,14 @@ def renderField(field, meta_type=None):\n
"default_params": default_params,\n
"list_method": list_method_name\n
}\n
if (list_method_query_dict is not None):\n
result["query"] = url_template_dict["jio_search_template"] % {\n
"query": make_query({"query": sql_catalog.buildQuery(\n
list_method_query_dict\n
).asSearchTextExpression(sql_catalog)})\n
}\n
if (list_method_custom is not None):\n
result["list_method_template"] = list_method_custom\n
\n
result["query"] = url_template_dict["jio_search_template"] % {\n
"query": make_query({"query": sql_catalog.buildQuery(\n
list_method_query_dict\n
).asSearchTextExpression(sql_catalog)})\n
}\n
else:\n
# XXX Not implemented\n
result = {\n
......@@ -682,10 +694,14 @@ elif mode == \'search\':\n
# length = len(\'/%s/\' % portal.getId())\n
# # context.log(portal.portal_catalog(full_text=query, limit=limit, src__=1))\n
# context.log(query)\n
if (list_method is None):\n
callable_list_method = portal.portal_catalog\n
else:\n
callable_list_method = getattr(traversed_document, list_method)\n
if query:\n
sql_list = portal.portal_catalog(full_text=query, limit=limit)\n
sql_list = callable_list_method(full_text=query, limit=limit)\n
else:\n
sql_list = portal.portal_catalog(limit=limit)\n
sql_list = callable_list_method(limit=limit)\n
\n
result_list = []\n
\n
......@@ -801,7 +817,7 @@ return json.dumps(result_dict, indent=2)\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None, restricted=0</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None, restricted=0, list_method=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -108,8 +108,8 @@
<value> <string encoding="cdata"><![CDATA[
/*jslint indent: 2, maxerr: 3, nomen: true */\n
/*global window, document, rJS, URI, RSVP */\n
(function (window, document, rJS, URI, RSVP) {\n
/*global window, document, rJS, URI, RSVP, UriTemplate */\n
(function (window, document, rJS, URI, RSVP, UriTemplate) {\n
"use strict";\n
\n
rJS(window)\n
......@@ -133,6 +133,7 @@
// acquired method\n
//////////////////////////////////////////////\n
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")\n
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")\n
.declareAcquiredMethod("translateHtml", "translateHtml")\n
.declareAcquiredMethod("whoWantToDisplayThis", "whoWantToDisplayThis")\n
.declareAcquiredMethod("pleasePublishMyState", "pleasePublishMyState")\n
......@@ -185,8 +186,10 @@
select_list = [],\n
dataset,\n
counter,\n
i;\n
\n
i,\n
list_method_promise = function () {\n
return gadget.jio_allDocs.apply(gadget, arguments);\n
};\n
if (field_json.query === undefined) {\n
original_tfoot.textContent = "Unsupported list method: \'" + field_json.list_method + "\'";\n
return;\n
......@@ -204,7 +207,43 @@
select_list.push(field_json.column_list[i][0]);\n
}\n
\n
return gadget.jio_allDocs({\n
if (field_json.list_method_template !== undefined) {\n
list_method_promise = function (option_dict) {\n
return gadget.jio_getAttachment({\n
// XXX Ugly hardcoded meaningless id...\n
"_id": "erp5",\n
"_attachment": new UriTemplate.parse(field_json.list_method_template)\n
.expand(option_dict)\n
})\n
.push(function (catalog_json) {\n
catalog_json = catalog_json.data;\n
var data = catalog_json._embedded.contents,\n
count = data.length,\n
k,\n
uri,\n
item,\n
result = [];\n
for (k = 0; k < count; k += 1) {\n
item = data[k];\n
uri = new URI(item._links.self.href);\n
delete item._links;\n
result.push({\n
id: uri.segment(2),\n
doc: {},\n
value: item\n
});\n
}\n
return {\n
data: {\n
rows: result,\n
total_rows: result.length\n
}\n
};\n
});\n
};\n
}\n
\n
return list_method_promise({\n
"query": new URI(field_json.query).query(true).query + query_string,\n
"limit": [begin_from, begin_from + lines + 1],\n
"select_list": select_list\n
......@@ -348,7 +387,7 @@
});\n
});\n
\n
}(window, document, rJS, URI, RSVP));
}(window, document, rJS, URI, RSVP, UriTemplate));
]]></string> </value>
</item>
......@@ -471,7 +510,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>romain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -485,7 +524,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.11535.19754.41932</string> </value>
<value> <string>940.50579.22253.1297</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -503,8 +542,8 @@
</tuple>
<state>
<tuple>
<float>1420800963.59</float>
<string>UTC</string>
<float>1423143600.86</float>
<string>GMT</string>
</tuple>
</state>
</object>
......
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