Commit edffaef2 authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_renderjs_ui: add support for LinkField

parent 0a48b4c6
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
field_url = 'gadget_erp5_field_string.html'; field_url = 'gadget_erp5_field_string.html';
} else if (field_type === 'HyperLinkField') { } else if (field_type === 'HyperLinkField') {
field_url = 'gadget_erp5_field_hyperlink.html'; field_url = 'gadget_erp5_field_hyperlink.html';
} else if (field_type === 'LinkField') {
field_url = 'gadget_erp5_field_link.html';
} else if (field_type === 'LinesField') { } else if (field_type === 'LinesField') {
field_url = 'gadget_erp5_field_lines.html'; field_url = 'gadget_erp5_field_lines.html';
} else if (field_type === 'PasswordField') { } else if (field_type === 'PasswordField') {
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.16240.14459.45960</string> </value> <value> <string>989.58905.49586.62361</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1602525354.74</float> <float>1614349412.76</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>ERP5 Link field</title>
<link rel="http://www.renderjs.org/rel/interface" href="interface_erp5_field.html">
<link rel="http://www.renderjs.org/rel/interface" href="interface_erp5_form_content_provider.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_erp5_field_link.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*global window, document, rJS */
/*jslint indent: 2, maxerr: 3 */
(function (window, document, rJS) {
"use strict";
rJS(window)
.setState({
tag: 'a'
})
.declareMethod('render', function (options) {
var field_json = options.field_json || {},
state_dict = {
value: field_json.value || field_json.default || "",
editable: field_json.editable,
required: field_json.required,
id: field_json.key,
name: field_json.key,
error_text: field_json.error_text,
title: field_json.description,
label: field_json.title,
hidden: field_json.hidden,
trim: true,
// Force calling subfield render
// as user may have modified the input value
render_timestamp: new Date().getTime()
};
return this.changeState(state_dict);
})
.onStateChange(function (modification_dict) {
var element = this.element,
gadget = this,
url,
result,
new_div;
if (modification_dict.hasOwnProperty('editable')) {
if (gadget.state.editable) {
url = 'gadget_html5_input.html';
} else {
url = 'gadget_html5_element.html';
}
while (element.firstChild) {
element.removeChild(element.firstChild);
}
new_div = document.createElement('div');
element.appendChild(new_div);
result = this.declareGadget(url, {scope: 'sub', element: new_div});
} else {
result = this.getDeclaredGadget('sub');
}
return result
.push(function (input) {
var state;
if (gadget.state.editable) {
state = gadget.state;
} else {
state = {
tag: 'a',
href: gadget.state.value,
text_content: gadget.state.label
};
}
return input.render(state);
});
})
/** Return content even for non-editable cells - be backward compatible! */
.declareMethod('getContent', function () {
if (this.state.editable) {
return this.getDeclaredGadget('sub')
.push(function (gadget) {
return gadget.getContent();
});
}
return {};
}, {mutex: 'changestate'})
.declareMethod('checkValidity', function () {
if (this.state.editable) {
return this.getDeclaredGadget('sub')
.push(function (gadget) {
return gadget.checkValidity();
});
}
return true;
}, {mutex: 'changestate'});
}(window, document, rJS));
\ No newline at end of file
...@@ -43,6 +43,8 @@ url_list = [ ...@@ -43,6 +43,8 @@ url_list = [
'gadget_erp5_field_list.js', 'gadget_erp5_field_list.js',
'gadget_erp5_field_lines.html', 'gadget_erp5_field_lines.html',
'gadget_erp5_field_lines.js', 'gadget_erp5_field_lines.js',
'gadget_erp5_field_link.html',
'gadget_erp5_field_link.js',
'gadget_erp5_field_listbox.html', 'gadget_erp5_field_listbox.html',
'gadget_erp5_field_listbox.js', 'gadget_erp5_field_listbox.js',
'gadget_erp5_field_matrixbox.html', 'gadget_erp5_field_matrixbox.html',
......
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