summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2012-03-23 16:04:48 +0100
committerniv-openerp <nicolas.vanhoren@openerp.com>2012-03-23 16:04:48 +0100
commit2a9cde48c863880a06770ae0cce74e8995dec4e8 (patch)
tree3ca0c21026efb2a1ff64afe4fab8eca293d28581 /addons/web/static/src
parentd4ec427f0168d57777b61fec4c941ea874ffcc02 (diff)
[imp] default value for "value" in the fields
bzr revid: nicolas.vanhoren@openerp.com-20120323150448-om2trotjpbee5j9o
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js24
-rw-r--r--addons/web/static/src/xml/base.xml20
2 files changed, 24 insertions, 20 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index c1e51b39bec..4132123f883 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -1428,7 +1428,7 @@ openerp.web.form.AbstractField = openerp.web.form.Widget.extend(/** @lends opene
init: function(field_manager, node) {
this._super(field_manager, node);
this.name = this.node.attrs.name;
- this.value = undefined;
+ this.value = false;
this.view.fields[this.name] = this;
this.view.fields_order.push(this.name);
this.type = this.node.attrs.widget;
@@ -1557,6 +1557,7 @@ openerp.web.form.ReinitializeFieldMixin = {
this.render_value();
});
this.initialize_content();
+ this.render_value();
},
/**
* Called to destroy anything that could have been created previously, called before a
@@ -1675,6 +1676,7 @@ openerp.web.form.FieldUrl = openerp.web.form.FieldChar.extend({
openerp.web.form.FieldFloat = openerp.web.form.FieldChar.extend({
init: function (view, node) {
this._super(view, node);
+ this.value = 0;
if (this.node.attrs.digits) {
this.parse_digits(this.node.attrs.digits);
} else {
@@ -3498,7 +3500,7 @@ openerp.web.form.FieldBinaryImage = openerp.web.form.FieldBinary.extend({
template: 'FieldBinaryImage',
initialize_content: function() {
this._super();
- this.$image = this.$element.find('img.oe-binary-image');
+ this.$placeholder = $(".oe_form_field-binary-image-placeholder", this.$element);
if (!this.get("effective_readonly"))
this.$element.find('.oe-binary').show();
else
@@ -3509,32 +3511,30 @@ openerp.web.form.FieldBinaryImage = openerp.web.form.FieldBinary.extend({
this.render_value();
},
render_value: function() {
- this.set_image_maxwidth();
-
var url;
if (this.value && this.value.substr(0, 10).indexOf(' ') == -1) {
url = 'data:image/png;base64,' + this.value;
- } else {
+ } else if (this.value) {
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime());
+ } else {
+ url = "/web/static/src/img/placeholder.png";
}
- this.$image.attr('src', url);
- },
- set_image_maxwidth: function() {
- this.$image.css('max-width', this.$element.width());
+ var rendered = QWeb.render("FieldBinaryImage-img", {widget: this, url: url});;
+ this.$placeholder.html(rendered);
},
on_file_change: function() {
- this.set_image_maxwidth();
+ this.render_value();
this._super.apply(this, arguments);
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
this.value = file_base64;
this.binary_value = true;
- this.$image.attr('src', 'data:' + (content_type || 'image/png') + ';base64,' + file_base64);
+ this.render_value();
},
on_clear: function() {
this._super.apply(this, arguments);
- this.$image.attr('src', '/web/static/src/img/placeholder.png');
+ this.render_value();
}
});
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index a6704ad659b..809ed991cd9 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -1116,14 +1116,8 @@
<t t-name="FieldBinaryImage">
<table t-attf-class="oe_form_field_#{widget.type}" cellpadding="0" cellspacing="0" border="0">
<tr>
- <td align="center">
- <img t-att-src='_s + "/web/static/src/img/placeholder.png"' class="oe-binary-image"
- t-att-border="widget.readonly ? 0 : 1"
- t-att-name="widget.name"
- t-attf-class="field_#{widget.type}"
- t-att-width="widget.node.attrs.img_width || widget.node.attrs.width"
- t-att-height="widget.node.attrs.img_height || widget.node.attrs.height"
- />
+ <td class="oe_form_field-binary-image-placeholder" align="center">
+
</td>
</tr>
<tr>
@@ -1161,6 +1155,16 @@
</tr>
</table>
</t>
+<t t-name="FieldBinaryImage-img">
+ <img t-att-src='url' class="oe-binary-image"
+ t-att-border="widget.readonly ? 0 : 1"
+ t-att-name="widget.name"
+ t-attf-class="field_#{widget.type}"
+ t-att-width="widget.node.attrs.img_width || widget.node.attrs.width"
+ t-att-height="widget.node.attrs.img_height || widget.node.attrs.height"
+ t-att-style="'max-width: ' + (widget.$element.width() > 60 ? widget.$element.width() : 60) + 'px'"
+ />
+</t>
<t t-name="FieldBinaryFile">
<t t-if="!widget.get('effective_readonly')">
<table t-attf-class="oe_form_field_#{widget.type}" cellpadding="0" cellspacing="0" border="0">