Commit c4b496d0 authored by Ivan Tyagov's avatar Ivan Tyagov

Allow client side to specify how it want server to return listbox field - i.e....

Allow client side to specify how it want server to return listbox field - i.e. it can be rendered locally or rendered entirely server side.
parent 60cda24d
...@@ -97,11 +97,16 @@ for field_id in form.get_field_ids():\n ...@@ -97,11 +97,16 @@ for field_id in form.get_field_ids():\n
# listbox\n # listbox\n
if field_meta_type in ["ListBox"]:\n if field_meta_type in ["ListBox"]:\n
field_dict[\'listbox\'] = {}\n field_dict[\'listbox\'] = {}\n
# disabled as now we pass entire listbox html\n if render_client_side_listbox:\n
#field_dict[\'listbox\'][\'lines\'] = original_field.get_value("lines")\n # client side can request its javascript representation so it can generate it using jqgrid\n
#field_dict[\'listbox\'][\'columns\'] = [x for x in original_field.get_value("columns")]\n # or ask server generate its entire HTML\n
#field_dict[\'listbox\'][\'listbox_data_url\'] = "Listbox_asJSON"\n field_dict[\'type\'] = \'ListBoxJavaScript\'\n
field_dict[\'listbox\'][\'listbox_html\'] = original_field.render()\n field_dict[\'listbox\'][\'lines\'] = original_field.get_value("lines")\n
field_dict[\'listbox\'][\'columns\'] = [x for x in original_field.get_value("columns")]\n
field_dict[\'listbox\'][\'listbox_data_url\'] = "Listbox_asJSON"\n
else:\n
# server generates entire HTML\n
field_dict[\'listbox\'][\'listbox_html\'] = original_field.render()\n
\n \n
if field_meta_type in LIST_FIELDS:\n if field_meta_type in LIST_FIELDS:\n
# form contains selects, pass list of selects\' values and calculate default one?\n # form contains selects, pass list of selects\' values and calculate default one?\n
...@@ -124,7 +129,7 @@ return dumps(result)\n ...@@ -124,7 +129,7 @@ return dumps(result)\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id=None</string> </value> <value> <string>form_id=None, render_client_side_listbox=0</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -41,8 +41,10 @@ ...@@ -41,8 +41,10 @@
<value> <unicode encoding="cdata"><![CDATA[ <value> <unicode encoding="cdata"><![CDATA[
<tal:block tal:define="field_name request/field_name | options/field_name">\n <tal:block tal:define="field_name request/field_name | options/field_name">\n
<div tal:attributes="id field_name">\n <div tal:attributes="id string:${field_name}_field">\n
<!-- Listbox content -->\n <!-- Listbox content -->\n
<table tal:attributes="id string:${field_name}">\n
</table>\n
</div>\n </div>\n
<div tal:attributes="id string:${field_name}_pager">\n <div tal:attributes="id string:${field_name}_pager">\n
<!-- Listbox navigation -->\n <!-- Listbox navigation -->\n
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_EtagSupport__etag</string> </key> <key> <string>_EtagSupport__etag</string> </key>
<value> <string>ts63188257.39</string> </value> <value> <string>ts63249775.51</string> </value>
</item> </item>
<item> <item>
<key> <string>__name__</string> </key> <key> <string>__name__</string> </key>
...@@ -217,51 +217,65 @@ var ERP5Form = ( function () {\n ...@@ -217,51 +217,65 @@ var ERP5Form = ( function () {\n
},\n },\n
\n \n
ListBox: function (field_id, field_dict) {\n ListBox: function (field_id, field_dict) {\n
/* Listbox field */\n /*\n
* Listbox field rendered at server\n
*/\n
var listbox_id, navigation_id, listbox_table, current_form_id, listbox_dict,\n var listbox_id, navigation_id, listbox_table, current_form_id, listbox_dict,\n
listbox_data_url, colModel, column_title_list;\n listbox_data_url, colModel, column_title_list;\n
listbox_id = "field_" + field_id;\n listbox_id = "field_" + field_id;\n
navigation_id = listbox_id + "_pager";\n navigation_id = listbox_id + "_pager";\n
listbox_table = $("#"+listbox_id);\n listbox_table = $("#"+listbox_id + "_table");\n
current_form_id = this.getCurrentFormId();\n current_form_id = this.getCurrentFormId();\n
listbox_dict = field_dict.listbox;\n
listbox_data_url = listbox_dict.listbox_data_url;\n
$("#" + listbox_id + "_field").html(listbox_dict["listbox_html"]);\n
return\n
},\n
\n \n
ListBoxJavaScript: function (field_id, field_dict) {\n
/*\n
* Listbox field rendered entirely at client side using jqgrid plugin\n
*/\n
var listbox_id, navigation_id, listbox_table, current_form_id, listbox_dict,\n
listbox_data_url, colModel, column_title_list;\n
listbox_id = "field_" + field_id;\n
navigation_id = listbox_id + "_pager";\n
listbox_table = $("#"+listbox_id);\n
current_form_id = this.getCurrentFormId();\n
listbox_dict = field_dict.listbox;\n listbox_dict = field_dict.listbox;\n
listbox_data_url = listbox_dict.listbox_data_url;\n listbox_data_url = listbox_dict.listbox_data_url;\n
$("#" + listbox_id).html(listbox_dict["listbox_html"]);\n colModel = [];\n
return;\n column_title_list = [];\n
// Uncomment below to use jqgrid plugin to render listbox\n $.each(listbox_dict.columns,\n
// colModel = [];\n function(i, value){\n
// column_title_list = [];\n var index, title, column;\n
// $.each(listbox_dict.columns,\n index = value[0];\n
// function(i, value){\n title = value[1];\n
// var index, title, column;\n column_title_list.push(title);\n
// index = value[0];\n column = {\'name\': index,\n
// title = value[1];\n \'index\': index,\n
// column_title_list.push(title);\n \'width\': 185,\n
// column = {\'name\': index,\n \'align\': \'left\'};\n
// \'index\': index,\n colModel.push(column);\n
// \'width\': 185,\n });\n
// \'align\': \'left\'};\n \n
// colModel.push(column);\n listbox_table.jqGrid({url:listbox_data_url + \'?form_id=\' + current_form_id + \'&amps;listbox_id=\' + field_id,\n
// });\n datatype: "json",\n
// \n colNames: column_title_list,\n
// listbox_table.jqGrid({url:listbox_data_url + \'?form_id=\' + current_form_id + \'&amps;listbox_id=\' + field_id,\n colModel: colModel,\n
// datatype: "json",\n rowNum: listbox_dict.lines,\n
// colNames: column_title_list,\n pager: \'#\'+navigation_id,\n
// colModel: colModel,\n sortname: \'id\',\n
// rowNum: listbox_dict.lines,\n viewrecords: true,\n
// pager: \'#\'+navigation_id,\n sortorder: "desc",\n
// sortname: \'id\',\n loadError : function(xhr, textStatus, errorThrown) {\n
// viewrecords: true,\n // XXX: handle better than just alert.\n
// sortorder: "desc",\n alert("Error occurred during getting data from server.");\n
// loadError : function(xhr, textStatus, errorThrown) {\n },\n
// // XXX: handle better than just alert.\n cmTemplate: {sortable:false}, // XXX: until we get list of sortable columns from server\n
// alert("Error occurred during getting data from server.");\n caption: field_dict.title});\n
// },\n listbox_table.jqGrid(\'navGrid\', \'#\'+navigation_id, {edit:false,add:false,del:false});\n
// cmTemplate: {sortable:false}, // XXX: until we get list of sortable columns from server\n return listbox_table;\n
// caption: field_dict.title});\n
// listbox_table.jqGrid(\'navGrid\', \'#\'+navigation_id, {edit:false,add:false,del:false});\n
// return listbox_table;\n
},\n },\n
\n \n
update: function(data) {\n update: function(data) {\n
...@@ -437,7 +451,7 @@ var ERP5Form = ( function () {\n ...@@ -437,7 +451,7 @@ var ERP5Form = ( function () {\n
</item> </item>
<item> <item>
<key> <string>size</string> </key> <key> <string>size</string> </key>
<value> <int>19948</int> </value> <value> <int>20620</int> </value>
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
......
19 20
\ No newline at end of file \ No newline at end of file
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