Thibault Delavallée (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-fix-maxsizeupload-chm into lp:openerp-web.

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-fix-maxsizeupload-chm/+merge/135342
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-fix-maxsizeupload-chm/+merge/135342
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-fix-maxsizeupload-chm.
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js	2012-11-20 15:39:58 +0000
+++ addons/web/static/src/js/view_form.js	2012-11-21 09:35:32 +0000
@@ -4026,9 +4026,11 @@
         }
         this._super(value_);
     },
+    is_false: function() {
+        return _(this.get("value")).isEmpty();
+    },
     get_value: function() {
-        var tmp = [commands.replace_with(this.get("value"))];
-        return tmp;
+        return [commands.replace_with(this.get("value"))];
     },
     get_search_blacklist: function() {
         return this.get("value");
@@ -4782,6 +4784,23 @@
     },
 });
 
+
+/**
+* Check the size of the files to upload for a input (type=file)
+* Throw an exeption if the file is too big.
+* @return Boolean
+*/
+instance.web.form.check_max_size_upload_per_file = function (input) {
+    var max_size = 25; //Mo
+    var file = input.files && input.files[0] || file;
+    if (file.size > max_size*1024*1024) {
+        instance.webclient.notification.warn(_t("File uploading"), _t('The max size per file uploading is ' + max_size + 'Mo.<br/><br/>File name:' + file.name + '<br/>File size: ' + Math.round(file.size/1024/1024) + 'Mo)'));
+        return false;
+    } else {
+        return true;
+    }
+}
+
 instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance.web.form.ReinitializeFieldMixin, {
     init: function(field_manager, node) {
         var self = this;
@@ -4810,7 +4829,7 @@
     on_file_change: function(e) {
         var self = this;
         var file_node = e.target;
-        if ((this.useFileAPI && file_node.files.length) || (!this.useFileAPI && $(file_node).val() !== '')) {
+        if ( instance.web.form.check_max_size_upload_per_file(file_node) && ((this.useFileAPI && file_node.files.length) || (!this.useFileAPI && $(file_node).val() !== ''))) {
             if (this.useFileAPI) {
                 var file = file_node.files[0];
                 var filereader = new FileReader();
@@ -5093,8 +5112,9 @@
         event.stopPropagation();
         var self = this;
         var $target = $(event.target);
-        if ($target.val() !== '') {
+        if ($target.val() !== '' &&  instance.web.form.check_max_size_upload_per_file(event.target)) {
 
+            console.log(this);
             var filename = $target.val().replace(/.*[\\\/]/,'');
 
             // if the files is currently uploded, don't send again

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to