Christophe Matthieu (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-openchatter-DOM-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-openchatter-DOM-chm/+merge/131595
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-openchatter-DOM-chm/+merge/131595
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-openchatter-DOM-chm.
=== modified file 'addons/web/static/src/css/base.css'
--- addons/web/static/src/css/base.css	2012-10-25 12:07:07 +0000
+++ addons/web/static/src/css/base.css	2012-10-26 12:15:27 +0000
@@ -2928,6 +2928,7 @@
   -webkit-border-radius: 3px;
   border-radius: 3px;
 }
+<<<<<<< TREE
 
 @media print {
   .openerp {
@@ -2966,3 +2967,51 @@
     overflow: hidden !important;
   }
 }
+=======
+
+
+
+.openerp .oe_fileuploader {
+    display: inline-block;
+    clear: both;
+}
+.openerp .oe_fileuploader .oe_add {
+    float: left;
+    width: 24px;
+    height: 24px;
+    position: relative;
+    left: +2px;
+    top: +7px;
+    overflow: hidden;
+}
+.openerp .oe_fileuploader .oe_add button {
+    position: absolute;
+    bottom: +0px;
+    left: +0px;
+    height: 24px;
+    width: 24px;
+    margin: 0px;
+    padding: 0px;
+}
+.openerp .oe_fileuploader .oe_add .oe_hidden_input_file input.oe_form_binary_file {
+    width: 300px;
+    left: -100px;
+    top: 1px;
+    height: 24px;
+    width: 300px;
+    background: transparent;
+    border: 0;
+    margin: 0px;
+    padding: 0px;
+    color: transparent;
+}
+.openerp .oe_fileuploader .oe_add button span {
+    position: relative;
+    bottom: +4px;
+    font-size: 30px;
+}
+
+.openerp .oe_fileuploader {
+    clear: both;
+}
+>>>>>>> MERGE-SOURCE

=== modified file 'addons/web/static/src/css/base.sass'
--- addons/web/static/src/css/base.sass	2012-10-25 12:07:07 +0000
+++ addons/web/static/src/css/base.sass	2012-10-26 12:15:27 +0000
@@ -2273,6 +2273,65 @@
         float: right
         color: #333
     // }}}
+
+.openerp .oe_fileuploader .oe_add .oe_hidden_input_file input.oe_form_binary_file {
+    width: 300px;
+    left: -100px;
+    top: 1px;
+    height: 24px;
+    width: 300px;
+    background: transparent;
+    border: 0;
+    margin: 0px;
+    padding: 0px;
+    color: transparent;
+}
+.openerp .oe_fileuploader .oe_add button span {
+    position: relative;
+    bottom: +4px;
+    font-size: 30px;
+}
+
+.openerp .oe_fileuploader {
+    clear: both;
+}
+
+    .oe_fileuploader
+        display: inline-block
+        clear: both
+        .oe_add
+            float: left
+            width: 24px
+            height: 24px
+            position: relative
+            z-index: 10
+            left: +2px
+            top: +7px
+            overflow: hidden
+            button
+                position: absolute
+                bottom: +0px
+                left: +0px
+                height: 24px
+                width: 24px
+                margin: 0px
+                padding: 0px
+            input.oe_form_binary_file
+                width: 300px
+                left: -100px
+                top: 1px
+                height: 24px
+                width: 300px
+                background: transparent
+                border: 0
+                margin: 0px
+                padding: 0px
+                color: transparent
+        button span
+            position: relative
+            bottom: +4px
+            font-size: 30px
+
 // Kitten Mode {{{
 .kitten-mode-activated
     background-image: url(http://placekitten.com/g/1365/769)

=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js	2012-10-26 10:00:11 +0000
+++ addons/web/static/src/js/view_form.js	2012-10-26 12:15:27 +0000
@@ -4733,6 +4733,8 @@
         }
         this.$el.find('.oe_form_binary_progress').hide();
         this.$el.find('.oe_form_binary').show();
