[FIX] Brought back attachments

bzr revid: fme@openerp.com-20120613141016-8m2mj4b7d9zzk7a5
This commit is contained in:
Fabien Meghazi
2012-06-13 16:10:16 +02:00
parent 1ce9ec0718
commit 8401b686b6
4 changed files with 67 additions and 50 deletions
+23
View File
@@ -1097,6 +1097,29 @@
.openerp .oe_sidebar {
white-space: nowrap;
}
.openerp .oe_sidebar .oe_sidebar_add_attachment {
cursor: pointer;
padding-left: 6px;
margin-top: 6px;
}
.openerp .oe_sidebar .oe_sidebar_add_attachment span {
font-weight: bold;
}
.openerp .oe_sidebar .oe_sidebar_add_attachment .oe_hidden_input_file {
width: 200px;
}
.openerp .oe_sidebar .oe_sidebar_add_attachment:hover {
background-color: #f0f0fa;
background-image: -webkit-gradient(linear, left top, left bottom, from(#f0f0fa), to(#eeeef6));
background-image: -webkit-linear-gradient(top, #f0f0fa, #eeeef6);
background-image: -moz-linear-gradient(top, #f0f0fa, #eeeef6);
background-image: -ms-linear-gradient(top, #f0f0fa, #eeeef6);
background-image: -o-linear-gradient(top, #f0f0fa, #eeeef6);
background-image: linear-gradient(to bottom, #f0f0fa, #eeeef6);
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
.openerp .oe_searchview {
cursor: text;
position: relative;
+11
View File
@@ -877,6 +877,17 @@ $colour4: #8a89ba
@include box-shadow(none)
.oe_sidebar
white-space: nowrap
.oe_sidebar_add_attachment
cursor: pointer
padding-left: 6px
margin-top: 6px
span
font-weight: bold
.oe_hidden_input_file
width: 200px
&:hover
@include vertical-gradient(#f0f0fa, #eeeef6)
@include box-shadow(none)
// }}}
// SearchView {{{
.oe_searchview
+19 -12
View File
@@ -696,6 +696,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({
instance.web.Sidebar = instance.web.Widget.extend({
init: function(parent) {
var self = this;
this._super(parent);
var view = this.getParent();
this.sections = [
@@ -712,6 +713,16 @@ instance.web.Sidebar = instance.web.Widget.extend({
var item = { label: _t("Translate"), callback: view.on_sidebar_translate, title: _t("Technical translation") };
this.items.other.push(item);
}
this.fileupload_id = _.uniqueId('oe_fileupload');
$(window).on(this.fileupload_id, function() {
var args = [].slice.call(arguments).slice(1);
if (args[0] && args[0].error) {
alert(args[0].error);
} else {
self.do_attachement_update(self.dataset, self.model_id);
}
$.unblockUI();
});
},
start: function() {
var self = this;
@@ -735,9 +746,6 @@ instance.web.Sidebar = instance.web.Widget.extend({
}
return false;
});
//this.$div.html(QWeb.render('FormView.sidebar.attachments', this));
//this.$element.find('.oe-binary-file').change(this.on_attachment_changed);
//this.$element.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete);
},
redraw: function() {
var self = this;
@@ -826,6 +834,8 @@ instance.web.Sidebar = instance.web.Widget.extend({
});
},
do_attachement_update: function(dataset, model_id) {
this.dataset = dataset;
this.model_id = model_id;
if (!model_id) {
this.on_attachments_loaded([]);
} else {
@@ -837,29 +847,26 @@ instance.web.Sidebar = instance.web.Widget.extend({
on_attachments_loaded: function(attachments) {
var self = this;
var items = [];
// TODO: preprend: _s +
var prefix = '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=name&id=';
var prefix = this.session.origin + '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=name&id=';
_.each(attachments,function(a) {
a.label = a.name;
if(a.type === "binary") {
a.url = prefix + a.id + '&t=' + (new Date().getTime());
}
});
attachments.push( { label: _t("Add..."), callback: self.on_attachment_add } );
self.items['files'] = attachments;
self.redraw();
},
on_attachment_add: function(e) {
this.$element.find('.oe_sidebar_add').show();
this.$('.oe_sidebar_add_attachment .oe-binary-file').change(this.on_attachment_changed);
//this.$element.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete);
},
on_attachment_changed: function(e) {
return;
window[this.element_id + '_iframe'] = this.do_update;
var $e = $(e.target);
if ($e.val() != '') {
if ($e.val() !== '') {
this.$element.find('form.oe-binary-form').submit();
$e.parent().find('input[type=file]').prop('disabled', true);
$e.parent().find('button').prop('disabled', true).find('img, span').toggle();
this.$('.oe_sidebar_add_attachment span').text(_t('Uploading...'));
$.blockUI();
}
},
on_attachment_delete: function(e) {
+14 -38
View File
@@ -517,49 +517,25 @@
<a class="oe_sidebar_action_a" t-att-title="item.title" t-att-data-section="section.name" t-att-data-index="item_index" t-att-href="item.url" target="_blank">
<t t-raw="item.label"/>
</a>
<!--<a href="#" class="oe-sidebar-attachment-delete" t-att-data-id="attachment.id" t-attf-title="Delete the attachment #{attachment.name}">
<img t-att-src='_s + "/web/static/src/img/attachments-close.png"' width="15" height="15" border="0"/>
</a>-->
</li>
<li t-if="section.name == 'files'" class="oe_sidebar_add" style="display:none;">
Input type file stuff
<li t-if="section.name == 'files'" class="oe_sidebar_add_attachment">
<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.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"/>
<span>Add...</span>
</t>
</li>
</ul>
</div>
</t>
</div>
</t>
<t t-name="Sidebar.attachments">
<div class="oe-sidebar-attachments-toolbar">
<div class="oe_hidden_input_file" style="float: right">
<form class="oe-binary-form" t-attf-target="#{element_id}_iframe"
method="post" enctype="multipart/form-data" action="/web/binary/upload_attachment">
<input type="hidden" name="session_id" t-att-value="session.session_id"/>
<input type="hidden" name="callback" t-attf-value="#{element_id}_iframe"/>
<input type="hidden" name="model" t-att-value="view.dataset.model"/>
<input type="hidden" name="id" t-att-value="view.datarecord.id"/>
<button class="oe_button" type="button">
<img t-att-src='_s + "/web/static/src/img/throbber.gif"' width="16" height="16" style="display: none"/>
<span>Add</span>
</button>
<input type="file" class="oe-binary-file" name="ufile" title="Add attachment"
t-att-onclick="view.datarecord.id ? null : 'alert(\'No record selected ! You can only attach to existing record.\'); return false;'"/>
</form>
<iframe t-attf-id="#{element_id}_iframe" t-attf-name="#{element_id}_iframe" style="display: none"/>
</div>
</div>
<br style="clear: both"/>
<ul class="oe-sidebar-attachments-items">
<li t-foreach="attachments" t-as="attachment">
<t t-if="attachment.type == 'binary'" t-set="attachment.url" t-value="_s + '/web/binary/saveas?session_id='
+ session.session_id + '&amp;model=ir.attachment&amp;id=' + attachment.id
+ '&amp;field=datas&amp;filename_field=name&amp;t=' + (new Date().getTime())"/>
<a class="oe-sidebar-attachments-link" t-att-href="attachment.url" target="_blank">
<t t-esc="attachment.name"/>
</a>
<a href="#" class="oe-sidebar-attachment-delete" t-att-data-id="attachment.id" t-attf-title="Delete the attachment #{attachment.name}">
<img t-att-src='_s + "/web/static/src/img/attachments-close.png"' width="15" height="15" border="0"/>
</a>
</li>
</ul>
</t>
<t t-name="TreeView">
<select t-if="toolbar" style="width: 30%">
@@ -1128,9 +1104,9 @@
</t>
</t>
<t t-name="HiddenInputFile">
<div class="oe_hidden_input_file" t-att-style="fileupload_style">
<div t-attf-class="oe_hidden_input_file #{fileupload_class or ''}" t-att-style="fileupload_style">
<form class="oe-binary-form" t-att-target="fileupload_id"
method="post" enctype="multipart/form-data" action="/web/binary/upload">
method="post" enctype="multipart/form-data" t-att-action="fileupload_action || '/web/binary/upload'">
<input type="hidden" name="session_id" value=""/>
<input type="hidden" name="callback" t-att-value="fileupload_id"/>
<t t-raw="__content__"/>