[ADD][WIP]Work in progress modules

This commit is contained in:
Fabien BOURGEOIS 2017-05-01 10:15:57 +02:00
parent e40f5a78a8
commit 31b46c2e9e
19 changed files with 911 additions and 0 deletions

View File

@ -0,0 +1,89 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
================
Base report xlsx
================
This module provides a basic report class to generate xlsx report.
Installation
============
Make sure you have ``xlsxwriter`` Python module installed::
$ pip install xlsxwriter
Usage
=====
An example of XLSX report for partners:
A python class ::
from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx
class partner_xlsx(ReportXlsx):
def generate_xlsx_report(self, workbook, data, partners):
for obj in partners:
report_name = obj.name
# One sheet by partner
sheet = workbook.add_worksheet(report_name[:31])
bold = workbook.add_format({'bold': True})
sheet.write(0, 0, obj.name, bold)
partner_xlsx('report.res.partner.xlsx',
'res.partner')
To manipulate the ``workbook`` and ``sheet`` objects, refer to the
`documentation <http://xlsxwriter.readthedocs.org/>`_ of ``xlsxwriter``.
A report XML record ::
<report
id="partner_xlsx"
model="res.partner"
string="Print to XLSX"
report_type="xlsx"
name="res.partner.xlsx"
file="res.partner.xlsx"
attachment_use="False"
/>
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/143/8.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_xlsx%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
* Icon taken from http://www.icons101.com/icon/id_67712/setid_2096/Boxed_Metal_by_Martin/xlsx.
Contributors
------------
* Adrien Peiffer <adrien.peiffer@acsone.eu>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import models
from . import report

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import ir_report

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from openerp import fields, models
class IrActionsReportRelatorio(models.Model):
_inherit = 'ir.actions.report.xml'
report_type = fields.Selection(selection_add=[("xlsx", "xlsx")])

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
'name': 'Relatorio reporting',
'summary': 'Adds simple reporting engine based on relatorio',
'version': '0.1',
'category': 'Reporting',
'author': 'Fabien Bourgeois',
'website': 'http://www.yaltik.com',
'license': 'AGPL-3',
'application': True,
'installable': True,
'external_dependencies': {'python': ['relatorio']},
'depends': ['base']
}

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import report_relatorio

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from cStringIO import StringIO
from openerp.report.report_sxw import report_sxw
from openerp.api import Environment
import logging
_logger = logging.getLogger(__name__)
try:
import xlsxwriter
except ImportError:
_logger.debug('Can not import xlsxwriter`.')
class ReportXlsx(report_sxw):
def create(self, cr, uid, ids, data, context=None):
self.env = Environment(cr, uid, context)
report_obj = self.env['ir.actions.report.xml']
report = report_obj.search([('report_name', '=', self.name[7:])])
if report.ids:
self.title = report.name
if report.report_type == 'xlsx':
return self.create_xlsx_report(ids, data, report)
return super(ReportXlsx, self).create(cr, uid, ids, data, context)
def create_xlsx_report(self, ids, data, report):
self.parser_instance = self.parser(
self.env.cr, self.env.uid, self.name2, self.env.context)
objs = self.getObjects(
self.env.cr, self.env.uid, ids, self.env.context)
self.parser_instance.set_context(objs, data, ids, 'xlsx')
file_data = StringIO()
workbook = xlsxwriter.Workbook(file_data)
self.generate_xlsx_report(workbook, data, objs)
workbook.close()
file_data.seek(0)
return (file_data.read(), 'xlsx')
def generate_xlsx_report(self, workbook, data, objs):
raise NotImplementedError()

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
'name': 'Web Image Uploader',
'summary': 'Web Widget : Image Uploader',
'description': 'Web Widget : Image Uploader',
'version': '0.1',
'category': 'Usability',
'author': 'Fabien Bourgeois',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': ['web'],
'data': ['views/web_image_uploader.xml']
}

View File

