[ADD] Added upload of image. (WIP)

bzr revid: fme@openerp.com-20110518223616-axty8elieyq3ccqt
This commit is contained in:
Fabien Meghazi 2011-05-19 00:36:16 +02:00
parent b432e7ba1a
commit 279d206a64
3 changed files with 67 additions and 9 deletions

View File

@ -1,4 +1,5 @@
/* TODO: separate openerp web client page css from openerp views css */
body {
padding: 0;
margin: 0;
@ -621,6 +622,27 @@ body.openerp {
-moz-background-origin: content-box;
-webkit-background-origin: content-box;
}
/* http://www.quirksmode.org/dom/inputfile.html
* http://stackoverflow.com/questions/2855589/replace-input-type-file-by-an-image
*/
.openerp button.oe-binary-image-set {
overflow: hidden;
position: relative;
}
.openerp input.oe-binary-file {
z-index: 2;
line-height: 0;
font-size: 50px;
position: absolute;
/* Should be adjusted for all browsers */
top: -2px;
left: -700px;
opacity: 0;
filter: alpha(opacity = 0);
-ms-filter: "alpha(opacity=0)";
margin: 0;
padding:0;
}
/* Widgets */
.openerp .separator {

View File

@ -1191,13 +1191,36 @@ openerp.base.form.FieldImage = openerp.base.form.Field.extend({
init: function(view, node) {
this._super(view, node);
this.template = "FieldImage";
this.iframe = this.element_id + '_iframe';
},
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-image-clear').click(this.on_clear);
},
set_value_from_ui: function() {
},
on_file_change: function() {
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_throbbler();
},
toggle_throbbler: function() {
this.$element.find('div.oe-binary-progress, div.oe-binary-image-buttons').toggle();
},
on_file_uploaded: function(size, name, content_type) {
delete(window[this.iframe]);
if (size === false) {
this.notification.warn("File Upload", "There was a problem while uploading your file");
// TODO: use openerp web exception handler
console.log("Error while uploading file : ", name);
} else {
alert('File uploaded')
console.log("Size", size, "Name", name, "Content", content_type);
}
this.toggle_throbbler();
},
on_clear: function() {
if (this.value !== false) {
this.value = false;

View File

@ -401,15 +401,28 @@
</tr>
<tr>
<td align="center" valign="bottom" height="25">
<button class="button oe-binary-image-set" type="button" title="Set Image">
<img src="/base/static/src/img/icons/STOCK_DIRECTORY.png"/>
</button>
<!--<button class="button oe-binary-image-save" type="button" title="Save As">
<img src="/base/static/src/img/icons/gtk-save.png"/>
</button>-->
<button class="button oe-binary-image-clear" type="button" title="Clear">
<img src="/base/static/src/img/icons/STOCK_MISSING_IMAGE.png"/>
</button>
<div class="oe-binary-image-buttons">
<!-- TODO: input@type=file inside a button won't work in firefox. Use links instead -->
<button class="button oe-binary-image-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-image-save" type="button" title="Save As">
<img src="/base/static/src/img/icons/gtk-save.png"/>
</button>-->
<button class="button oe-binary-image-clear" type="button" title="Clear">
<img src="/base/static/src/img/icons/STOCK_MISSING_IMAGE.png"/>
</button>
</div>
<div class="oe-binary-progress" style="display: none">
Uploading ...
</div>
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"> </iframe>
</td>
</tr>
</table>