[IMP] Chatter: added option to delete attachments in composer.
bzr revid: tde@openerp.com-20120911161700-ty7h844h6f0t7nea
This commit is contained in:
parent
0ef0b3df61
commit
8aba3e0210
|
@ -410,3 +410,6 @@
|
|||
padding: 0;
|
||||
list-style-type: square;
|
||||
}
|
||||
.openerp .oe_mail_msg_content a.oe_mail_attachment_delete {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ openerp.mail = function(session) {
|
|||
this.options.context = options.context || {};
|
||||
this.options.form_xml_id = options.form_xml_id || 'email_compose_message_wizard_form_chatter';
|
||||
this.options.form_view_id = options.form_view_id || false;
|
||||
this.show_attachment_delete = true;
|
||||
},
|
||||
|
||||
start: function () {
|
||||
|
@ -157,20 +158,30 @@ openerp.mail = function(session) {
|
|||
var input_node = this.$el.find('input[name=ufile]');
|
||||
button_attach.detach().insertAfter(input_node);
|
||||
// set the function called when attachments are added
|
||||
this.$el.find('input.oe_form_binary_file').change(this.on_attachment_changed);
|
||||
this.$el.find('input.oe_form_binary_file').change(this.on_attachment_change);
|
||||
this.bind_events();
|
||||
this.form_view.do_show();
|
||||
},
|
||||
|
||||
/** Called when the user submits a new attachment */
|
||||
on_attachment_changed: function(e) {
|
||||
var $e = $(e.target);
|
||||
if ($e.val() !== '') {
|
||||
on_attachment_change: function (event) {
|
||||
var $target = $(event.target);
|
||||
if ($target.val() !== '') {
|
||||
this.$el.find('form.oe_form_binary_form').submit();
|
||||
session.web.blockUI();
|
||||
}
|
||||
},
|
||||
|
||||
on_attachment_delete: function (event) {
|
||||
if (event.target.dataset && event.target.dataset.id) {
|
||||
var attachment_id = parseInt(event.target.dataset.id);
|
||||
var idx = _.pluck(this.attachment_ids, 'id').indexOf(attachment_id);
|
||||
if (idx == -1) return false;
|
||||
new session.web.DataSetSearch(this, 'ir.attachment').unlink(attachment_id);
|
||||
this.attachment_ids.splice(idx, 1);
|
||||
this.display_attachments();
|
||||
}
|
||||
},
|
||||
|
||||
display_attachments: function () {
|
||||
var attach_node = this.$el.find('div.oe_mail_compose_message_attachments');
|
||||
var rendered = session.web.qweb.render('mail.thread.message.attachments', {'record': this});
|
||||
|
@ -205,10 +216,6 @@ openerp.mail = function(session) {
|
|||
* in the function. */
|
||||
bind_events: function() {
|
||||
var self = this;
|
||||
// event: click on 'Attachment' button that opens the dialog to add an attachment.
|
||||
this.$el.on('click', 'button.oe_mail_compose_message_attachment', function (event) {
|
||||
event.stopImmediatePropagation();
|
||||
});
|
||||
// event: add a new attachment
|
||||
$(window).on(this.fileupload_id, function() {
|
||||
var args = [].slice.call(arguments).slice(1);
|
||||
|
@ -218,6 +225,8 @@ openerp.mail = function(session) {
|
|||
self.display_attachments();
|
||||
session.web.unblockUI();
|
||||
});
|
||||
// event: delete an attachment
|
||||
this.$el.on('click', '.oe_mail_attachment_delete', self.on_attachment_delete);
|
||||
},
|
||||
}),
|
||||
|
||||
|
|
|
@ -169,7 +169,12 @@
|
|||
<t t-name="mail.thread.message.attachments">
|
||||
<ul class="oe_mail_msg_attachments">
|
||||
<t t-foreach="record.attachment_ids" t-as="attachment">
|
||||
<li><a t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a></li>
|
||||
<li>
|
||||
<a t-att-href="attachment.url"><t t-raw="attachment.name || attachment.filename"/></a>
|
||||
<t t-if="record.show_attachment_delete">
|
||||
<a class="oe_right oe_mail_attachment_delete" title="Delete this attachmentt" t-attf-data-id="{attachment.id}">x</a>
|
||||
</t>
|
||||
</li>
|
||||
</t>
|
||||
</ul>
|
||||
</t>
|
||||
|
|
Loading…
Reference in New Issue