@ -0,0 +1,289 @@
/*
* dmuploader.js - Jquery File Uploader - 0.1
* http://www.daniel.com.uy/projects/jquery-file-uploader/
*
* Copyright (c) 2013 Daniel Morales
* Dual licensed under the MIT and GPL licenses.
* http://www.daniel.com.uy/doc/license/
*/
(function($) {
var pluginName = 'dmUploader';
// These are the plugin defaults values
var defaults = {
url: document.URL,
method: 'POST',
extraData: {},
maxFileSize: 0,
maxFiles: 0,
allowedTypes: '*',
extFilter: null,
dataType: null,
fileName: 'file',
onInit: function(){},
onFallbackMode: function(message) {},
onNewFile: function(id, file){},
onBeforeUpload: function(id){},
onComplete: function(){},
onUploadProgress: function(id, percent){},
onUploadSuccess: function(id, data){},
onUploadError: function(id, message){},
onFileTypeError: function(file){},
onFileSizeError: function(file){},
onFileExtError: function(file){},
onFilesMaxError: function(file){}
};
var DmUploader = function(element, options)
{
this.element = $(element);
this.settings = $.extend({}, defaults, options);
if(!this.checkBrowser()){
return false;
}
this.init();
return true;
};
DmUploader.prototype.checkBrowser = function()
{
if(window.FormData === undefined){
this.settings.onFallbackMode.call(this.element, 'Browser doesn\'t support Form API');
return false;
}
if(this.element.find('input[type=file]').length > 0){
return true;
}
if (!this.checkEvent('drop', this.element) || !this.checkEvent('dragstart', this.element)){
this.settings.onFallbackMode.call(this.element, 'Browser doesn\'t support Ajax Drag and Drop');
return false;
}
return true;
};
DmUploader.prototype.checkEvent = function(eventName, element)
{
var element = element || document.createElement('div');
var eventName = 'on' + eventName;
var isSupported = eventName in element;
if(!isSupported){
if(!element.setAttribute){
element = document.createElement('div');
}
if(element.setAttribute && element.removeAttribute){
element.setAttribute(eventName, '');
isSupported = typeof element[eventName] == 'function';
if(typeof element[eventName] != 'undefined'){
element[eventName] = undefined;
}
element.removeAttribute(eventName);
}
}
element = null;
return isSupported;
};
DmUploader.prototype.init = function()
{
var widget = this;
widget.queue = new Array();
widget.queuePos = -1;
widget.queueRunning = false;
// -- Drag and drop event
widget.element.on('drop', function (evt){
evt.preventDefault();
var files = evt.originalEvent.dataTransfer.files;
widget.queueFiles(files);
});
//-- Optional File input to make a clickable area
widget.element.find('input[type=file]').on('change', function(evt){
var files = evt.target.files;
widget.queueFiles(files);
$(this).val('');
});
this.settings.onInit.call(this.element);
};
DmUploader.prototype.queueFiles = function(files)
{
var j = this.queue.length;
for (var i= 0; i < files.length; i++)
{
var file = files[i];
// Check file size
if((this.settings.maxFileSize > 0) &&
(file.size > this.settings.maxFileSize)){
this.settings.onFileSizeError.call(this.element, file);
continue;
}
// Check file type
if((this.settings.allowedTypes != '*') &&
!file.type.match(this.settings.allowedTypes)){
this.settings.onFileTypeError.call(this.element, file);
continue;
}
// Check file extension
if(this.settings.extFilter != null){
var extList = this.settings.extFilter.toLowerCase().split(';');
var ext = file.name.toLowerCase().split('.').pop();
if($.inArray(ext, extList) < 0){
this.settings.onFileExtError.call(this.element, file);
continue;
}
}
// Check max files
if(this.settings.maxFiles > 0) {
if(this.queue.length >= this.settings.maxFiles) {
this.settings.onFilesMaxError.call(this.element, file);
continue;
}
}
this.queue.push(file);
var index = this.queue.length - 1;
this.settings.onNewFile.call(this.element, index, file);
}
// Only start Queue if we haven't!
if(this.queueRunning){
return false;
}
// and only if new Failes were successfully added
if(this.queue.length == j){
return false;
}
this.processQueue();
return true;
};
DmUploader.prototype.processQueue = function()
{
var widget = this;
widget.queuePos++;
if(widget.queuePos >= widget.queue.length){
// Cleanup
widget.settings.onComplete.call(widget.element);
// Wait until new files are droped
widget.queuePos = (widget.queue.length - 1);
widget.queueRunning = false;
return;
}
var file = widget.queue[widget.queuePos];
// Form Data
var fd = new FormData();
fd.append(widget.settings.fileName, file);
// Return from client function (default === undefined)
var can_continue = widget.settings.onBeforeUpload.call(widget.element, widget.queuePos);
// If the client function doesn't return FALSE then continue
if( false === can_continue ) {
return;
}
// Append extra Form Data
$.each(widget.settings.extraData, function(exKey, exVal){
fd.append(exKey, exVal);
});
widget.queueRunning = true;
// Ajax Submit
$.ajax({
url: widget.settings.url,
type: widget.settings.method,
dataType: widget.settings.dataType,
data: fd,
cache: false,
contentType: false,
processData: false,
forceSync: false,
xhr: function(){
var xhrobj = $.ajaxSettings.xhr();
if(xhrobj.upload){
xhrobj.upload.addEventListener('progress', function(event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total || event.totalSize;
if(event.lengthComputable){
percent = Math.ceil(position / total * 100);
}
widget.settings.onUploadProgress.call(widget.element, widget.queuePos, percent);
}, false);
}
return xhrobj;
},
success: function (data, message, xhr){
widget.settings.onUploadSuccess.call(widget.element, widget.queuePos, data);
},
error: function (xhr, status, errMsg){
widget.settings.onUploadError.call(widget.element, widget.queuePos, errMsg);
},
complete: function(xhr, textStatus){
widget.processQueue();
}
});
}
$.fn.dmUploader = function(options){
return this.each(function(){
if(!$.data(this, pluginName)){
$.data(this, pluginName, new DmUploader(this, options));
}
});
};
// -- Disable Document D&D events to prevent opening the file on browser when we drop them
$(document).on('dragenter', function (e) { e.stopPropagation(); e.preventDefault(); });
$(document).on('dragover', function (e) { e.stopPropagation(); e.preventDefault(); });
$(document).on('drop', function (e) { e.stopPropagation(); e.preventDefault(); });
})(jQuery);

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<openerp>
<data>
<!-- Assets inclusion -->
<template id="web_image_uploader_assets"
inherit_id="web.assets_common" name="Mass Image Upload Editor">
<xpath expr="." position="inside">
<script type="text/javascript"
src="/web_image_uploader/static/src/js/dmuploader.js"></script>
</xpath>
</template>
<template id="mass_upload_page" name="Mass Image Upload Page">
<t t-call="web.assets_common"/>
<t t-call="web.assets_backend"/>
<div style="padding:50px;">
<form action="demo_form.asp">
Enter the name of the field which matches the filename e.g. field 'pin' with value 138 matches up with 138.jpg<br/>
<b>Mapping Field</b> <input type="textbox" id="mapField" /><br/>
<input id="mass_image_upload_input" name="mass_image_upload_input[]" type="file" multiple="multiple" accept="image/*" /><br/>
<br/>
<input type="button" id="mass_image_upload_button" value="Upload"/><br/>
<b>Currently Complete: </b><span id="complete_count"></span>
</form>
<br/>
<br/>
<div id="logdiv" style="float:left;width:50%;">
<b>Log</b><br/>
<textarea id="massimageuploadsuccess" style="width:90%;height:500px;"/>
</div>
<div id="errordiv" style="float:right;width:50%">
<b>Errors</b><br/>
<textarea id="massimageuploaderror" style="width:100%;height:500px;"/>
</div>
</div>
</template>
</data>
</openerp>

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Author: Naresh Soni
# Copyright 2015 Cozy Business Solutions Pvt.Ltd
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import controllers

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Author: Naresh Soni
# Copyright 2015 Cozy Business Solutions Pvt.Ltd
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Web Multi Uploader',
'version': '0.1',
'author': 'Cozy Business Solutions Pvt.Ltd.',
'category': 'Tools',
'description': """
This module enables you to upload multiple files as attachments at once
from top menu and chatter attachment.
==================================
""",
'version': '1.0',
'depends': ['web'],
'data': [
'views/web_multi_uploader.xml',
],
'qweb': [
"static/src/xml/web_multi_uploader.xml",
],
'auto_install': False,
}

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Author: Naresh Soni
# Copyright 2015 Cozy Business Solutions Pvt.Ltd
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import main

