[ADD] Added attachments in sidebar

bzr revid: fme@openerp.com-20110526213811-jxj5mdshq8v4sbfj
This commit is contained in:
Fabien Meghazi 2011-05-26 23:38:11 +02:00
parent e3eb23b96c
commit 7bf4a4d9e0
5 changed files with 138 additions and 20 deletions

View File

@ -666,7 +666,7 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
}
.openerp .button span {
position: relative;
top: -3px;
vertical-align: top;
}
.openerp input.field_date, .openerp input.field_datetime {
background: #fff url('../img/ui/field_calendar.png') no-repeat right center;
@ -793,6 +793,41 @@ background: linear-gradient(top, #ffffff 0%,#d8d8d8 11%,#afafaf 86%,#333333 91%,
color: black;
}
.openerp .oe-sidebar-attachments-toolbar {
margin: 4px 0 0 4px;
}
.openerp .oe-sidebar-attachments-items {
clear: both;
padding-top: 5px !important;
}
.openerp .oe-sidebar-attachments-items li {
position: relative;
padding: 0 0 3px 10px !important;
}
.openerp .oe-sidebar-attachments-items li:hover {
background: #ddd;
}
.openerp .oe-sidebar-attachments-link {
display: block;
margin-right: 15px;
overflow: hidden;
}
.openerp .oe-sidebar-attachment-delete {
position: absolute;
right: 2px;
top: 1px;
overflow: hidden;
width: 15px;
height: 15px;
padding: 1px;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
}
.openerp .oe-sidebar-attachment-delete:hover {
background-color: white;
}
.openerp .view-manager-main-sidebar h2 {
margin:0;
font-family: Ubuntu, Helvetica, sans-serif;

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

View File

@ -57,7 +57,6 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
this.$element.find('#' + this.element_id + '_header button.oe_form_button_new').click(this.on_button_new);
this.view_manager.sidebar.set_toolbar(data.fields_view.toolbar);
this.view_manager.sidebar.do_refresh.add_last(this.on_sidebar_refreshed);
},
do_show: function () {
var self = this;
@ -99,6 +98,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
this.log("No record received");
}
this.do_update_pager(record.id == null);
this.do_update_sidebar();
},
on_form_changed: function(widget) {
if (widget && widget.node.attrs.on_change) {
@ -288,6 +288,7 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
this.dataset.index = this.dataset.ids.length - 1;
this.dataset.count++;
this.do_update_pager();
this.do_update_sidebar();
this.notification.notify("Record created", "The record has been created with id #" + this.datarecord.id);
if (success) {
success(r);
@ -303,9 +304,49 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV
do_cancel: function () {
this.notification.notify("Cancelling form");
},
on_sidebar_refreshed: function(new_view) {
var sidebar = this.view_manager.sidebar;
// TODO: Add attachment WIP
do_update_sidebar: function() {
if (this.view_manager.action.flags.sidebar === false) {
return;
}
if (!this.datarecord.id) {
this.on_attachments_loaded([]);
} else {
this.rpc('/base/dataset/search_read', {
model: 'ir.attachment',
fields: ['name', 'url', 'type'],
domain: [['res_model', '=', this.dataset.model], ['res_id', '=', this.datarecord.id], ['type', 'in', ['binary', 'url']]],
context: this.dataset.context
}, this.on_attachments_loaded);
}
},
on_attachments_loaded: function(attachments) {
this.$sidebar = this.view_manager.sidebar.$element.find('.sidebar-attachments');
this.attachments = attachments;
this.$sidebar.html(QWeb.render('FormView.sidebar.attachments', this));
this.$sidebar.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete);
this.$sidebar.find('.oe-binary-file').change(this.on_attachment_changed);
},
on_attachment_changed: function(e) {
window[this.element_id + '_iframe'] = this.do_update_sidebar;
var $e = $(e.target);
if ($e.val() != '') {
this.$sidebar.find('form.oe-binary-form').submit();
$e.parent().find('input[type=file]').attr('disabled', 'true');
$e.parent().find('button').attr('disabled', 'true').find('img, span').toggle();
}
},
on_attachment_delete: function(e) {
var self = this, $e = $(e.currentTarget);
var name = _.trim($e.parent().find('a.oe-sidebar-attachments-link').text());
if (confirm("Do you really want to delete the attachment " + name + " ?")) {
this.rpc('/base/dataset/unlink', {
model: 'ir.attachment',
ids: [parseInt($e.attr('data-id'))]
}, function(r) {
$e.parent().remove();
self.notification.notify("Delete an attachment", "The attachment '" + name + "' has been deleted");
});
}
},
reload: function() {
if (this.datarecord.id) {
@ -1251,10 +1292,14 @@ openerp.base.form.FieldBinary = openerp.base.form.Field.extend({
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
},
on_save_as: function() {
var url = '/base/binary/saveas?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name +
'&fieldname=' + (this.node.attrs.filename || '') + '&t=' + (new Date().getTime())
window.open(url);
if (!this.view.datarecord.id) {
this.notification.warn("Can't save file", "The record has not yet been saved");
} else {
var url = '/base/binary/saveas?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name +
'&fieldname=' + (this.node.attrs.filename || '') + '&t=' + (new Date().getTime())
window.open(url);
}
},
on_clear: function() {
if (this.value !== false) {

View File

@ -317,7 +317,7 @@ openerp.base.Sidebar = openerp.base.BaseWidget.extend({
this.$element.removeClass('closed-sidebar');
}
this.$element.html(QWeb.render("ViewManager.sidebar.internal",this));
this.$element.html(QWeb.render("ViewManager.sidebar.internal", { sidebar: this, view: view }));
var self = this;
this.$element.find(".toggle-sidebar").click(function(e) {

View File

@ -267,6 +267,41 @@
</div>
<t t-raw="frame.render()"/>
</t>
<t t-name="FormView.sidebar.attachments">
<h2>Attachments</h2>
<div class="oe-sidebar-attachments-toolbar">
<div class="oe-binary-file-set" style="float: right">
<form class="oe-binary-form" t-attf-target="#{element_id}_iframe"
method="post" enctype="multipart/form-data" action="/base/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="dataset.model"/>
<input type="hidden" name="id" t-att-value="datarecord.id"/>
<button class="button" type="button">
<img src="/base/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="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"> </iframe>
</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="'/base/binary/saveas?session_id='
+ session.session_id + '&amp;model=ir.attachment&amp;id=' + attachment.id
+ '&amp;field=datas' + '&amp;fieldname=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 src="/base/static/src/img/attachments-close.png" width="15" height="15" border="0"/>
</a>
</li>
</ul>
</t>
<t t-name="Widget">
Unhandled widget
<t t-raw="console.log('Unhandled widget', widget)"/>
@ -699,16 +734,19 @@
<t t-name="ViewManager.sidebar.internal">
<a class="toggle-sidebar"></a>
<div class="sidebar-content">
<t t-foreach="sections" t-as="section" t-if="section.elements.length">
<h2><t t-esc="section.label"/></h2>
<ul>
<li t-foreach="section.elements" t-as="element">
<a class="oe_sidebar_action_a" t-attf-data-index="#{section_index}-#{element_index}" href="#">
<t t-esc="element.name"/>
</a>
</li>
</ul>
</t>
<div class="sidebar-attachments" t-if="view == 'form'"> </div>
<div class="sidebar-actions">
<t t-foreach="sidebar.sections" t-as="section" t-if="section.elements.length">
<h2><t t-esc="section.label"/></h2>
<ul>
<li t-foreach="section.elements" t-as="element">
<a class="oe_sidebar_action_a" t-attf-data-index="#{section_index}-#{element_index}" href="#">
<t t-esc="element.name"/>
</a>
</li>
</ul>
</t>
</div>
</div>
</t>
<t t-name="DialogWarning">