Commit 157c669d authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Rewrite integer field

parent fa6b944b
......@@ -3,18 +3,15 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Floatfield</title>
<title>ERP5 Integerfield</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_global.js" type="text/javascript"></script>
<script src="gadget_erp5_field_integer.js" type="text/javascript"></script>
</head>
<body>
<input type="number" step="1"/>
</body>
</html>
\ No newline at end of file
......@@ -220,7 +220,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>xiaowu</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>940.60742.34496.36488</string> </value>
<value> <string>954.42877.47511.36096</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1423754455.46</float>
<float>1476697183.42</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP, loopEventListener */
/*global window, rJS */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, loopEventListener) {
(function (window, rJS) {
"use strict";
rJS(window)
.ready(function (gadget) {
return gadget.getElement()
.push(function (element) {
gadget.element = element;
});
})
.declareAcquiredMethod("notifyValid", "notifyValid")
.declareAcquiredMethod("notifyInvalid", "notifyInvalid")
.declareAcquiredMethod("notifyChange", "notifyChange")
.declareMethod('getTextContent', function () {
return this.element.querySelector('input').getAttribute('value');
.setState({
tag: 'p',
step: 1,
type: "number"
})
.declareMethod('render', function (options) {
var input = this.element.querySelector('input'),
field_json = options.field_json || {};
input.setAttribute(
'value',
field_json.value || field_json.default || ""
);
input.setAttribute('name', field_json.key);
input.setAttribute('title', field_json.title);
if (field_json.required === 1) {
input.setAttribute('required', 'required');
}
if (field_json.editable !== 1) {
input.setAttribute('readonly', 'readonly');
input.setAttribute('data-wrapper-class', 'ui-state-disabled ui-state-readonly');
input.setAttribute('disabled', 'disabled');
var field_json = options.field_json || {},
state_dict = {
value: field_json.value || field_json.default || "",
editable: field_json.editable,
required: field_json.required,
name: field_json.key,
title: field_json.title
};
state_dict.text_content = state_dict.value;
return this.changeState(state_dict);
})
.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';
}
})
.declareMethod('getContent', function () {
var input = this.element.querySelector('input'),
result = {};
result[input.getAttribute('name')] = input.value;
return result;
})
.declareMethod('checkValidity', function () {
var result;
result = this.element.querySelector('input').checkValidity();
if (result) {
return this.notifyValid()
.push(function () {
return result;
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;
return result
.push(function (input) {
return input.render(gadget.state);
});
})
.declareService(function () {
////////////////////////////////////
// Check field validity when the value changes
////////////////////////////////////
var field_gadget = this;
function notifyChange() {
return RSVP.all([
field_gadget.checkValidity(),
field_gadget.notifyChange()
]);
.declareMethod('getContent', function () {
if (this.state.editable) {
return this.getDeclaredGadget('sub')
.push(function (gadget) {
return gadget.getContent();
});
}
// Listen to input change
return loopEventListener(
field_gadget.element.querySelector('input'),
'change',
false,
notifyChange
);
return {};
})
.declareService(function () {
////////////////////////////////////
// Inform when the field input is invalid
////////////////////////////////////
var field_gadget = this;
.declareMethod('getTextContent', function () {
return this.getDeclaredGadget('sub')
.push(function (gadget) {
return gadget.getTextContent();
});
})
function notifyInvalid(evt) {
return field_gadget.notifyInvalid(evt.target.validationMessage);
.declareMethod('checkValidity', function () {
if (this.state.editable) {
return this.getDeclaredGadget('sub')
.push(function (gadget) {
return gadget.checkValidity();
});
}
// Listen to input change
return loopEventListener(
field_gadget.element.querySelector('input'),
'invalid',
false,
notifyInvalid
);
return true;
});
}(window, rJS, RSVP, loopEventListener));
\ No newline at end of file
}(window, rJS));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>949.15479.42024.21538</string> </value>
<value> <string>954.42915.19295.27187</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1455899193.71</float>
<float>1476697168.98</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -22,7 +22,8 @@
name: options.name,
type: options.type || 'text',
title: options.title,
focus: options.focus
focus: options.focus,
step: options.step
};
return this.changeState(state_dict);
})
......@@ -40,6 +41,9 @@
if (this.state.title) {
textarea.setAttribute('title', this.state.title);
}
if (this.state.step) {
textarea.setAttribute('step', this.state.step);
}
if (this.state.required) {
textarea.required = true;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.35751.60338.24780</string> </value>
<value> <string>954.35863.52273.29354</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476274067.85</float>
<float>1476697276.8</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