+
+        console.log("upload ok");
     },
     on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
     },
@@ -4874,6 +4876,140 @@
     }
 });
 
+/**
+ * Widget for (one2many field) to upload one or more file in same time and display in list.
+ * The user can delete his files.
+ * Options on attribute ; "blockui" {Boolean} block the UI or not
+ * during the file is uploading
+ */
+instance.web.form.FieldOne2ManyBinaryMultiFiles = instance.web.form.AbstractField.extend({
+    template: "FieldBinaryFileUploader",
+    init: function(field_manager, node) {
+        this._super(field_manager, node);
+        this.field_manager = field_manager;
+        this.node = node;
+        if(this.field.type != "one2many" || this.field.relation != 'ir.attachment') {
+            console.log("The type of the field '"+this.field.string+"' must be a one2many field with a relation to 'ir.attachment' model.");
+        }
+        this.ds_file = new instance.web.DataSetSearch(this, 'ir.attachment');
+        this.fileupload_id = _.uniqueId('oe_fileupload_temp');
+        $(window).on(this.fileupload_id, this.on_file_loaded);
+
+        this.files = false;
+    },
+    start: function() {
+        this._super(this);
+        this.$list_file = this.$('.oe_placeholder_files');
+        this.$el.on('change', 'input.oe_form_binary_file', this.on_file_change );
+        this.display_files();
+    },
+    set_value: function(value_) {
+        var values = this.files = (value_ && !this.files) ? value_ : this.files;
+        this._super( values );
+        this.display_files();
+    },
+    get_value: function() {
+        return _.map(this.get('value'), function (value) { return commands.link_to( value.id ); });
+    },
+    get_file_url: function (attachment) {
+        return instance.origin + '/web/binary/saveas?session_id=' + this.session.session_id + '&model=ir.attachment&field=datas&filename_field=datas_fname&id=' + attachment['id'];
+    },
+    display_files: function(){
+        if(this.$list_file) {
+            var render = $(instance.web.qweb.render('FieldBinaryFileUploader.files', {'widget': this}));
+            this.$list_file.replaceWith( render );
+            this.$list_file = this.$(".oe_files");
+            this.$list_file.on('click', '.oe_delete', this.on_file_delete);
+        }
+    },
+    on_file_change: function (event) {
+        event.stopPropagation();
+        var self = this;
+        var $target = $(event.target);
+        if ($target.val() !== '') {
+
+            var filename = $target.val().replace(/.*[\\\/]/,'');
+
+            // if the files is currently uploded, don't send again
+            if( !isNaN(_.find(this.files, function (file) { return (file.filename || file.name) == filename && file.upload; } )) ) {
+                return false;
+            }
+
+            // if the files exits for this answer, delete the file before upload
+            this.files = _.filter(this.files, function (file) {
+                if((file.filename || file.name) == filename) {
+                    self.ds_file.unlink([file.id]);
+                    return false;
+                } else {
+                    return true;
+                }
+            });
+
+            // block UI or not
+            if(this.node.attrs.blockui) {
+                instance.web.blockUI();
+            }
+
+            // TODO : unactivate send on wizard and form
+
+            // submit file
+            this.$('form.oe_form_binary_form').submit();
+            this.$(".oe_fileuploader").hide();
+
+            // add file on result
+            this.files.push({
+                'id': 0,
+                'name': filename,
+                'filename': filename,
+                'url': '',
+                'upload': true
+            });
+            this.set_value();
+        }
+    },
+    on_file_loaded: function (event, result) {
+        // unblock UI
+        if(this.node.attrs.blockui) {
+            instance.web.unblockUI();
+        }
+
+        // TODO : activate send on wizard and form
+
+        for(var i in this.files){
+            if(this.files[i].filename == result.filename && this.files[i].upload) {
+                this.files[i] = {
+                    'id': result.id,
+                    'name': result.name,
+                    'filename': result.filename,
+                    'url': this.get_file_url(result)
+                };
+            }
+        }
+        this.set_value();
+
+        var $input = this.$('input.oe_form_binary_file');
+        $input.after($input.clone(true)).remove();
+        this.$(".oe_fileuploader").show();
+    },
+    on_file_delete: function (event) {
+        event.stopPropagation();
+        var file_id=$(event.target).data("id");
+        if (file_id) {
+            var files=[];
+            for(var i in this.files){
+                if(file_id!=this.files[i].id){
+                    files.push(this.files[i]);
+                }
+                else {
+                    this.ds_file.unlink([file_id]);
+                }
+            }
+            this.files = files;
+            this.set_value();
+        }
+    },
+});
+
 instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
     template: "FieldStatus",
     init: function(field_manager, node) {
@@ -5026,6 +5162,7 @@
     'progressbar': 'instance.web.form.FieldProgressBar',
     'image': 'instance.web.form.FieldBinaryImage',
     'binary': 'instance.web.form.FieldBinaryFile',
+    'one2many_binary': 'instance.web.form.FieldOne2ManyBinaryMultiFiles',
     'statusbar': 'instance.web.form.FieldStatus',
     'monetary': 'instance.web.form.FieldMonetary',
 });