View File

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Author: Naresh Soni
# Copyright 2015 Cozy Business Solutions Pvt.Ltd
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base64
import logging
import simplejson
import openerp
from openerp.addons.web import http
from openerp.http import request
from openerp.addons.web.controllers.main import serialize_exception, Home
logger = logging.getLogger(__name__)
class Uplodear(Home):
@http.route('/web/binary/upload_multi_attachment', type='http', auth="user")
@serialize_exception
def upload_attachment(self, callback, model, id, ufile):
files = http.request.httprequest.files.getlist('ufile')
Model = request.session.model('ir.attachment')
out = """<script language="javascript" type="text/javascript">
var win = window.top.window;
win.jQuery(win).trigger(%s, %s);
</script>"""
try:
args = {}
for ufile in files:
attachment_id = Model.create({
'name': ufile.filename,
'datas': base64.encodestring(ufile.read()),
'datas_fname': ufile.filename,
'res_model': model,
'res_id': int(id)
}, request.context)
args[attachment_id] = ufile.filename
except Exception:
args = {'error': "Something horrible happened"}
logger.exception("Fail to upload attachment %s" % ufile.filename)
return out % (simplejson.dumps(callback), simplejson.dumps(args))

View File

@ -0,0 +1,68 @@
openerp.web_multi_uploader = function(session) {
var mail = session.mail;
session.mail.ThreadComposeMessage.include({
on_attachment_change: function (event) {
event.stopPropagation();
var self = this;
var $target = $(event.target);
if ($target.val() !== '') {
var filename = $target.val().replace(/.*[\\\/]/,'');
// if the files exits for this answer, delete the file before upload
var attachments=[];
for (var i in this.attachment_ids) {
if ((this.attachment_ids[i].filename || this.attachment_ids[i].name) == filename) {
if (this.attachment_ids[i].upload) {
return false;
}
this.ds_attachment.unlink([this.attachment_ids[i].id]);
} else {
attachments.push(this.attachment_ids[i]);
}
}
this.attachment_ids = attachments;
// submit file
this.$('form.oe_form_binary_form').submit();
this.$(".oe_attachment_file").hide();
var target = $target.get(0);
_.each(target.files, function(file){
self.attachment_ids.push({
'id': 0,
'name': file.name,
'filename': file.name,
'url': '',
'upload': true
});
});
this.display_attachments();
}
},
on_attachment_loaded: function (event, result) {
if (result.erorr) {
this.do_warn( session.web.qweb.render('mail.error_upload'), result.error);
this.attachment_ids = _.filter(this.attachment_ids, function (val) { return !val.upload; });
} else {
for (var i in this.attachment_ids) {
if (_.contains(_.values(result), this.attachment_ids[i].filename) && this.attachment_ids[i].upload) {
var filename = this.attachment_ids[i].filename;
var id = _.invert(result)[filename];
this.attachment_ids[i]={
'id': id,
'name': filename,
'filename': filename,
'url': mail.ChatterUtils.get_attachment_url(this.session, this.id, id)
};
}
}
}
this.display_attachments();
var $input = this.$('input.oe_form_binary_file');
$input.after($input.clone(true)).remove();
this.$(".oe_attachment_file").show();
},
});
};

