Commit bfd06301 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Rewrite float field

parent 157c669d
...@@ -13,6 +13,5 @@ ...@@ -13,6 +13,5 @@
</head> </head>
<body> <body>
<input type='number' />
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -220,7 +220,7 @@ ...@@ -220,7 +220,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value> <value> <string>zope</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>940.63282.44183.51353</string> </value> <value> <string>954.34618.13218.7202</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>1423905795.16</float> <float>1476697790.84</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, RSVP, loopEventListener */ /*global window, rJS */
/*jslint indent: 2, maxerr: 3 */ /*jslint indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, loopEventListener) { (function (window, rJS) {
"use strict"; "use strict";
rJS(window) rJS(window)
.ready(function (gadget) { .setState({
return gadget.getElement() tag: 'p',
.push(function (element) { step: 1,
gadget.element = element; type: "number"
});
})
.declareAcquiredMethod("notifyValid", "notifyValid")
.declareAcquiredMethod("notifyInvalid", "notifyInvalid")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareMethod('getTextContent', function () {
return this.element.querySelector('input').getAttribute('value');
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var input = this.element.querySelector('input'), var field_json = options.field_json || {},
step = 0.00000001, state_dict = {
field_json = options.field_json || {}; value: field_json.value || field_json.default || "",
input.setAttribute( editable: field_json.editable,
'value', required: field_json.required,
field_json.value || field_json.default || "" name: field_json.key,
); title: field_json.title,
if (field_json.precision !== "") { precision: field_json.precision
step = 1 / Math.pow(10, field_json.precision); };
} state_dict.text_content = state_dict.value;
input.setAttribute("step", step); if (field_json.precision) {
input.setAttribute('name', field_json.key); state_dict.step = 1 / Math.pow(10, field_json.precision);
input.setAttribute('title', field_json.title); } else {
if (field_json.required === 1) { state_dict.step = 0.00000001;
input.setAttribute('required', 'required');
} }
if (field_json.editable !== 1) { return this.changeState(state_dict);
input.setAttribute('readonly', 'readonly'); })
input.setAttribute('data-wrapper-class', 'ui-state-disabled ui-state-readonly');
input.setAttribute('disabled', 'disabled');
.onStateChange(function (modification_dict) {
var element = this.element,
gadget = this,
url,
result;
if (modification_dict.hasOwnProperty('editable')) {
if (gadget.state.editable) {
url = 'gadget_html5_input.html';
} else {
url = 'gadget_html5_element.html';
}
result = this.declareGadget(url, {scope: 'sub'})
.push(function (input) {
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
element.appendChild(input.element);
return input;
});
} else {
result = this.getDeclaredGadget('sub');
} }
return result
.push(function (input) {
return input.render(gadget.state);
});
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
var input = this.element.querySelector('input'), if (this.state.editable) {
result = {}; return this.getDeclaredGadget('sub')
result[input.getAttribute('name')] = input.value; .push(function (gadget) {
return result; return gadget.getContent();
})
.declareMethod('checkValidity', function () {
var result;
result = this.element.querySelector('input').checkValidity();
if (result) {
return this.notifyValid()
.push(function () {
return result;
}); });
} }
return result; return {};
}) })
.declareService(function () { .declareMethod('getTextContent', function () {
//////////////////////////////////// return this.getDeclaredGadget('sub')
// Check field validity when the value changes .push(function (gadget) {
//////////////////////////////////// return gadget.getTextContent();
var field_gadget = this; });
function notifyChange() {
return RSVP.all([
field_gadget.checkValidity(),
field_gadget.notifyChange()
]);
}
// Listen to input change
return loopEventListener(
field_gadget.element.querySelector('input'),
'change',
false,
notifyChange
);
}) })
.declareService(function () { .declareMethod('checkValidity', function () {
//////////////////////////////////// if (this.state.editable) {
// Inform when the field input is invalid return this.getDeclaredGadget('sub')
//////////////////////////////////// .push(function (gadget) {
var field_gadget = this; return gadget.checkValidity();
});
function notifyInvalid(evt) {
return field_gadget.notifyInvalid(evt.target.validationMessage);
} }
return true;
// Listen to input change
return loopEventListener(
field_gadget.element.querySelector('input'),
'invalid',
false,
notifyInvalid
);
}); });
}(window, rJS, RSVP, loopEventListener)); }(window, rJS));
\ No newline at end of file \ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>949.15478.31551.48810</string> </value> <value> <string>954.34618.13218.7202</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>1455899205.51</float> <float>1476698259.52</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