Commit ae43dea9 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Rewrite relation field

Support calling render method multiple times.
parent d46f9de9
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.33012.29157.25361</string> </value>
<value> <string>954.57674.49472.38673</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1468331865.64</float>
<float>1477584183.47</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Relationstringfield</title>
<title>ERP5 Relation Input</title>
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
......@@ -18,9 +18,9 @@
</script>
<script id="relation-input-template" type="text/x-handlebars-template">
<div class="relation-input ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset ui-input-has-clear ui-input-has-icon {{readonly}}">
<div class="relation-input ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset ui-input-has-clear ui-input-has-icon">
<div>
<input type='search' title="{{title}}" name="{{name}}" autocomplete="off" {{{input_readonly}}} data-enhanced="true" value="{{value}}" >
<input type='search' title="{{title}}" name="{{name}}" autocomplete="off" data-enhanced="true" value="{{value}}" >
<ul class="ui-listview ui-corner-all search_ul"></ul>
</div>
<a href={{href}} tabindex="-1" class="{{class_name}}" >Jump to this document</a>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>954.54399.20164.63317</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1476956228.04</float>
<float>1477475951.1</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>953.41070.65129.47718</string> </value>
<value> <string>954.57692.7289.25070</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1472800801.64</float>
<float>1477583820.22</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint indent: 2, maxerr: 3, nomen: true */
/*jslint indent: 2, maxerr: 3, nomen: true, maxlen: 80 */
/*global window, rJS */
(function (window, rJS) {
"use strict";
rJS(window)
.allowPublicAcquisition("addRelationInput", function () {
return;
})
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod('render', function (options) {
var gadget = this,
field_json = options.field_json || {};
return this.getDeclaredGadget("relation_input")
.push(function (gadget) {
return gadget.render(options, {index: 0});
var render_options = {
editable: field_json.editable,
query: field_json.query,
catalog_index: field_json.catalog_index,
allow_jump: field_json.allow_jump,
// required: field_json.required,
title: field_json.title,
key: field_json.key,
view: field_json.view,
url: field_json.url,
allow_creation: field_json.allow_creation,
portal_types: field_json.portal_types,
value_relative_url: field_json.relation_item_relative_url[0],
relation_index: 0
};
if (field_json.default.hasOwnProperty('value_text_list')) {
//load non saved value
render_options.value_relative_url =
field_json.default.value_relative_url_list[0];
render_options.value_uid =
field_json.default.value_uid_list[0];
render_options.value_text =
field_json.default.value_text_list[0];
render_options.value_portal_type =
field_json.default.value_portal_type_list[0];
} else {
render_options.value_text = field_json.default[0] || "";
}
return gadget.render(render_options);
})
.push(function () {
return gadget.changeState({
key: options.field_json.key,
relation_field_id: options.field_json.relation_field_id
});
});
})
.declareMethod('getContent', function (options) {
var gadget = this;
return this.getDeclaredGadget("relation_input")
.push(function (gadget) {
return gadget.getContent(options);
.push(function (input_gadget) {
return input_gadget.getContent();
})
.push(function (input_result) {
var result = {};
if (!input_result.hasOwnProperty('value_text')) {
return result;
}
if (options.format === "erp5") {
if (input_result.value_portal_type) {
result[gadget.state.relation_field_id] =
"_newContent_" + input_result.value_portal_type;
}
result[gadget.state.key] = input_result.value_text;
} else {
result[gadget.state.key] = {
value_text_list: [input_result.value_text],
value_relative_url_list: [input_result.value_relative_url],
value_portal_type_list: [input_result.value_portal_type],
value_uid_list: [undefined]
};
}
return result;
});
});
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>954.57675.64427.52462</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1477037965.54</float>
<float>1477582815.99</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -446,7 +446,7 @@
function execHistoryPreviousCommand(gadget, previous_options, load_options) {
var history = previous_options.history,
jio_key = previous_options.jio_key,
target_index = previous_options.target_index,
relation_index = previous_options.relation_index,
field = previous_options.back_field,
queue = new RSVP.Queue(),
previous_id;
......@@ -473,9 +473,9 @@
if (results) {
results = JSON.parse(results.target.result);
if (load_options.uid) {
results[field].value[target_index] = "";
results[field].relation_item_relative_url[target_index] = load_options.jio_key;
results[field].uid = load_options.uid;
results[field].value_text_list[relation_index] = "";
results[field].value_relative_url_list[relation_index] = load_options.jio_key;
results[field].value_uid_list[relation_index] = load_options.uid;
}
gadget.props.form_content = results;
}
......@@ -491,8 +491,8 @@
return gadget.props.jio_gadget.get(history.options_id);
})
.push(function (result) {
var result_list = [result, previous_id];
var options = result_list[0].data,
var result_list = [result, previous_id],
options = result_list[0].data,
next_jio_key = options.jio_key;
delete options.jio_key;
return addNavigationHistoryAndDisplay(gadget, next_jio_key, options);
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.47260.43395.7014</string> </value>
<value> <string>954.57620.63396.46779</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1476957907.92</float>
<float>1477580291.06</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