[IMP] mail: attachment
bzr revid: chm@openerp.com-20121009132824-dsl7f02hxfpypc0w
This commit is contained in:
parent
52f8ea85c8
commit
2e4a6953c4
|
@ -349,10 +349,10 @@ class mail_message(osv.Model):
|
|||
attachment = self.pool.get('ir.attachment')
|
||||
attachment_ids = attachment.search(cr, uid, [('res_model','=',''),('create_uid','=',uid)])
|
||||
if len(attachment_ids):
|
||||
attachment_list = [{'id': attach[0], 'name': attach[1]} for attach in attachment.name_get(cr, uid, attachment_ids, context=context)]
|
||||
attachment_list = [{'id': attach.id, 'name': attach.name, 'date': attach.create_date} for attach in attachment.browse(cr, uid, attachment_ids, context=context)]
|
||||
|
||||
return attachment_list
|
||||
|
||||
|
||||
#------------------------------------------------------
|
||||
# Email api
|
||||
#------------------------------------------------------
|
||||
|
|
|
@ -391,7 +391,25 @@
|
|||
}
|
||||
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments li {
|
||||
float: none;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style-type: square;
|
||||
}
|
||||
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments .oe_upload_in_process {
|
||||
float: right;
|
||||
width: 200px;
|
||||
height: 16px;
|
||||
}
|
||||
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments .oe_upload_in_process div {
|
||||
float: left;
|
||||
width: 38px;
|
||||
height: 16px;
|
||||
margin-right: 2px;
|
||||
background: #66FF66;
|
||||
}
|
||||
.openerp .oe_mail_msg_content ul.oe_mail_msg_attachments .oe_upload_in_process span {
|
||||
color: #aaaaaa;
|
||||
position: absolute;
|
||||
}
|
|
@ -114,6 +114,8 @@ openerp.mail = function(session) {
|
|||
|
||||
this.parent_thread= parent.messages!= undefined ? parent : false;
|
||||
|
||||
|
||||
this.ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment');
|
||||
this.fileupload_id = _.uniqueId('oe_fileupload_temp');
|
||||
$(window).on(self.fileupload_id, self.on_attachment_loaded);
|
||||
},
|
||||
|
@ -148,12 +150,16 @@ openerp.mail = function(session) {
|
|||
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].url == $target.val()){
|
||||
var ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment');
|
||||
ds_attachment.unlink([this.attachment_ids.id]);
|
||||
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]);
|
||||
}
|
||||
|
@ -161,22 +167,87 @@ openerp.mail = function(session) {
|
|||
this.attachment_ids = attachments;
|
||||
|
||||
// submit file
|
||||
session.web.blockUI();
|
||||
var form = self.$('form.oe_form_binary_form');
|
||||
form.submit();
|
||||
$target.after($target.clone(true)).remove();
|
||||
//session.web.blockUI();
|
||||
self.$('form.oe_form_binary_form').submit();
|
||||
//self.submit_ajax_attachment();
|
||||
|
||||
this.$(".oe_attachment_file").hide();
|
||||
|
||||
this.attachment_ids.push({
|
||||
'id': 0,
|
||||
'name': filename,
|
||||
'filename': filename,
|
||||
'url': '',
|
||||
'upload': true
|
||||
});
|
||||
this.display_attachments();
|
||||
}
|
||||
},
|
||||
on_attachment_loaded: function (event, result) {
|
||||
session.web.unblockUI();
|
||||
this.attachment_ids.push({
|
||||
'id': result.id,
|
||||
'name': '',
|
||||
'filename': result.filename,
|
||||
'url': mail.ChatterUtils.get_attachment_url(this.session, result)
|
||||
|
||||
submit_ajax_attachment: function(){
|
||||
var self=this;
|
||||
var $form = self.$('form.oe_form_binary_form');
|
||||
var filename = this.$('input.oe_form_binary_file').val().replace(/.*[\\\/]/,'');
|
||||
|
||||
// create form data
|
||||
var fomdata = new FormData();
|
||||
$.each($form.find('input'), function(i, field) {
|
||||
var $field=$(field);
|
||||
if($field.attr('type')!='file'){
|
||||
fomdata.append($field.attr('name'), $field.val());
|
||||
} else {
|
||||
fomdata.append($field.attr('name'), field.files[0]);
|
||||
}
|
||||
});
|
||||
this.$('input.oe_form_binary_file').empty();
|
||||
|
||||
var progress=function(event) {
|
||||
console.log('xhr progress :', Math.floor(event.loaded / event.total*100), event);
|
||||
self.$("span[name='"+filename+"'] div:lt("+Math.floor(event.loaded / event.total*5)+")").show();
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: $form.attr("action"),
|
||||
data: fomdata,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
type: 'POST',
|
||||
enctype: 'multipart/form-data',
|
||||
xhr: function() {
|
||||
// custom xhr
|
||||
myXhr = $.ajaxSettings.xhr();
|
||||
if(myXhr.upload){
|
||||
// for handling the progress of the upload
|
||||
myXhr.upload.addEventListener('progress', progress, false);
|
||||
}
|
||||
myXhr.addEventListener('progress', progress, false);
|
||||
return myXhr;
|
||||
},
|
||||
success: function(data){
|
||||
$iframe=$('<iframe style="display:none;"/>').html(data);
|
||||
$iframe.appendTo(self.$el);
|
||||
$iframe.remove();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
on_attachment_loaded: function (event, result) {
|
||||
//session.web.unblockUI();
|
||||
for(var i in this.attachment_ids){
|
||||
if(this.attachment_ids[i].filename == result.filename && this.attachment_ids[i].upload){
|
||||
this.attachment_ids[i]={
|
||||
'id': result.id,
|
||||
'name': result.name,
|
||||
'filename': result.filename,
|
||||
'url': mail.ChatterUtils.get_attachment_url(this.session, result)
|
||||
};
|
||||
}
|
||||
}
|
||||
this.display_attachments();
|
||||
|
||||
var $input = this.$('input.oe_form_binary_file');
|
||||
$input.after($input.clone(true)).remove();
|
||||
this.$(".oe_attachment_file").show();
|
||||
},
|
||||
/* unlink the file on the server and reload display
|
||||
*/
|
||||
|
@ -190,8 +261,7 @@ openerp.mail = function(session) {
|
|||
attachments.push(this.attachment_ids[i]);
|
||||
}
|
||||
else {
|
||||
var ds_attachment = new session.web.DataSetSearch(this, 'ir.attachment');
|
||||
ds_attachment.unlink([attachment_id]);
|
||||
this.ds_attachment.unlink([attachment_id]);
|
||||
}
|
||||
}
|
||||
this.attachment_ids = attachments;
|
||||
|
@ -199,10 +269,21 @@ openerp.mail = function(session) {
|
|||
}
|
||||
},
|
||||
|
||||
/* to avoid having unsorted file on the server.
|
||||
we will show the users files of the first message post
|
||||
*/
|
||||
set_free_attachments: function(){
|
||||
var self=this;
|
||||
this.parent_thread.ds_message.call('user_free_attachment').then(function(attachments){
|
||||
self.attachment_ids=attachments;
|
||||
this.attachment_ids=[];
|
||||
for(var i in attachments){
|
||||
self.attachment_ids[i]={
|
||||
'id': attachments[i].id,
|
||||
'name': attachments[i].name,
|
||||
'filename': attachments[i].filename,
|
||||
'url': mail.ChatterUtils.get_attachment_url(self.session, attachments[i])
|
||||
};
|
||||
}
|
||||
self.display_attachments();
|
||||
});
|
||||
},
|
||||
|
@ -246,7 +327,7 @@ openerp.mail = function(session) {
|
|||
event.stopPropagation();
|
||||
this.$('textarea').val("");
|
||||
this.$('input[data-id]').remove();
|
||||
this.attachment_ids=[];
|
||||
//this.attachment_ids=[];
|
||||
this.display_attachments();
|
||||
if(!this.options.thread.show_header_compose || !this.options.thread.display_on_flat){
|
||||
this.$el.hide();
|
||||
|
@ -261,20 +342,22 @@ openerp.mail = function(session) {
|
|||
var body = comment_node.val();
|
||||
comment_node.val('');
|
||||
}
|
||||
if(body.match(/\S+/)) {
|
||||
|
||||
var attachments=[];
|
||||
for(var i in this.attachment_ids){
|
||||
attachments.push(this.attachment_ids[i].id);
|
||||
var attachments=[];
|
||||
for(var i in this.attachment_ids){
|
||||
if(this.attachment_ids[i].upload){
|
||||
session.web.dialog($('<div>' + session.web.qweb.render('CrashManager.warning', {message: 'Please, wait while the file is uploading.'}) + '</div>'));
|
||||
return false;
|
||||
}
|
||||
attachments.push(this.attachment_ids[i].id);
|
||||
}
|
||||
|
||||
if(body.match(/\S+/)) {
|
||||
this.parent_thread.ds_thread.call('message_post_api', [
|
||||
this.context.default_res_id, body, false, 'comment', false, this.context.default_parent_id, attachments])
|
||||
.then(this.parent_thread.proxy('switch_new_message'));
|
||||
this.on_cancel();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -58,8 +58,21 @@
|
|||
<ul t-attf-class="oe_mail_msg_attachments #{widget.attachment_ids[0] and widget.options.thread.show_attachment_link?'':'oe_hidden'}">
|
||||
<t t-foreach="widget.attachment_ids" t-as="attachment">
|
||||
<li>
|
||||
<a t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a>
|
||||
<t t-if="widget.options.thread.show_attachment_delete">
|
||||
<span t-if="(attachment.upload or attachment.percent_loaded<100)" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}" t-attf-name="{attachment.name || attachment.filename}">
|
||||
<div class="oe_upload_in_process">
|
||||
<span>...wait upload...</span>
|
||||
<div t-attf-style="{attachment.percent_loaded>0?'':'display:none;'}"/>
|
||||
<div t-attf-style="{attachment.percent_loaded>20?'':'display:none;'}"/>
|
||||
<div t-attf-style="{attachment.percent_loaded>40?'':'display:none;'}"/>
|
||||
<div t-attf-style="{attachment.percent_loaded>60?'':'display:none;'}"/>
|
||||
<div t-attf-style="{attachment.percent_loaded>80?'':'display:none;'}"/>
|
||||
</div>
|
||||
<t t-raw="attachment.name || attachment.filename"/>
|
||||
</span>
|
||||
<a t-if="(!attachment.upload or attachment.percent_loaded>=100)" t-att-href="attachment.url" t-attf-title="{(attachment.name || attachment.filename) + (attachment.date?' \n('+attachment.date+')':'' )}">
|
||||
<t t-raw="attachment.name || attachment.filename"/>
|
||||
</a>
|
||||
<t t-if="widget.options.thread.show_attachment_delete and (!attachment.upload or attachment.percent_loaded>=100)">
|
||||
<a class="oe_right oe_mail_attachment_delete" title="Delete this attachmentt" t-attf-data-id="{attachment.id}">x</a>
|
||||
</t>
|
||||
|
||||
|
@ -68,7 +81,6 @@
|
|||
</ul>
|
||||
</t>
|
||||
|
||||
|
||||
<t t-name="mail.thread.message.private">
|
||||
<div>
|
||||
<span class="oe_placeholder_checkbox_private"/>
|
||||
|
|
Loading…
Reference in New Issue