Commit 8f9a20c6 authored by Romain Courteaud's avatar Romain Courteaud

INTERACTION experimentation with hardcoded form/field update

parent 3588e8f7
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
.setState({ .setState({
// erp5 document is an instance of a document referenced by jio_key // erp5 document is an instance of a document referenced by jio_key
erp5_document: undefined, erp5_document_json: undefined,
jio_key: undefined, jio_key: undefined,
// form definition holds positioning of fields // form definition holds positioning of fields
form_definition: undefined, form_definition: undefined,
...@@ -156,7 +156,7 @@ ...@@ -156,7 +156,7 @@
} }
return this.changeState({ return this.changeState({
erp5_document: options.erp5_document, erp5_document_json: JSON.stringify(options.erp5_document),
form_definition: options.form_definition, form_definition: options.form_definition,
jio_key: options.jio_key, jio_key: options.jio_key,
hash: hash, hash: hash,
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
}) })
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
var erp5_document = this.state.erp5_document, var erp5_document = JSON.parse(this.state.erp5_document_json),
form_definition = this.state.form_definition, form_definition = this.state.form_definition,
rendered_document = erp5_document._embedded._view, rendered_document = erp5_document._embedded._view,
group_list = form_definition.group_list, group_list = form_definition.group_list,
...@@ -286,6 +286,77 @@ ...@@ -286,6 +286,77 @@
return result; return result;
}); });
}, {mutex: 'changestate'}); }, {mutex: 'changestate'})
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareJob("updateForm", function () {
var context = this;
return new RSVP.Queue()
.push(function () {
return RSVP.delay(50);
})
.push(function () {
return context.getContent();
})
.push(function (content) {
var quantity = content.field_my_quantity,
title = 'foo ' + quantity + ' title',
erp5_document = JSON.parse(context.state.erp5_document_json);
// console.log(context.state);
erp5_document._embedded._view.my_title.default = title;
return context.changeState({
erp5_document_json: JSON.stringify(erp5_document)
});
});
})
/*
.declareJob("updateHeader", function (param_list) {
var context = this;
return new RSVP.Queue()
.push(function () {
return RSVP.delay(200);
})
.push(function () {
return context.notifyChange.call(context, param_list);
});
})
*/
/* can do any declarative
add a gadget in the page. Gadget "not rendered", ie no label, no dom
gadget call erp5_form.addInteraction('field_my_quantity', 'notifyChange')
problem: impossible from JS to hardcode this field key (formulator can change)
should notifyChange provides the getContent value of the field?
should the form check the subgadget scope OR the getContent field key
scope is no guarantee to be as the field key
developper doesn't know anything also about formulator key generation algorithm (black box)
shoud the update field
how to dynamically add/remove on field
how to render only the needed field?
listbox: how not to reload the lines? how to reload the lines on demand?
*/
.allowPublicAcquisition("notifyChange", function (param_list, scope) {
// Trigger update field if needed
var context = this;
if (scope === 'field_my_quantity') {
context.updateForm();
}
// return context.updateHeader(param_list);
return context.notifyChange.call(context, param_list);
/*
return this.getContent()
.push(function (content) {
console.log(scope, content);
return context.notifyChange.call(context, param_list);
});
*/
});
}(window, document, rJS, RSVP)); }(window, document, rJS, RSVP));
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>964.58561.19908.14080</string> </value> <value> <string>964.50178.15987.24217</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1516274548.88</float> <float>1515763409.77</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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