Commit 016684f2 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui] FloatField and Input uses render() to complete state change

parent 721fcfee
...@@ -4,37 +4,30 @@ ...@@ -4,37 +4,30 @@
"use strict"; "use strict";
rJS(window) rJS(window)
.setState({
type: "number",
// `step` is used for browser-level validation thus a mandatory value
// HTML5 default is 1.0 which is not feasible most of the time thus we
// default to over-sufficiently small value
step: 0.00000001,
required: false,
editable: true,
hidden: false,
name: undefined,
title: undefined,
value: undefined,
text_content: undefined,
// `append` is a string to display next to the field (%, currency...)
append: undefined
})
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var field_json = options.field_json || {}, var field_json = options.field_json || {},
percentage = (field_json.input_style || "").endsWith("%"), percentage = (field_json.input_style || "").endsWith("%"),
state_dict = { state_dict = {
type: "number",
editable: field_json.editable, editable: field_json.editable,
required: field_json.required, required: field_json.required,
hidden: field_json.hidden,
name: field_json.key, name: field_json.key,
title: field_json.title, title: field_json.title,
precision: window.parseFloat(field_json.precision), precision: window.parseFloat(field_json.precision),
hidden: field_json.hidden, // erp5 always put value into "default" (never "value")
// erp5 always put value into "default" value: window.parseFloat(field_json.default),
value: window.parseFloat(field_json.default) text_content: '',
// `step` is used for browser-level validation thus a mandatory value
// HTML5 default is 1.0 which is not feasible most of the time thus we
// default to over-sufficiently small value
step: 0.00000001,
// `append` is a string to display next to the field ("%", "EUR"...)
append: ''
}; };
if (!window.isNaN(state_dict.value)) {
state_dict.text_content = state_dict.value.toString();
}
if (!window.isNaN(state_dict.precision)) { if (!window.isNaN(state_dict.precision)) {
state_dict.step = Math.pow(10, -state_dict.precision); state_dict.step = Math.pow(10, -state_dict.precision);
state_dict.value = state_dict.value.toFixed(state_dict.precision); state_dict.value = state_dict.value.toFixed(state_dict.precision);
...@@ -46,11 +39,6 @@ ...@@ -46,11 +39,6 @@
state_dict.append = "%"; state_dict.append = "%";
} }
if (window.isNaN(state_dict.value)) {
state_dict.text_content = ""; // show empty value insted of ugly "NaN"
} else {
state_dict.text_content = state_dict.value.toString();
}
return this.changeState(state_dict); return this.changeState(state_dict);
}) })
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.12584.16558.54920</string> </value> <value> <string>962.12588.2416.8721</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>1505816402.11</float> <float>1505921992.31</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -15,20 +15,6 @@ ...@@ -15,20 +15,6 @@
} }
rJS(window) rJS(window)
.setState({
editable: false,
value: undefined,
checked: undefined,
hidden: false,
title: '',
name: '',
type: 'text',
required: false, // mandatory field
trim: false, // trim content for spaces
focus: undefined, // has focus by default
prepend: undefined, // text to prepend infront the field
append: undefined // text to apend after the field
})
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
return this.changeState({ return this.changeState({
...@@ -44,8 +30,8 @@ ...@@ -44,8 +30,8 @@
step: options.step, step: options.step,
hidden: options.hidden, hidden: options.hidden,
trim: options.trim || false, trim: options.trim || false,
append: options.append, append: options.append, // text to apend after the field
prepend: options.prepend prepend: options.prepend // text to prepend infront the field
}); });
}) })
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.13886.9310.48640</string> </value> <value> <string>962.13897.43577.15308</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>1505894979.84</float> <float>1505922105.23</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