[FIX] Fixed file selector button hack for Firefox

bzr revid: fme@openerp.com-20110523133840-slawlyaexyq4l3j1
This commit is contained in:
Fabien Meghazi 2011-05-23 15:38:40 +02:00
parent 5238385e6a
commit 753f80e851
3 changed files with 66 additions and 37 deletions

View File

@ -628,7 +628,7 @@ body.openerp {
/* http://www.quirksmode.org/dom/inputfile.html
* http://stackoverflow.com/questions/2855589/replace-input-type-file-by-an-image
*/
.openerp button.oe-binary-file-set {
.openerp .oe-binary-file-set {
overflow: hidden;
position: relative;
}

View File

@ -1212,6 +1212,7 @@ openerp.base.form.FieldBinary = openerp.base.form.Field.extend({
start: function() {
this._super.apply(this, arguments);
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);
},
set_value_from_ui: function() {
@ -1225,14 +1226,16 @@ openerp.base.form.FieldBinary = openerp.base.form.Field.extend({
}
return size.toFixed(2) + ' ' + units[i];
},
on_file_change: function() {
on_file_change: function(e) {
// TODO: on modern browsers, we could directly read the file locally on client ready to be used on image cropper
// http://www.html5rocks.com/tutorials/file/dndfiles/
// http://deepliquid.com/projects/Jcrop/demos.php?demo=handler
window[this.iframe] = this.on_file_uploaded;
this.$element.find('form.oe-binary-form input[name=session_id]').val(this.session.session_id);
this.$element.find('form.oe-binary-form').submit();
this.toggle_progress();
if ($(e.target).val() != '') {
this.$element.find('form.oe-binary-form input[name=session_id]').val(this.session.session_id);
this.$element.find('form.oe-binary-form').submit();
this.toggle_progress();
}
},
toggle_progress: function() {
this.$element.find('.oe-binary-progress, .oe-binary').toggle();
@ -1251,6 +1254,12 @@ openerp.base.form.FieldBinary = openerp.base.form.Field.extend({
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
},
on_save_as: function() {
var url = '/base/formview/saveas?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name +
'&fieldname=' + (this.node.attrs.filename || '') + '&t=' + (new Date().getTime())
window.open(url);
},
on_clear: function() {
if (this.value !== false) {
this.value = false;

View File

@ -416,19 +416,28 @@
<tr>
<td align="center" valign="bottom" height="25">
<div class="oe-binary">
<!-- TODO: input@type=file inside a button won't work in firefox. Use links instead -->
<button class="button oe-binary-file-set" type="button" title="Set Image">
<img src="/base/static/src/img/icons/STOCK_DIRECTORY.png"/>
<form class="oe-binary-form" t-att-target="widget.iframe"
method="post" enctype="multipart/form-data" action="/base/formview/upload">
<input type="hidden" name="session_id" value=""/>
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
<input type="file" class="oe-binary-file" name="ufile"/>
</form>
</button>
<button class="button oe-binary-file-clear" type="button" title="Clear">
<img src="/base/static/src/img/icons/STOCK_MISSING_IMAGE.png"/>
</button>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td>
<div class="oe-binary-file-set" style="width: 40px; height:22px;">
<form class="oe-binary-form" t-att-target="widget.iframe"
method="post" enctype="multipart/form-data" action="/base/formview/upload">
<input type="hidden" name="session_id" value=""/>
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
<button class="button" type="button" title="Set Image">
<img src="/base/static/src/img/icons/STOCK_DIRECTORY.png"/>
</button>
<input type="file" class="oe-binary-file" name="ufile"/>
</form>
</div>
</td>
<td>
<button class="button oe-binary-file-clear" type="button" title="Clear">
<img src="/base/static/src/img/icons/STOCK_MISSING_IMAGE.png"/>
</button>
</td>
</tr>
</table>
</div>
<div class="oe-binary-progress" style="display: none">
<img src="/base/static/src/img/throbber.gif" width="16" height="16"/>
@ -450,25 +459,36 @@
/>
</td>
<td class="oe-binary" nowrap="true">
<!-- TODO: input@type=file inside a button won't work in firefox. Use links instead -->
<button class="button oe-binary-file-set" type="button" title="Select file">
<img src="/base/static/src/img/icons/STOCK_DIRECTORY.png"/>
<span>Select</span>
<form class="oe-binary-form" t-att-target="widget.iframe"
method="post" enctype="multipart/form-data" action="/base/formview/upload">
<input type="hidden" name="session_id" value=""/>
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
<input type="file" class="oe-binary-file" name="ufile"/>
</form>
</button>
<button class="button oe-binary-file-save" type="button" title="Save As">
<img src="/base/static/src/img/icons/gtk-save.png"/>
<span>Save As</span>
</button>
<button class="button oe-binary-file-clear" type="button" title="Clear">
<img src="/base/static/src/img/icons/STOCK_MISSING_IMAGE.png"/>
<span>Clear</span>
</button>
<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="/base/formview/upload">
<input type="hidden" name="session_id" value=""/>
<input type="hidden" name="callback" t-att-value="widget.iframe"/>
<button class="button" type="button" title="Set Image">
<img src="/base/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="button oe-binary-file-save" type="button" title="Save As">
<img src="/base/static/src/img/icons/gtk-save.png"/>
<span>Save As</span>
</button>
</td>
<td>
<button class="button oe-binary-file-clear" type="button" title="Clear">
<img src="/base/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 src="/base/static/src/img/throbber.gif" width="16" height="16"/>