Commit 30ec359f authored by Roque's avatar Roque

erp5_officejs: moving json-form render method to a main gadget (controller for now)

parent 97b5c80f
......@@ -15,6 +15,73 @@
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getFormDefinition", function () {
//somehow the form_definition should come from the erp5-doc/form (jio?)
//for now, hardcoded form_definition for POST VIEW
return {
_debug: "traverse",
pt: "form_view",
title: "Post",
group_list: [[
"left",
[["my_title", {meta_type: "StringField"}]]
], [
"bottom",
[["my_text_content", {meta_type: "ProxyField"}]]
]],
//this field_info is totally made up, but somewhere in the definition there must be
//information about the fields. So, foreach field: key->info
field_info_dict: {
"my_title": {
"title": "Title",
"default": "Undefined title",
"editable": 1,
"key": "title",
"type": "StringField"
},
"my_text_content": {
"editable": 1,
"key": "text_content",
"renderjs_extra": '{"editor": "fck_editor",' +
'"maximize": true}',
"type": "GadgetField",
"url": "gadget_editor.html",
"sandbox": "public"
}
},
action: "Base_edit",
update_action: "",
_links: {}
};
})
.declareMethod("generateJsonRenderForm", function (form_definition, document) {
var form_json = {
erp5_document: {
"_embedded": {"_view": {}},
"_links": {}
},
form_definition: form_definition
};
for (var i = 0; i < form_definition.group_list.length; i++) {
var fields = form_definition.group_list[i][1];
for (var j = 0; j < fields.length; j++) {
var my_element = fields[j][0], element_id;
if (my_element.startsWith("my_")) {
element_id = my_element.replace("my_", "");
}
var field_info = form_definition.field_info_dict[my_element];
if (document && document.hasOwnProperty(element_id)) {
field_info["default"] = document[element_id];
}
form_json.erp5_document._embedded._view[my_element] = field_info;
form_json.erp5_document._links = form_definition._links;
}
}
return form_json;
})
.allowPublicAcquisition('notifySubmit', function () {
return this.triggerSubmit();
})
......@@ -41,10 +108,8 @@
.declareMethod("render", function (options) {
var gadget = this,
child_gadget_url;
return gadget.jio_get(options.jio_key)
.push(function (result) {
if (result.portal_type !== undefined) {
child_gadget_url = 'gadget_officejs_jio_' +
result.portal_type.replace(/ /g, '_').toLowerCase() +
......@@ -52,39 +117,48 @@
} else {
throw new Error('Can not display document: ' + options.jio_key);
}
return gadget.changeState({
jio_key: options.jio_key,
doc: result,
child_gadget_url: child_gadget_url
});
//somehow the form_definition should come from the erp5-doc/form (jio?)
return gadget.getFormDefinition(options.jio_key)
.push(function (form_definition) {
return gadget.changeState({
jio_key: options.jio_key,
doc: result,
child_gadget_url: child_gadget_url,
form_definition: form_definition
});
});
});
})
.onStateChange(function (modification_dict) {
var fragment = document.createElement('div'),
gadget = this;
if (!modification_dict.hasOwnProperty('child_gadget_url')) {
return gadget.getDeclaredGadget('fg')
.push(function (child_gadget) {
return child_gadget.render({
jio_key: gadget.state.jio_key,
doc: gadget.state.doc
});
});
}
// Clear first to DOM, append after to reduce flickering/manip
while (this.element.firstChild) {
this.element.removeChild(this.element.firstChild);
}
this.element.appendChild(fragment);
return gadget.generateJsonRenderForm(gadget.state.form_definition, gadget.state.doc)
.push(function (form_json) {
if (!modification_dict.hasOwnProperty('child_gadget_url')) {
return gadget.getDeclaredGadget('fg')
.push(function (child_gadget) {
return child_gadget.render({
jio_key: gadget.state.jio_key,
doc: gadget.state.doc,
form_json: form_json
});
});
}
// Clear first to DOM, append after to reduce flickering/manip
while (gadget.element.firstChild) {
gadget.element.removeChild(gadget.element.firstChild);
}
gadget.element.appendChild(fragment);
return gadget.declareGadget(gadget.state.child_gadget_url, {element: fragment,
scope: 'fg'})
.push(function (form_gadget) {
return form_gadget.render({
jio_key: gadget.state.jio_key,
doc: gadget.state.doc
});
return gadget.declareGadget(gadget.state.child_gadget_url, {element: fragment,
scope: 'fg'})
.push(function (form_gadget) {
return form_gadget.render({
jio_key: gadget.state.jio_key,
doc: gadget.state.doc,
form_json: form_json
});
});
});
});
......
......@@ -227,7 +227,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>967.6016.61211.59613</string> </value>
<value> <string>973.30677.12698.50312</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -245,7 +245,7 @@
</tuple>
<state>
<tuple>
<float>1524754712.51</float>
<float>1549379093.01</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -18,72 +18,11 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("generateJsonRenderForm", function (gadget) {
//hardcoded form_definition (this should come from erp5 form)
var form_definition = {
_debug: "traverse",
pt: "form_view",
title: "Post",
group_list: [[
"left",
[["my_title", {meta_type: "StringField"}]]
], [
"bottom",
[["my_text_content", {meta_type: "ProxyField"}]]
]],
//this field_info is totally made up, but somewhere in the definition there must be
//information about the fields. So, foreach field: key->info
field_info_dict: {
"my_title": {
"title": "Title",
"default": "Undefined title",
"editable": 1,
"key": "title",
"type": "StringField"
},
"my_text_content": {
"editable": 1,
"key": "text_content",
"renderjs_extra": '{"editor": "fck_editor",' +
'"maximize": true}',
"type": "GadgetField",
"url": "gadget_editor.html",
"sandbox": "public"
}
},
action: "Base_edit",
update_action: "",
_links: {}
},
form_json = {
erp5_document: {
"_embedded": {"_view": {}},
"_links": {}
},
form_definition: form_definition
};
for (var i = 0; i < form_definition.group_list.length; i++) {
var fields = form_definition.group_list[i][1];
for (var j = 0; j < fields.length; j++) {
var my_element = fields[j][0], element_id;
if (my_element.startsWith("my_")) {
element_id = my_element.replace("my_", "");
}
var field_info = form_definition.field_info_dict[my_element];
if (gadget.state.hasOwnProperty("doc") && gadget.state.doc.hasOwnProperty(element_id)) {
field_info["default"] = gadget.state.doc[element_id];
}
form_json.erp5_document._embedded._view[my_element] = field_info;
form_json.erp5_document._links = form_definition._links;
}
}
return form_json;
})
.declareMethod("render", function (options) {
return this.changeState({
jio_key: options.jio_key,
doc: options.doc
doc: options.doc,
form_json: options.form_json
});
})
......@@ -109,31 +48,26 @@
})
.onStateChange(function () {
var gadget = this,
form_json;
return gadget.generateJsonRenderForm(gadget)
.push(function (result) {
form_json = result;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render(form_json);
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: gadget.state.doc.title,
save_action: true,
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
});
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render(gadget.state.form_json);
})
.push(function () {
return RSVP.all([
gadget.getUrlFor({command: 'history_previous'}),
gadget.getUrlFor({command: 'selection_previous'}),
gadget.getUrlFor({command: 'selection_next'})
]);
})
.push(function (url_list) {
return gadget.updateHeader({
page_title: gadget.state.doc.title,
save_action: true,
selection_url: url_list[0],
previous_url: url_list[1],
next_url: url_list[2]
});
});
});
}(window, rJS, RSVP));
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>973.29142.36243.7697</string> </value>
<value> <string>973.30699.43343.35106</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1549285941.45</float>
<float>1549379311.18</float>
<string>UTC</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