Commit 617f79f6 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web_renderjs_ui: allow relation string field to create item and clean input after submit

The idea to clean input after submit:
in pt form view editable gadget, after submit, it will check if there has a field which
should regenerate, if yes, it will ask it's parent gadget to provide new erp5 site info,
then use it to regenerate sub field
parent e5ce5ae6
......@@ -218,8 +218,7 @@ def renderField(field, form_relative_url, meta_type=None, key=None):\n
"query": query,\n
"catalog_index": field.get_value(\'catalog_index\'),\n
"allow_jump": field.get_value(\'allow_jump\'),\n
# "allow_creation": field.get_value(\'allow_creation\'),\n
"allow_creation": 0,\n
"allow_creation": field.get_value(\'allow_creation\'),\n
"type": meta_type,\n
"key": key,\n
"editable": field.get_value("editable"),\n
......
......@@ -339,8 +339,87 @@
return data;\n
});\n
})\n
.declareMethod("refresh", function (options) {\n
var form_gadget = this,\n
j,\n
i,\n
index = 0,\n
erp5_document = options.erp5_document,\n
form_definition = options.form_definition,\n
rendered_form = erp5_document._embedded._view,\n
group_list = form_definition.group_list,\n
refresh_queue = new RSVP.Queue(),\n
suboption_dict = {},\n
suboptions,\n
renderered_field,\n
field,\n
refresh_list = this.props.refresh_list;\n
delete options.erp5_document;\n
delete options.form_definition;\n
\n
form_gadget.state_parameter_dict = options.form_gadget || {};\n
// XXX Hardcoded for searchfield - remove later!\n
if (form_definition.extended_search) {\n
suboption_dict.extended_search = form_definition.extended_search;\n
}\n
\n
function refresh_gadget(options, gadget_index) {\n
if (form_gadget.props.gadget_list[gadget_index].refresh !== undefined) {\n
refresh_queue.push(function () {\n
return form_gadget.props.gadget_list[gadget_index].refresh(options);\n
});\n
}\n
}\n
for (i = 0; i < group_list.length; i += 1) {\n
for (j = 0; j < group_list[i][1].length; j += 1) {\n
field = group_list[i][1][j];\n
if (rendered_form.hasOwnProperty(field[0])) {\n
if (refresh_list[index]) {\n
renderered_field = rendered_form[field[0]];\n
suboptions = options[renderered_field.key] || suboption_dict;\n
suboptions.field_json = renderered_field;\n
refresh_gadget(suboptions, index);\n
}\n
index += 1;\n
}\n
}\n
}\n
return refresh_queue;\n
})\n
.declareMethod("checkRefresh", function () {\n
var form_gadget = this,\n
k,\n
field_gadget,\n
count = form_gadget.props.gadget_list.length,\n
result = false,\n
refresh_list = [],\n
queue = new RSVP.Queue();\n
function extendData(needToRefresh) {\n
result = result || needToRefresh;\n
refresh_list[refresh_list.length] = needToRefresh;\n
}\n
function dontNeedToRefresh() {\n
return false;\n
}\n
for (k = 0; k < count; k += 1) {\n
field_gadget = form_gadget.props.gadget_list[k];\n
// XXX Hack until better defined\n
if (field_gadget.checkRefresh !== undefined) {\n
queue\n
.push(field_gadget.checkRefresh.bind(field_gadget));\n
} else {\n
queue\n
.push(dontNeedToRefresh);\n
}\n
queue.push(extendData);\n
}\n
return queue\n
.push(function () {\n
form_gadget.props.refresh_list = refresh_list;\n
return result;\n
});\n
\n
})\n
.declareMethod("checkValidity", function () {\n
var form_gadget = this,\n
k,\n
......@@ -506,7 +585,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>943.18226.40997.54510</string> </value>
<value> <string>942.57027.49275.7236</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -524,8 +603,8 @@
</tuple>
<state>
<tuple>
<float>1432653451.85</float>
<string>GMT</string>
<float>1431049784.59</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -135,6 +135,7 @@
.declareAcquiredMethod("renderPageHeader", "renderPageHeader")\n
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")\n
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")\n
.declareAcquiredMethod("pleaseRefreshFields", "pleaseRefreshFields")\n
\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
......@@ -193,6 +194,18 @@
});\n
});\n
})\n
.declareMethod(\'refresh\', function (options) {\n
return this.getDeclaredGadget("erp5_form")\n
.push(function (erp5_form) {\n
var form_options = options.erp5_form || {};\n
\n
form_options.erp5_document = options.erp5_document;\n
form_options.form_definition = options.form_definition;\n
form_options.view = options.view;\n
\n
return erp5_form.refresh(form_options);\n
});\n
})\n
\n
\n
.declareService(function () {\n
......@@ -202,13 +215,20 @@
var form_gadget = this;\n
\n
function formSubmit() {\n
var erp5_form;\n
var erp5_form,\n
validity,\n
need_to_refresh;\n
return form_gadget.getDeclaredGadget("erp5_form")\n
.push(function (gadget) {\n
erp5_form = gadget;\n
return erp5_form.checkValidity();\n
return RSVP.all([\n
erp5_form.checkValidity(),\n
erp5_form.checkRefresh()\n
]);\n
})\n
.push(function (validity) {\n
.push(function (result) {\n
validity = result[0];\n
need_to_refresh = result[1];\n
if (validity) {\n
return erp5_form.getContent()\n
.push(function (data) {\n
......@@ -225,6 +245,11 @@
})\n
]);\n
})\n
.push(function () {\n
if (need_to_refresh) {\n
return form_gadget.pleaseRefreshFields();\n
}\n
})\n
.push(form_gadget.notifySubmitted.bind(form_gadget));\n
}\n
});\n
......@@ -360,7 +385,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>xiaowu</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -374,7 +399,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.49289.61084.65194</string> </value>
<value> <string>942.56412.30506.44083</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -392,8 +417,8 @@
</tuple>
<state>
<tuple>
<float>1423215734.45</float>
<string>GMT</string>
<float>1431046040.15</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -128,7 +128,29 @@
// Acquired methods\n
/////////////////////////////////////////////////////////////////\n
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")\n
\n
.allowPublicAcquisition("pleaseRefreshFields", function () {\n
var gadget = this,\n
options = this.props.options,\n
erp5_document,\n
form_gadget = this.props.form_gadget;\n
return gadget.jio_getAttachment({"_id": options.jio_key, "_attachment": options.view})\n
.push(function (result) {\n
var uri = new URI(result.data._embedded._view._links.form_definition.href);\n
erp5_document = result.data;\n
return gadget.jio_getAttachment({"_id": uri.segment(2), "_attachment": "view"});\n
})\n
.push(function (result) {\n
var new_options;\n
new_options = options.fg || {};\n
new_options.erp5_document = erp5_document;\n
new_options.form_definition = result.data;\n
new_options.view = options.view;\n
new_options.action_view = options.action_view;\n
new_options.jio_key = options.jio_key;\n
new_options.editable = options.editable;\n
return form_gadget.refresh(new_options);\n
});\n
})\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
/////////////////////////////////////////////////////////////////\n
......@@ -144,7 +166,7 @@
erp5_document,\n
erp5_form,\n
form_gadget;\n
\n
gadget.props.options = options;\n
return gadget.jio_getAttachment({"_id": options.jio_key, "_attachment": options.view})\n
.push(function (result) {\n
var uri = new URI(result.data._embedded._view._links.form_definition.href);\n
......@@ -173,7 +195,7 @@
sub_options.action_view = options.action_view;\n
sub_options.jio_key = options.jio_key;\n
sub_options.editable = options.editable;\n
\n
gadget.props.form_gadget = result;\n
form_gadget = result;\n
return form_gadget.render(sub_options);\n
})\n
......@@ -312,7 +334,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>xiaowu</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -326,7 +348,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.49122.12001.41540</string> </value>
<value> <string>942.55908.31920.60569</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -344,8 +366,8 @@
</tuple>
<state>
<tuple>
<float>1423065965.58</float>
<string>GMT</string>
<float>1431045870.59</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
......@@ -322,6 +322,7 @@ promiseEventListener */\n
// show "new" tag, clicking it will remove it and reset the field!\n
// XXX Not active - reset should be handled by a generic reset method!\n
if (no_results && field_json.allow_creation) {\n
props.need_to_refresh = true;\n
return new RSVP.Queue()\n
.push(function () {\n
props.wrapper.appendChild(createNewTag(my_gadget));\n
......@@ -347,9 +348,9 @@ promiseEventListener */\n
tag_list = wrapper.querySelector(".ui-tag-list");\n
tag_list.parentNode.removeChild(tag_list);\n
return setRelationJump(my_gadget, undefined);\n
})\n
});\n
}\n
\n
props.need_to_refresh = false;\n
// default autocomplete\n
return new RSVP.Queue()\n
.push(function () {\n
......@@ -398,6 +399,7 @@ promiseEventListener */\n
// Init local properties\n
.ready(function (my_gadget) {\n
my_gadget.property_dict = {};\n
my_gadget.property_dict.need_to_refresh = false;\n
})\n
\n
.ready(function (my_gadget) {\n
......@@ -472,10 +474,22 @@ promiseEventListener */\n
result[this.property_dict.field_json.relation_field_id] =\n
this.property_dict.selected_uid;\n
}\n
\n
return result;\n
})\n
\n
.declareMethod(\'refresh\', function (options) {\n
var wrapper = this.property_dict.wrapper,\n
tag_list;\n
tag_list = wrapper.querySelector(".ui-tag-list");\n
if (tag_list !== null) {\n
tag_list.parentNode.removeChild(tag_list);\n
}\n
return this.render(options);\n
})\n
.declareMethod(\'checkRefresh\', function () {\n
var tmp = this.property_dict.need_to_refresh;\n
this.property_dict.need_to_refresh = false;\n
return tmp;\n
})\n
.declareMethod(\'checkValidity\', function () {\n
var result;\n
result = (this.element.querySelector(\'input\').checkValidity()) &&\n
......@@ -606,11 +620,11 @@ promiseEventListener */\n
- OK reimplement setting link without calling allDocs\n
- on small displays JQM will toggle headers, find way to prevent!\n
- fix broken promise chain\n
- test\n
- ok test\n
- keyboard speed test\n
- add generic text and translations\n
- do multiRelationfield\n
- find way to digest response of erp5? submit should clean input\n
- ok find way to digest response of erp5? submit should clean input\n
- add column_list parameter to pass more than title = "John Smith", render?\n
\n
\n
......@@ -739,7 +753,7 @@ promiseEventListener */\n
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>xiaowu</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -753,7 +767,7 @@ promiseEventListener */\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>941.1041.20854.22596</string> </value>
<value> <string>942.57468.41646.29286</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -771,8 +785,8 @@ promiseEventListener */\n
</tuple>
<state>
<tuple>
<float>1424104195.48</float>
<string>GMT</string>
<float>1431075656.16</float>
<string>UTC</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