Commit 4ffdaa40 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Add draft support for editable listbox

parent 84f8caf1
......@@ -71,13 +71,14 @@ return context.ERP5Document_getHateoas(\n
relative_url=relative_url,\n
list_method=list_method,\n
default_param_json=default_param_json,\n
form_relative_url=form_relative_url,\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=10, form=None, relative_url=None, list_method=None, default_param_json=None</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -78,6 +78,7 @@ url_template_dict = {\n
"{&query,select_list*,limit*}",\n
"custom_search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"&relative_url=%(relative_url)s" \\\n
"&form_relative_url=%(form_relative_url)s" \\\n
"&list_method=%(list_method)s" \\\n
"&default_param_json=%(default_param_json)s" \\\n
"{&query,select_list*,limit*}",\n
......@@ -104,16 +105,18 @@ def getFieldDefault(field, key):\n
# REQUEST.get(field.id, field.get_value("default"))\n
return traversed_document.Field_getDefaultValue(field, key, REQUEST)\n
\n
def renderField(field, meta_type=None):\n
def renderField(field, form_relative_url, meta_type=None, key=None):\n
if meta_type is None:\n
meta_type = field.meta_type\n
if key is None:\n
key = field.generate_field_key()\n
\n
if meta_type == "ProxyField":\n
result = renderField(field, meta_type=field.getRecursiveTemplateField().meta_type)\n
result = renderField(field, form_relative_url, meta_type=field.getRecursiveTemplateField().meta_type, key=key)\n
elif meta_type == "ListField":\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -127,7 +130,7 @@ def renderField(field, meta_type=None):\n
elif meta_type in ("ParallelListField", "MultiListField"):\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -145,7 +148,7 @@ def renderField(field, meta_type=None):\n
"PasswordField", "EditorField"):\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -159,7 +162,7 @@ def renderField(field, meta_type=None):\n
elif meta_type == "DateTimeField":\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -196,7 +199,7 @@ def renderField(field, meta_type=None):\n
accessor_name = \'get%sValue\' % \\\n
\'\'.join([part.capitalize() for part in base_category.split(\'_\')])\n
jump_reference = getattr(traversed_document, accessor_name)(\n
portal_type=map(lambda x:x[0], field.get_value(\'portal_type\')),\n
portal_type=[x[0] for x in field.get_value(\'portal_type\')],\n
filter=kw\n
)\n
\n
......@@ -213,7 +216,7 @@ def renderField(field, meta_type=None):\n
# "allow_creation": field.get_value(\'allow_creation\'),\n
"allow_creation": 0,\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -238,7 +241,7 @@ def renderField(field, meta_type=None):\n
elif meta_type == "CheckBoxField":\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -249,7 +252,7 @@ def renderField(field, meta_type=None):\n
elif meta_type == "GadgetField":\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"key": key,\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
......@@ -261,7 +264,9 @@ def renderField(field, meta_type=None):\n
result["default"] = getFieldDefault(field, result["key"])\n
elif meta_type == "ListBox":\n
# XXX Not implemented\n
columns = field.get_value("columns")\n
column_list = field.get_value("columns")\n
search_column_list = field.get_value(\'search_columns\')\n
editable_column_list = field.get_value(\'editable_columns\')\n
\n
# XXX \n
# list_method = getattr(traversed_document, traversed_document.Listbox_getListMethodName(field))\n
......@@ -277,7 +282,17 @@ def renderField(field, meta_type=None):\n
)\n
list_method_custom = None\n
\n
if (list_method_name == "portal_catalog"):\n
if (editable_column_list):\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
"form_relative_url": "%s/%s" % (form_relative_url, field.id),\n
"list_method": list_method_name,\n
"default_param_json": urlsafe_b64encode(json.dumps(list_method_query_dict))\n
}\n
list_method_query_dict = {}\n
elif (list_method_name == "portal_catalog"):\n
pass\n
elif (list_method_name == "searchFolder"):\n
list_method_query_dict["parent_uid"] = traversed_document.getUid()\n
......@@ -313,11 +328,14 @@ def renderField(field, meta_type=None):\n
\n
result = {\n
"type": meta_type,\n
"editable": field.get_value("editable"),\n
# "column_list": [x[1] for x in columns],\n
"column_list": columns,\n
"column_list": column_list,\n
"search_column_list": search_column_list,\n
"editable_column_list": editable_column_list,\n
# "line_list": line_list,\n
"title": field.get_value("title"),\n
"key": field.generate_field_key(),\n
"key": key,\n
"portal_type": portal_types,\n
"lines": lines,\n
"default_params": default_params,\n
......@@ -337,7 +355,7 @@ def renderField(field, meta_type=None):\n
"type": meta_type,\n
"_debug": "Unsupported field type",\n
"title": field.get_value("title"),\n
"key": field.generate_field_key(),\n
"key": key,\n
}\n
return result\n
\n
......@@ -367,6 +385,7 @@ def renderForm(form, response_dict):\n
"title": traversed_document.getTitle()\n
}\n
\n
form_relative_url = getFormRelativeUrl(form)\n
response_dict[\'_links\'][\'form_definition\'] = {\n
# "href": default_document_uri_template % {\n
# "root_url": site_root.absolute_url(),\n
......@@ -374,7 +393,7 @@ def renderForm(form, response_dict):\n
# "relative_url": getFormRelativeUrl(form)\n
# },\n
"href": default_document_uri_template % {\n
"relative_url": getFormRelativeUrl(form)\n
"relative_url": form_relative_url\n
},\n
\'name\': form.id\n
}\n
......@@ -387,7 +406,7 @@ def renderForm(form, response_dict):\n
# field_list.append((field.id, renderRawField(field)))\n
if field.get_value("enabled"):\n
try:\n
response_dict[field.id] = renderField(field)\n
response_dict[field.id] = renderField(field, form_relative_url)\n
if field_errors.has_key(field.id):\n
response_dict[field.id]["error_text"] = field_errors[field.id].error_text\n
except AttributeError:\n
......@@ -830,10 +849,22 @@ elif mode == \'search\':\n
# else:\n
\n
# Cast to list if only one element is provided\n
editable_field_dict = {}\n
if select_list is None:\n
select_list = []\n
elif same_type(select_list, ""):\n
select_list = [select_list]\n
\n
if select_list:\n
if (form_relative_url is not None):\n
listbox_field = portal.restrictedTraverse(form_relative_url)\n
listbox_field_id = listbox_field.id\n
# XXX Proxy field are not correctly handled in traversed_document of web site\n
listbox_form = getattr(traversed_document, listbox_field.aq_parent.id)\n
for select in select_list:\n
# See Listbox.py getEditableField method\n
if listbox_form.has_field("%s_%s" % (listbox_field_id, select), include_disabled=1):\n
editable_field_dict[select] = listbox_form.get_field("%s_%s" % (listbox_field_id, select), include_disabled=1)\n
\n
for sql_document in sql_list:\n
try:\n
......@@ -841,6 +872,7 @@ elif mode == \'search\':\n
except AttributeError:\n
# XXX ERP5 Site is not an ERP5 document\n
document = sql_document\n
document_uid = document.getUid()\n
document_result = {\n
# \'_relative_url\': sql_document.path[length:],\n
\'_links\': {\n
......@@ -854,8 +886,18 @@ elif mode == \'search\':\n
},\n
}\n
}\n
if editable_field_dict:\n
document_result[\'listbox_uid:list\'] = {\n
\'key\': "%s_uid:list" % listbox_field_id,\n
\'value\': document_uid\n
}\n
for select in select_list:\n
property_value = document.getProperty(select, d=None)\n
if editable_field_dict.has_key(select):\n
REQUEST.set(\'cell\', document)\n
property_value = renderField(editable_field_dict[select], form_relative_url, key=\'field_%s_%s\' % (editable_field_dict[select].id, document_uid))\n
REQUEST.other.pop(\'cell\', None)\n
else:\n
property_value = document.getProperty(select, d=None)\n
if property_value is not None:\n
if same_type(property_value, DateTime()):\n
# Serialize DateTime\n
......@@ -914,7 +956,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=10, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None</string> </value>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -111,6 +111,39 @@
/////////////////////////////////////////////////////////////////\n
// Precompile the templates while loading the first gadget instance\n
var gadget_klass = rJS(window);\n
\n
function getFieldTypeGadgetUrl(type) {\n
var field_url = \'gadget_erp5_field_readonly.html\';\n
if (type === \'ListField\') {\n
field_url = \'gadget_erp5_field_list.html\';\n
} else if ((type === \'ParallelListField\') ||\n
(type === \'MultiListField\')) {\n
field_url = \'gadget_erp5_field_multilist.html\';\n
} else if (type === \'CheckBoxField\') {\n
field_url = \'gadget_erp5_field_checkbox.html\';\n
} else if (type === \'StringField\') {\n
field_url = \'gadget_erp5_field_string.html\';\n
} else if (type === \'RelationStringField\') {\n
field_url = \'gadget_erp5_field_relationstring.html\';\n
} else if (type === \'TextAreaField\') {\n
field_url = \'gadget_erp5_field_textarea.html\';\n
} else if (type === \'DateTimeField\') {\n
field_url = \'gadget_erp5_field_datetime.html\';\n
} else if (type === \'FloatField\') {\n
field_url = \'gadget_erp5_field_float.html\';\n
} else if (type === \'IntegerField\') {\n
field_url = \'gadget_erp5_field_integer.html\';\n
} else if (type === \'ListBox\') {\n
field_url = \'gadget_erp5_field_listbox.html\';\n
} else if (type === \'EditorField\') {\n
field_url = \'gadget_erp5_field_textarea.html\';\n
// field_url = \'gadget_codemirror.html\';\n
// sandbox = \'iframe\';\n
} else if (type === \'GadgetField\') {\n
field_url = \'gadget_erp5_field_gadget.html\';\n
}\n
return field_url;\n
}\n
\n
gadget_klass\n
/////////////////////////////////////////////////////////////////\n
......@@ -150,6 +183,11 @@
gadget_element.previousElementSibling.querySelector("span").textContent = "";\n
});\n
})\n
\n
.allowPublicAcquisition("getFieldTypeGadgetUrl", function (param_list) {\n
return getFieldTypeGadgetUrl(param_list[0]);\n
})\n
\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
/////////////////////////////////////////////////////////////////\n
......@@ -191,7 +229,7 @@
// Field is enabled in this context\n
var field_queue = new RSVP.Queue(),\n
sandbox = "public",\n
field_url = \'gadget_erp5_field_readonly.html\',\n
field_url,\n
// Don\'t change the structure without changing notifyValid and notifyInvalid\n
field_element = document.createElement("div"),\n
gadget_element = document.createElement("div"),\n
......@@ -213,34 +251,8 @@
if (group[0] !== "bottom") {\n
field_element.appendChild(label_element);\n
}\n
if (renderered_field.type === \'ListField\') {\n
field_url = \'gadget_erp5_field_list.html\';\n
} else if ((renderered_field.type === \'ParallelListField\') ||\n
(renderered_field.type === \'MultiListField\')) {\n
field_url = \'gadget_erp5_field_multilist.html\';\n
} else if (renderered_field.type === \'CheckBoxField\') {\n
field_url = \'gadget_erp5_field_checkbox.html\';\n
} else if (renderered_field.type === \'StringField\') {\n
field_url = \'gadget_erp5_field_string.html\';\n
} else if (renderered_field.type === \'RelationStringField\') {\n
field_url = \'gadget_erp5_field_relationstring.html\';\n
} else if (renderered_field.type === \'TextAreaField\') {\n
field_url = \'gadget_erp5_field_textarea.html\';\n
} else if (renderered_field.type === \'DateTimeField\') {\n
field_url = \'gadget_erp5_field_datetime.html\';\n
} else if (renderered_field.type === \'FloatField\') {\n
field_url = \'gadget_erp5_field_float.html\';\n
} else if (renderered_field.type === \'IntegerField\') {\n
field_url = \'gadget_erp5_field_integer.html\';\n
} else if (renderered_field.type === \'ListBox\') {\n
field_url = \'gadget_erp5_field_listbox.html\';\n
} else if (renderered_field.type === \'EditorField\') {\n
field_url = \'gadget_erp5_field_textarea.html\';\n
// field_url = \'gadget_codemirror.html\';\n
// sandbox = \'iframe\';\n
} else if (renderered_field.type === \'GadgetField\') {\n
field_url = \'gadget_erp5_field_gadget.html\';\n
}\n
\n
field_url = getFieldTypeGadgetUrl(renderered_field.type);\n
\n
return field_queue\n
.push(function () {\n
......@@ -480,7 +492,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value>
<value> <string>romain</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -494,7 +506,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.60735.27223.48179</string> </value>
<value> <string>943.18226.40997.54510</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -512,8 +524,8 @@
</tuple>
<state>
<tuple>
<float>1423755151.34</float>
<string>UTC</string>
<float>1432653451.85</float>
<string>GMT</string>
</tuple>
</state>
</object>
......
......@@ -118,7 +118,10 @@
/////////////////////////////////////////////////////////////////\n
// Init local properties\n
.ready(function (g) {\n
g.props = {};\n
g.props = {\n
cell_gadget_list: [],\n
listbox_uid_dict: {}\n
};\n
})\n
\n
// Assign the element to a variable\n
......@@ -137,6 +140,7 @@
.declareAcquiredMethod("translateHtml", "translateHtml")\n
.declareAcquiredMethod("whoWantToDisplayThis", "whoWantToDisplayThis")\n
.declareAcquiredMethod("pleasePublishMyState", "pleasePublishMyState")\n
.declareAcquiredMethod("getFieldTypeGadgetUrl", "getFieldTypeGadgetUrl")\n
//////////////////////////////////////////////\n
// initialize the gadget content\n
//////////////////////////////////////////////\n
......@@ -263,27 +267,60 @@
th,\n
a,\n
result = result_list[0],\n
tmp_url;\n
tmp_url,\n
value,\n
promise_list = [],\n
uid_value,\n
uid_value_dict = {};\n
\n
dataset = result;\n
function renderSubCell(element, sub_field_json) {\n
return gadget.getFieldTypeGadgetUrl(sub_field_json.type)\n
.push(function (gadget_url) {\n
return gadget.declareGadget(gadget_url, {\n
element: element\n
});\n
})\n
.push(function (cell_gadget) {\n
gadget.props.cell_gadget_list.push(cell_gadget);\n
sub_field_json.editable = sub_field_json.editable && field_json.editable; // XXX \n
return cell_gadget.render({field_json: sub_field_json});\n
});\n
}\n
\n
dataset = result;\n
for (i = 0; i < counter; i += 1) {\n
tr = document.createElement("tr");\n
tmp_url = result_list[i + 1];\n
\n
for (j = 0; j < field_json.column_list.length; j += 1) {\n
th = document.createElement("th");\n
a = document.createElement("a");\n
a.href = tmp_url;\n
a.className = "ui-link";\n
a.textContent = (result.data.rows[i]\n
.value[field_json.column_list[j][0]] || "");\n
th.appendChild(a);\n
value = result.data.rows[i].value[field_json.column_list[j][0]] || "";\n
if (value.type === undefined) {\n
a = document.createElement("a");\n
a.href = tmp_url;\n
a.className = "ui-link";\n
a.textContent = value;\n
th.appendChild(a);\n
} else {\n
if (gadget.props.listbox_uid_dict.key === undefined) {\n
gadget.props.listbox_uid_dict.key = result.data.rows[i].value["listbox_uid:list"].key;\n
gadget.props.listbox_uid_dict.value = [result.data.rows[i].value["listbox_uid:list"].value];\n
uid_value_dict[result.data.rows[i].value["listbox_uid:list"].value] = null;\n
} else {\n
uid_value = result.data.rows[i].value["listbox_uid:list"].value;\n
if (!uid_value_dict.hasOwnProperty(uid_value)) {\n
uid_value_dict[uid_value] = null;\n
gadget.props.listbox_uid_dict.value.push(uid_value);\n
}\n
}\n
\n
promise_list.push(renderSubCell(th, value));\n
}\n
tr.appendChild(th);\n
}\n
tbody.appendChild(tr);\n
}\n
\n
return RSVP.all(promise_list);\n
}).push(function () {\n
var prev_param = {},\n
next_param = {};\n
......@@ -372,19 +409,56 @@
// NOTE: for passing translations, temp must contain a table\n
temp_table.appendChild(fragment);\n
temp.appendChild(temp_table);\n
return gadget.translateHtml(temp.innerHTML);\n
table.appendChild(temp.querySelector("tbody"));\n
return gadget.translateHtml(temp.querySelector("tfoot").innerHTML);\n
})\n
.push(function (my_translated_html) {\n
var new_body,\n
new_foot,\n
temp = document.createElement("div");\n
var temp = document.createElement("tfoot");\n
temp.innerHTML = my_translated_html;\n
new_body = temp.querySelector("tbody");\n
new_foot = temp.querySelector("tfoot");\n
table.appendChild(new_body);\n
table.appendChild(new_foot);\n
return gadget;\n
table.appendChild(temp);\n
});\n
})\n
\n
\n
.declareMethod("getContent", function () {\n
var form_gadget = this,\n
k,\n
field_gadget,\n
count = form_gadget.props.cell_gadget_list.length,\n
data = {},\n
queue = new RSVP.Queue();\n
\n
function extendData(field_data) {\n
var key;\n
for (key in field_data) {\n
if (field_data.hasOwnProperty(key)) {\n
data[key] = field_data[key];\n
}\n
}\n
}\n
\n
for (k = 0; k < count; k += 1) {\n
field_gadget = form_gadget.props.cell_gadget_list[k];\n
// XXX Hack until better defined\n
if (field_gadget.getContent !== undefined) {\n
queue\n
.push(field_gadget.getContent.bind(field_gadget))\n
.push(extendData);\n
}\n
}\n
return queue\n
.push(function () {\n
data[form_gadget.props.listbox_uid_dict.key] = form_gadget.props.listbox_uid_dict.value;\n
return data;\n
});\n
})\n
\n
.allowPublicAcquisition("notifyInvalid", function () {\n
return;\n
})\n
\n
.allowPublicAcquisition("notifyValid", function () {\n
return;\n
});\n
\n
}(window, document, rJS, URI, RSVP, UriTemplate));
......@@ -524,7 +598,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>941.55789.57588.57941</string> </value>
<value> <string>943.18213.25268.27562</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -542,7 +616,7 @@
</tuple>
<state>
<tuple>
<float>1427276913.09</float>
<float>1432652509.88</float>
<string>GMT</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