View File

@ -0,0 +1,46 @@
<template>
<t t-name="HiddenInputMultiFile">
<div t-attf-class="oe_hidden_input_file #{fileupload_class or ''}" t-att-style="fileupload_style">
<form class="oe_form_binary_form" t-att-target="fileupload_id"
method="post" enctype="multipart/form-data" t-att-action="fileupload_action || '/web/binary/upload'">
<input type="hidden" name="session_id" value="" t-if="widget.session.override_session"/>
<input type="hidden" name="callback" t-att-value="fileupload_id"/>
<t t-raw="0"/>
<input type="file" class="oe_form_binary_file" multiple="multiple" name="ufile" t-if="widget.widget!='image'"/>
<input type="file" class="oe_form_binary_file" name="ufile" accept="image/*" t-if="widget.widget=='image'"/>
</form>
<iframe t-att-id="fileupload_id" t-att-name="fileupload_id" style="display: none"/>
</div>
</t>
<t t-extend="Sidebar">
<t t-jquery="li.oe_sidebar_add_attachment" t-operation="replace">
<li t-if="widget.view.is_action_enabled('edit') &amp;&amp; section.name == 'files'" class="oe_sidebar_add_attachment">
<t t-call="HiddenInputMultiFile">
<t t-set="fileupload_id" t-value="widget.fileupload_id"/>
<t t-set="fileupload_action" t-translation="off">/web/binary/upload_multi_attachment</t>
<input type="hidden" name="model" t-att-value="widget.dataset and widget.dataset.model"/>
<input type="hidden" name="id" t-att-value="widget.model_id"/>
<input type="hidden" name="session_id" t-att-value="widget.session.session_id" t-if="widget.session.override_session"/>
<span>Add...</span>
</t>
</li>
</t>
</t>
<t t-extend="mail.compose_message.add_attachment">
<t t-jquery="span.oe_add" t-operation="replace">
<span class="oe_add">
<button class="oe_attach"><span class="oe_e">'</span></button>
<span class='oe_attach_label'>Attach a File</span>
<t t-call="HiddenInputMultiFile">
<t t-set="fileupload_id" t-value="widget.fileupload_id"/>
<t t-set="fileupload_action" t-translation="off">/web/binary/upload_multi_attachment</t>
<input type="hidden" name="model" value="mail.compose.message"/>
<input type="hidden" name="id" value="0"/>
<input type="hidden" name="session_id" t-att-value="widget.session.session_id"/>
</t>
</span>
</t>
</t>
</template>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<template id="assets_backend" name="web_mulit_uploader assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_multi_uploader/static/src/js/web_mulit_uploader.js"></script>
</xpath>
</template>
</data>
</openerp>