[imp] refactored fields binary & image
bzr revid: nicolas.vanhoren@openerp.com-20120319161358-uw9h91fakkc1e2fu
This commit is contained in:
parent
e3ba4192e4
commit
e3a8b30a15
|
@ -3290,14 +3290,17 @@ openerp.web.form.FieldReference = openerp.web.form.AbstractField.extend(_.extend
|
|||
}
|
||||
}));
|
||||
|
||||
openerp.web.form.FieldBinary = openerp.web.form.AbstractField.extend({
|
||||
openerp.web.form.FieldBinary = openerp.web.form.AbstractField.extend(_.extend({}, openerp.web.form.ReinitializeFieldMixin, {
|
||||
init: function(view, node) {
|
||||
this._super(view, node);
|
||||
this.iframe = this.element_id + '_iframe';
|
||||
this.binary_value = false;
|
||||
},
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this._super();
|
||||
openerp.web.form.ReinitializeFieldMixin.start.call(this);
|
||||
},
|
||||
bind_events: function() {
|
||||
this.$element.find('input.oe-binary-file').change(this.on_file_change);
|
||||
this.$element.find('button.oe-binary-file-save').click(this.on_save_as);
|
||||
this.$element.find('.oe-binary-file-clear').click(this.on_clear);
|
||||
|
@ -3361,27 +3364,41 @@ openerp.web.form.FieldBinary = openerp.web.form.AbstractField.extend({
|
|||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
openerp.web.form.FieldBinaryFile = openerp.web.form.FieldBinary.extend({
|
||||
template: 'FieldBinaryFile',
|
||||
start: function() {
|
||||
this._super();
|
||||
},
|
||||
update_dom: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.find('.oe-binary-file-set, .oe-binary-file-clear').toggle(!this.readonly);
|
||||
this.$element.find('input[type=text]').prop('readonly', this.readonly);
|
||||
bind_events: function() {
|
||||
if (this.get("effective_readonly")) {
|
||||
var self = this;
|
||||
this.$element.find('a').click(function() {
|
||||
if (self.value) {
|
||||
self.on_save_as();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
},
|
||||
set_value: function(value) {
|
||||
this._super.apply(this, arguments);
|
||||
var show_value;
|
||||
if (this.node.attrs.filename) {
|
||||
show_value = this.view.datarecord[this.node.attrs.filename] || '';
|
||||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
if (!this.get("effective_readonly")) {
|
||||
var show_value;
|
||||
if (this.node.attrs.filename) {
|
||||
show_value = this.view.datarecord[this.node.attrs.filename] || '';
|
||||
} else {
|
||||
show_value = (this.value != null && this.value !== false) ? this.value : '';
|
||||
}
|
||||
this.$element.find('input').eq(0).val(show_value);
|
||||
} else {
|
||||
show_value = (value != null && value !== false) ? value : '';
|
||||
this.$element.find('a').show(!!this.value);
|
||||
if (this.value) {
|
||||
var show_value = _t("Download") + " " + (this.view.datarecord[this.node.attrs.filename] || '');
|
||||
this.$element.find('a').text(show_value);
|
||||
}
|
||||
}
|
||||
this.$element.find('input').eq(0).val(show_value);
|
||||
},
|
||||
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
|
||||
this.value = file_base64;
|
||||
|
@ -3406,24 +3423,22 @@ openerp.web.form.FieldBinaryFile = openerp.web.form.FieldBinary.extend({
|
|||
|
||||
openerp.web.form.FieldBinaryImage = openerp.web.form.FieldBinary.extend({
|
||||
template: 'FieldBinaryImage',
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
bind_events: function() {
|
||||
this.$image = this.$element.find('img.oe-binary-image');
|
||||
var check_visibility = function() {
|
||||
if (!this.get("effective_readonly"))
|
||||
this.$element.find('.oe-binary').show();
|
||||
else
|
||||
this.$element.find('.oe-binary').hide();
|
||||
}
|
||||
this.on("change:effective_readonly", this, check_visibility);
|
||||
_.bind(check_visibility, this)();
|
||||
if (!this.get("effective_readonly"))
|
||||
this.$element.find('.oe-binary').show();
|
||||
else
|
||||
this.$element.find('.oe-binary').hide();
|
||||
},
|
||||
set_value: function(value) {
|
||||
this._super.apply(this, arguments);
|
||||
this.render_value();
|
||||
},
|
||||
render_value: function() {
|
||||
this.set_image_maxwidth();
|
||||
|
||||
var url;
|
||||
if (value && value.substr(0, 10).indexOf(' ') == -1) {
|
||||
if (this.value && this.value.substr(0, 10).indexOf(' ') == -1) {
|
||||
url = 'data:image/png;base64,' + this.value;
|
||||
} else {
|
||||
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
|
||||
|
|
|
@ -68,29 +68,7 @@ openerp.web.page = function (openerp) {
|
|||
/** @namespace */
|
||||
openerp.web.page = {};
|
||||
|
||||
openerp.web.page.FieldBinaryFileReadonly = openerp.web.form.FieldBinary.extend({
|
||||
form_template: 'FieldURI.readonly',
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
var self = this;
|
||||
this.$element.find('a').click(function() {
|
||||
if (self.value) {
|
||||
self.on_save_as();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
set_value: function(value) {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.find('a').show(!!value);
|
||||
if (value) {
|
||||
var show_value = _t("Download") + " " + (this.view.datarecord[this.node.attrs.filename] || '');
|
||||
this.$element.find('a').text(show_value);
|
||||
}
|
||||
}
|
||||
});
|
||||
openerp.web.page.readonly = openerp.web.form.widgets.extend({
|
||||
'binary': 'openerp.web.page.FieldBinaryFileReadonly',
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -1152,54 +1152,61 @@
|
|||
</table>
|
||||
</t>
|
||||
<t t-name="FieldBinaryFile">
|
||||
<table t-attf-class="oe_form_field_#{widget.type}" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" size="1" readonly="readonly"
|
||||
t-att-name="widget.name"
|
||||
t-att-id="widget.element_id + '_field'"
|
||||
t-attf-class="field_#{widget.type}"
|
||||
/>
|
||||
</td>
|
||||
<td class="oe-binary" nowrap="true">
|
||||
<table cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<div class="oe-binary-file-set" style="width: 80px; height:22px;">
|
||||
<form class="oe-binary-form" t-att-target="widget.iframe"
|
||||
method="post" enctype="multipart/form-data" action="/web/binary/upload">
|
||||
<input type="hidden" name="session_id" value=""/>
|
||||
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
|
||||
<button class="oe_button oe_field_button" type="button" title="Set Image">
|
||||
<img t-att-src='_s + "/web/static/src/img/icons/STOCK_DIRECTORY.png"'/>
|
||||
<span>Select</span>
|
||||
</button>
|
||||
<input type="file" class="oe-binary-file" name="ufile"/>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button class="oe_button oe-binary-file-save" type="button" title="Save As">
|
||||
<img t-att-src='_s + "/web/static/src/img/icons/gtk-save.png"'/>
|
||||
<span>Save As</span>
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="oe_button oe-binary-file-clear" type="button" title="Clear">
|
||||
<img t-att-src='_s + "/web/static/src/img/icons/STOCK_MISSING_IMAGE.png"'/>
|
||||
<span>Clear</span>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td class="oe-binary-progress" style="display: none" nowrap="true">
|
||||
<img t-att-src='_s + "/web/static/src/img/throbber.gif"' width="16" height="16"/>
|
||||
<b>Uploading ...</b>
|
||||
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<t t-if="!widget.get('effective_readonly')">
|
||||
<table t-attf-class="oe_form_field_#{widget.type}" cellpadding="0" cellspacing="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" size="1" readonly="readonly"
|
||||
t-att-name="widget.name"
|
||||
t-att-id="widget.element_id + '_field'"
|
||||
t-attf-class="field_#{widget.type}"
|
||||
/>
|
||||
</td>
|
||||
<td class="oe-binary" nowrap="true">
|
||||
<table cellspacing="0" cellpadding="0" border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<div class="oe-binary-file-set" style="width: 80px; height:22px;">
|
||||
<form class="oe-binary-form" t-att-target="widget.iframe"
|
||||
method="post" enctype="multipart/form-data" action="/web/binary/upload">
|
||||
<input type="hidden" name="session_id" value=""/>
|
||||
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
|
||||
<button class="oe_button oe_field_button" type="button" title="Set Image">
|
||||
<img t-att-src='_s + "/web/static/src/img/icons/STOCK_DIRECTORY.png"'/>
|
||||
<span>Select</span>
|
||||
</button>
|
||||
<input type="file" class="oe-binary-file" name="ufile"/>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button class="oe_button oe-binary-file-save" type="button" title="Save As">
|
||||
<img t-att-src='_s + "/web/static/src/img/icons/gtk-save.png"'/>
|
||||
<span>Save As</span>
|
||||
</button>
|
||||
</td>
|
||||
<td>
|
||||
<button class="oe_button oe-binary-file-clear" type="button" title="Clear">
|
||||
<img t-att-src='_s + "/web/static/src/img/icons/STOCK_MISSING_IMAGE.png"'/>
|
||||
<span>Clear</span>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td class="oe-binary-progress" style="display: none" nowrap="true">
|
||||
<img t-att-src='_s + "/web/static/src/img/throbber.gif"' width="16" height="16"/>
|
||||
<b>Uploading ...</b>
|
||||
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</t>
|
||||
<t t-if="widget.get('effective_readonly')">
|
||||
<div>
|
||||
<a href="javascript:void(0)" class="oe_form_uri"/>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-name="WidgetButton">
|
||||
<div t-attf-class="oe_form_field_#{widget.type}">
|
||||
|
|
Loading…
Reference in New Issue