=== modified file 'addons/web/static/src/xml/base.xml'
--- addons/web/static/src/xml/base.xml	2012-10-25 08:35:09 +0000
+++ addons/web/static/src/xml/base.xml	2012-10-26 12:15:27 +0000
@@ -1174,6 +1174,42 @@
         <iframe t-att-id="fileupload_id" t-att-name="fileupload_id" style="display: none"/>
     </div>
 </t>
+<t t-name="FieldBinaryFileUploader.files">
+    <ul class="oe_files">
+        <t t-foreach="widget.files" t-as="file">
+            <li>
+                <span t-if="(file.upload or file.percent_loaded&lt;100)" t-attf-title="{(file.name || file.filename) + (file.date?' \n('+file.date+')':'' )}" t-attf-name="{file.name || file.filename}">
+                    <span class="oe_fileuploader_in_process">
+                        <span>...Upload in progress...</span>
+                    </span>
+                    <t t-raw="file.name || file.filename"/>
+                </span>
+                <a t-if="(!file.upload or file.percent_loaded&gt;=100)" t-att-href="file.url" t-attf-title="{(file.name || file.filename) + (file.date?' \n('+file.date+')':'' )}">
+                    <t t-raw="file.name || file.filename"/>
+                </a>
+                <t t-if="(!file.upload or file.percent_loaded&gt;=100)">
+                    <a class="oe_delete" title="Delete this file" t-attf-data-id="{file.id}">x</a>
+                </t>
+            </li>
+        </t>
+    </ul>
+</t>
+<t t-name="FieldBinaryFileUploader">
+    <div t-att-style="widget.node.attrs.style" t-attf-class="oe_fileuploader #{widget.node.attrs.class ? widget.node.attrs.class :''}">
+        <div class="oe_placeholder_files"/>
+        <div class="oe_add">
+            <!-- uploader of file -->
+            <button><span class="oe_e">p</span></button>
+            <t t-call="HiddenInputFile">
+                <t t-set="fileupload_id" t-value="widget.fileupload_id"/>
+                <t t-set="fileupload_action">/web/binary/upload_attachment</t>
+                <input type="hidden" name="model" t-att-value="widget.view.model"/>
+                <input type="hidden" name="id" value="0"/>
+                <input type="hidden" name="session_id" t-att-value="widget.session.session_id"/>
+            </t>
+        </div>
+    </div>
+</t>
 <t t-name="WidgetButton">
     <button type="button" class="oe_button oe_form_button"
         t-att-style="widget.node.attrs.style"

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to