Commit 22b7d084 authored by Łukasz Nowak's avatar Łukasz Nowak

Follow current changes.

Do not care about software products: users are only interested in software
releases.

By default show some software releases.

Follow protection against json XSS (make it incorrect javascript).

Drop not needed methods.

Use catalog directly while fetching list of software releases.
parent 55b75b8a
......@@ -53,7 +53,7 @@
<value> <string>result = []\n
for computer in context.getPortalObject().portal_catalog(portal_type=\'Computer\', validation_state=\'validated\'):\n
result.append({\'id\': computer.getReference(), \'title\': computer.getTitle()})\n
return context.asJSON(result)\n
return context.asJSON({"computer_list": result})\n
</string> </value>
</item>
<item>
......
<?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>_body</string> </key>
<value> <string>response = []\n
\n
kw = {}\n
kw.update(\n
portal_type=\'Software Product\',\n
validation_state=\'published\',\n
limit=(offset, limit),\n
title=title\n
)\n
if title:\n
for software_product in context.getPortalObject().portal_catalog(**kw\n
):\n
response.append({\'title\': software_product.getTitle(), \'image\': software_product.getDefaultImageAbsoluteUrl() + \'/Base_download\', \'uid\': software_product.getUid()})\n
return context.asJSON(response)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>title, offset=0, limit=10</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getSoftwareProductListAsJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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>_body</string> </key>
<value> <string>response = []\n
\n
kw = {}\n
kw.update(\n
portal_type=\'Software Release\',\n
validation_state=\'published\',\n
uid=software_release_uid,\n
)\n
software_release = context.getPortalObject().portal_catalog.getResultValue(**kw)\n
return context.asJSON({\n
\'url\': software_release.getUrlString(),\n
\'title\': software_release.getTitle(),\n
\'version\': software_release.getVersion(),\n
})\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>software_release_uid</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getSoftwareReleaseAsJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -50,27 +50,44 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>response = []\n
\n
portal_catalog = context.getPortalObject().portal_catalog\n
<value> <string>portal_catalog = context.getPortalObject().portal_catalog\n
kw = {}\n
\n
if title is not None:\n
kw[\'title\'] = title\n
if uid is not None:\n
kw[\'uid\'] = uid\n
\n
kw.update(\n
portal_type=\'Software Release\',\n
validation_state=\'published\',\n
select_dict={\n
\'title\': None,\n
\'description\': None,\n
\'software_release_url\': \'software_release.url\',\n
\'image_url\': \'software_release.image_relative_url\'\n
},\n
limit=(offset, limit),\n
title=title,\n
aggregate_relative_url=portal_catalog.getResultValue(uid=software_product_uid).getRelativeUrl()\n
**{\'software_release.state\': \'stopped\'}\n
)\n
if title:\n
for software_release in portal_catalog(**kw\n
):\n
response.append({\'title\': software_release.getTitle(), \'uid\': software_release.getUid(), \'version\': software_release.getVersion()})\n
return context.asJSON(response)\n
\n
response = []\n
\n
prefix_url = context.absolute_url()\n
for q in portal_catalog(**kw):\n
response.append({\n
\'uid\': q.UID,\n
\'title\': q.TITLE,\n
\'description\': q.DESCRIPTION,\n
\'image\': \'/\'.join([prefix_url, q.IMAGE_URL, \'Base_download\']),\n
\'url\': q.SOFTWARE_RELEASE_URL,\n
})\n
return context.asJSON({\'software_release_list\':response})\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>software_product_uid, title, offset=0, limit=10</string> </value>
<value> <string>title=None, uid=None, offset=0, limit=10</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -8,7 +8,7 @@
<dictionary>
<item>
<key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts21438314.37</string> </value>
<value> <string>ts21542815.59</string> </value>
</item>
<item>
<key> <string>__name__</string> </key>
......@@ -22,55 +22,34 @@
<key> <string>data</string> </key>
<value> <string encoding="cdata"><![CDATA[
function drawSoftwareProductList(data) {\n
$(\'#software_product_container\').empty()\n
var ul = $(\'<ul>\');\n
$.each(data, function(i,item){\n
li = $(\'<li>\').appendTo(ul);\n
var a = $(\'<a>\');\n
a.attr({\'href\': \'#!software_product/\' + item.uid})\n
var img = $(\'<img>\');\n
img.attr({\n
\'alt\': item.title,\n
\'src\': item.image,\n
\'width\': \'100\',\n
\'height\': \'40\'})\n
img.appendTo(a);\n
a.html(a.html() + item.title);\n
a.appendTo(li);\n
});\n
$("#software_product_container").append(ul);\n
}\n
\n
function drawSoftwareReleaseList(data) {\n
$(\'#software_release_container\').empty()\n
var ul = $(\'<ul>\');\n
$.each(data, function(i,item){\n
$.each(data[\'software_release_list\'], function(i,item){\n
li = $(\'<li>\').appendTo(ul);\n
var a = $(\'<a>\');\n
a.attr({\n
\'href\': \'#!software_release/\' + item.uid });\n
a.html(item.title + \' (\' + item.version + \')\');\n
var img = $(\'<img>\');\n
img.attr({\n
\'src\': item.image,\n
\'alt\': item.title,\n
\'title\': item.title,\n
\'height\': 40,\n
\'width\': 100\n
});\n
a.append(img);\n
a.html(a.html() + item.title + \' (\' + item.description + \')\');\n
a.appendTo(li);\n
});\n
$("#software_release_container").append(ul);\n
}\n
\n
function updateSoftwareProductList() {\n
q = $(\'#software_product_query\')[0][\'value\']\n
$.getJSON(\n
vifib[\'site_url\'] + "/ERP5Site_getSoftwareProductListAsJSON",\n
{"title":q},\n
drawSoftwareProductList);\n
}\n
\n
function updateSoftwareReleaseList() {\n
software_product_id = /#!software_product\\/([0-9]+)?/.exec(window.location.hash)[1];\n
software_product_id = parseInt(software_product_id);\n
q = $(\'#software_release_query\')[0][\'value\']\n
$.getJSON(\n
vifib[\'site_url\'] + "/ERP5Site_getSoftwareReleaseListAsJSON",\n
{"title":q, "software_product_uid": software_product_id},\n
{"title":q},\n
drawSoftwareReleaseList);\n
}\n
\n
......@@ -92,25 +71,9 @@ function softwareReleaseController() {\n
software_release_container.attr(\'id\', \'software_release_container\');\n
refresh.after(software_release_container);\n
refresh.click(updateSoftwareReleaseList);\n
}\n
\n
function softwareProductController () {\n
js_container = $("#js_container");\n
js_container.empty();\n
\n
var input = $(\'<input type="text">\');\n
input.attr(\'id\', "software_product_query");\n
js_container.append(input);\n
\n
var refresh = $(\'<input type="button">\');\n
refresh.attr(\'value\', \'Refresh...\');\n
refresh.addClass(\'bt-med dialog_submit_button\');\n
input.after(refresh);\n
software_product_container = $(\'<div>\');\n
software_product_container.attr(\'id\', \'software_product_container\');\n
refresh.after(software_product_container);\n
refresh.click(updateSoftwareProductList);\n
\n
$.getJSON(\n
vifib[\'site_url\'] + "/ERP5Site_getSoftwareReleaseListAsJSON",\n
drawSoftwareReleaseList);\n
}\n
\n
function processRequest() {\n
......@@ -132,6 +95,7 @@ function processRequest() {\n
}\n
\n
function drawRequest(data) {\n
data = data[\'software_release_list\'][0];\n
js_container = $("#js_container");\n
js_container.empty();\n
url_a = $(\'<input type="hidden">\');\n
......@@ -161,7 +125,7 @@ function drawRequest(data) {\n
option = $(\'<option>\');\n
option.attr(\'value\', \'\');\n
option.appendTo(computer_a);\n
$.each(data, function(i, item){\n
$.each(data[\'computer_list\'], function(i, item){\n
computer_a = $(\'#computer\');\n
option = $(\'<option>\');\n
option.attr(\'value\', item.id);\n
......@@ -170,7 +134,7 @@ function drawRequest(data) {\n
});\n
});\n
summary = $(\'<div>\');\n
summary.html(\'Software Release: \' + data.title + \' (\' + data.version + \'), url: \' + data.url);\n
summary.html(\'Software Release: \' + data.title + \' (\' + data.description + \'), url: \' + data.url);\n
js_container.append(summary);\n
request = $(\'<input type="button">\');\n
request.attr(\'value\', \'Request\');\n
......@@ -185,8 +149,8 @@ function requestController() {\n
software_release_id = /#!software_release\\/([0-9]+)?/.exec(window.location.hash)[1];\n
software_release_id = parseInt(software_release_id);\n
$.getJSON(\n
vifib[\'site_url\'] + "/ERP5Site_getSoftwareReleaseAsJSON",\n
{"software_release_uid":software_release_id},\n
vifib[\'site_url\'] + "/ERP5Site_getSoftwareReleaseListAsJSON",\n
{"uid":software_release_id},\n
drawRequest);\n
}\n
\n
......@@ -194,10 +158,6 @@ function requestController() {\n
var hash_list = [\n
{\n
\'regexp\': /^$/, \n
\'func\': softwareProductController,\n
},\n
{\n
\'regexp\': /^#!software_product\\/([0-9]+)?$/, \n
\'func\': softwareReleaseController,\n
},\n
{\n
......@@ -237,7 +197,7 @@ function hashController ()\n
</item>
<item>
<key> <string>size</string> </key>
<value> <int>5885</int> </value>
<value> <int>4656</int> </value>
</item>
<item>
<key> <string>title</string> </key>
......
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