[FIX] restore attachement, part1 read-only
bzr revid: al@openerp.com-20120417011933-wwkynkzpxex0lbbh
This commit is contained in:
parent
d71662bd7c
commit
c9cd4657af
|
@ -112,7 +112,6 @@ openerp.web.FormView = openerp.web.View.extend({
|
||||||
if (!this.sidebar && this.options.sidebar) {
|
if (!this.sidebar && this.options.sidebar) {
|
||||||
this.sidebar = new openerp.web.Sidebar(this);
|
this.sidebar = new openerp.web.Sidebar(this);
|
||||||
this.sidebar.appendTo(this.$sidebar);
|
this.sidebar.appendTo(this.$sidebar);
|
||||||
//this.sidebar.attachments = new openerp.web.form.SidebarAttachments(this.sidebar, this);
|
|
||||||
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
this.sidebar.add_toolbar(this.fields_view.toolbar);
|
||||||
this.sidebar.add_items('other', [{
|
this.sidebar.add_items('other', [{
|
||||||
label: _t('Set Default'),
|
label: _t('Set Default'),
|
||||||
|
@ -269,7 +268,7 @@ openerp.web.FormView = openerp.web.View.extend({
|
||||||
self.is_initialized.resolve();
|
self.is_initialized.resolve();
|
||||||
self.do_update_pager(record.id == null);
|
self.do_update_pager(record.id == null);
|
||||||
if (self.sidebar) {
|
if (self.sidebar) {
|
||||||
// self.sidebar.attachments.do_update();
|
self.sidebar.do_attachement_update(self.dataset, self.datarecord.id);
|
||||||
}
|
}
|
||||||
if (self.default_focus_field) {
|
if (self.default_focus_field) {
|
||||||
self.default_focus_field.focus();
|
self.default_focus_field.focus();
|
||||||
|
@ -697,12 +696,12 @@ openerp.web.FormView = openerp.web.View.extend({
|
||||||
this.dataset.alter_ids(this.dataset.ids.concat([this.datarecord.id]));
|
this.dataset.alter_ids(this.dataset.ids.concat([this.datarecord.id]));
|
||||||
this.dataset.index = this.dataset.ids.length - 1;
|
this.dataset.index = this.dataset.ids.length - 1;
|
||||||
} else {
|
} else {
|
||||||
this.dataset.alter_ids([this.datarecord.id].concat(this.dataset.ids));
|
this.dataset.alter_ids([this.datarecord.id].concat(this.dataset.ids));
|
||||||
this.dataset.index = 0;
|
this.dataset.index = 0;
|
||||||
}
|
}
|
||||||
this.do_update_pager();
|
this.do_update_pager();
|
||||||
if (this.sidebar) {
|
if (this.sidebar) {
|
||||||
// this.sidebar.attachments.do_update();
|
this.sidebar.do_attachement_update(this.dataset, this.datarecord.id);
|
||||||
}
|
}
|
||||||
//openerp.log("The record has been created with id #" + this.datarecord.id);
|
//openerp.log("The record has been created with id #" + this.datarecord.id);
|
||||||
this.reload();
|
this.reload();
|
||||||
|
@ -1221,62 +1220,6 @@ openerp.web.form.FormDialog = openerp.web.Dialog.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
openerp.web.form.SidebarAttachments = openerp.web.Widget.extend({
|
|
||||||
init: function(parent, form_view) {
|
|
||||||
//var $section = parent.add_section(_t('Attachments'), 'attachments');
|
|
||||||
//this.$div = $('<div class="oe-sidebar-attachments"></div>');
|
|
||||||
//$section.append(this.$div);
|
|
||||||
this._super(parent);
|
|
||||||
this.view = form_view;
|
|
||||||
},
|
|
||||||
do_update: function() {
|
|
||||||
return;
|
|
||||||
if (!this.view.datarecord.id) {
|
|
||||||
this.on_attachments_loaded([]);
|
|
||||||
} else {
|
|
||||||
(new openerp.web.DataSetSearch(
|
|
||||||
this, 'ir.attachment', this.view.dataset.get_context(),
|
|
||||||
[
|
|
||||||
['res_model', '=', this.view.dataset.model],
|
|
||||||
['res_id', '=', this.view.datarecord.id],
|
|
||||||
['type', 'in', ['binary', 'url']]
|
|
||||||
])).read_slice(['name', 'url', 'type'], {}).then(this.on_attachments_loaded);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
on_attachments_loaded: function(attachments) {
|
|
||||||
return;
|
|
||||||
this.attachments = attachments;
|
|
||||||
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);
|
|
||||||
},
|
|
||||||
on_attachment_changed: function(e) {
|
|
||||||
return;
|
|
||||||
window[this.element_id + '_iframe'] = this.do_update;
|
|
||||||
var $e = $(e.target);
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
on_attachment_delete: function(e) {
|
|
||||||
return;
|
|
||||||
var self = this, $e = $(e.currentTarget);
|
|
||||||
var name = _.str.trim($e.parent().find('a.oe-sidebar-attachments-link').text());
|
|
||||||
if (confirm(_.str.sprintf(_t("Do you really want to delete the attachment %s?"), name))) {
|
|
||||||
this.rpc('/web/dataset/unlink', {
|
|
||||||
model: 'ir.attachment',
|
|
||||||
ids: [parseInt($e.attr('data-id'))]
|
|
||||||
}, function(r) {
|
|
||||||
$e.parent().remove();
|
|
||||||
self.do_notify("Delete an attachment", "The attachment '" + name + "' has been deleted");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
openerp.web.form.compute_domain = function(expr, fields) {
|
openerp.web.form.compute_domain = function(expr, fields) {
|
||||||
var stack = [];
|
var stack = [];
|
||||||
for (var i = expr.length - 1; i >= 0; i--) {
|
for (var i = expr.length - 1; i >= 0; i--) {
|
||||||
|
|
|
@ -727,8 +727,6 @@ session.web.Sidebar = session.web.Widget.extend({
|
||||||
init: function(parent) {
|
init: function(parent) {
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
var view = this.getParent();
|
var view = this.getParent();
|
||||||
var view_manager = view.getParent();
|
|
||||||
var action = view_manager.action;
|
|
||||||
this.sections = [
|
this.sections = [
|
||||||
{ 'name' : 'print', 'label' : _t('Print'), },
|
{ 'name' : 'print', 'label' : _t('Print'), },
|
||||||
{ 'name' : 'files', 'label' : _t('Attachement'), },
|
{ 'name' : 'files', 'label' : _t('Attachement'), },
|
||||||
|
@ -763,21 +761,22 @@ session.web.Sidebar = session.web.Widget.extend({
|
||||||
var item = self.items[section][index];
|
var item = self.items[section][index];
|
||||||
if (item.callback) {
|
if (item.callback) {
|
||||||
item.callback.apply(self, [item]);
|
item.callback.apply(self, [item]);
|
||||||
}
|
} else if (item.action) {
|
||||||
if (item.action) {
|
|
||||||
self.on_item_action_clicked(item);
|
self.on_item_action_clicked(item);
|
||||||
|
} else if (item.url) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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() {
|
redraw: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.$element.html(QWeb.render('Sidebar', {widget: self}));
|
self.$element.html(QWeb.render('Sidebar', {widget: self}));
|
||||||
this.$element.find('ul').hide();
|
this.$element.find('ul').hide();
|
||||||
},
|
},
|
||||||
add_default_sections: function() {
|
|
||||||
var self = this;
|
|
||||||
},
|
|
||||||
add_section: function() {
|
add_section: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
},
|
},
|
||||||
|
@ -857,6 +856,52 @@ session.web.Sidebar = session.web.Widget.extend({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
do_attachement_update: function(dataset, model_id) {
|
||||||
|
if (!model_id) {
|
||||||
|
this.on_attachments_loaded([]);
|
||||||
|
} else {
|
||||||
|
var dom = [ ['res_model', '=', dataset.model], ['res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ];
|
||||||
|
var ds = new session.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
|
||||||
|
ds.read_slice(['name', 'url', 'type'], {}).then(this.on_attachments_loaded);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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=';
|
||||||
|
_.each(attachments,function(a) {
|
||||||
|
a.label = a.name;
|
||||||
|
if(a.type === "binary") {
|
||||||
|
a.url = prefix + a.id + '&t=' + (new Date().getTime());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.add_items('files', attachments);
|
||||||
|
},
|
||||||
|
on_attachment_changed: function(e) {
|
||||||
|
return;
|
||||||
|
window[this.element_id + '_iframe'] = this.do_update;
|
||||||
|
var $e = $(e.target);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
on_attachment_delete: function(e) {
|
||||||
|
return;
|
||||||
|
var self = this, $e = $(e.currentTarget);
|
||||||
|
var name = _.str.trim($e.parent().find('a.oe-sidebar-attachments-link').text());
|
||||||
|
if (confirm(_.str.sprintf(_t("Do you really want to delete the attachment %s?"), name))) {
|
||||||
|
this.rpc('/web/dataset/unlink', {
|
||||||
|
model: 'ir.attachment',
|
||||||
|
ids: [parseInt($e.attr('data-id'))]
|
||||||
|
}, function(r) {
|
||||||
|
$e.parent().remove();
|
||||||
|
self.do_notify("Delete an attachment", "The attachment '" + name + "' has been deleted");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
session.web.TranslateDialog = session.web.Dialog.extend({
|
session.web.TranslateDialog = session.web.Dialog.extend({
|
||||||
|
@ -1147,9 +1192,6 @@ session.web.View = session.web.Widget.extend({
|
||||||
},
|
},
|
||||||
do_search: function(view) {
|
do_search: function(view) {
|
||||||
},
|
},
|
||||||
set_common_sidebar_sections: function(sidebar) {
|
|
||||||
sidebar.add_default_sections();
|
|
||||||
},
|
|
||||||
on_sidebar_import: function() {
|
on_sidebar_import: function() {
|
||||||
var import_view = new session.web.DataImport(this, this.dataset);
|
var import_view = new session.web.DataImport(this, this.dataset);
|
||||||
import_view.start();
|
import_view.start();
|
||||||
|
|
|
@ -515,7 +515,7 @@
|
||||||
<button class="oe_dropdown_toggle"><t t-esc="section.label"/></button>
|
<button class="oe_dropdown_toggle"><t t-esc="section.label"/></button>
|
||||||
<ul class="oe_dropdown_menu">
|
<ul class="oe_dropdown_menu">
|
||||||
<li t-foreach="widget.items[section.name]" t-as="item" t-att-class="item.classname">
|
<li t-foreach="widget.items[section.name]" t-as="item" t-att-class="item.classname">
|
||||||
<a class="oe_sidebar_action_a" t-att-title="item.title" href="#" t-att-data-section="section.name" t-att-data-index="item_index">
|
<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"/>
|
<t t-raw="item.label"/>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -524,6 +524,40 @@
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
<t t-name="Sidebar.attachments">
|
||||||
|
<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="/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 + '&model=ir.attachment&id=' + attachment.id
|
||||||
|
+ '&field=datas&filename_field=name&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">
|
<t t-name="TreeView">
|
||||||
<select t-if="toolbar" style="width: 30%">
|
<select t-if="toolbar" style="width: 30%">
|
||||||
|
@ -690,40 +724,6 @@
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-name="FormView.sidebar.attachments">
|
|
||||||
<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="/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 + '&model=ir.attachment&id=' + attachment.id
|
|
||||||
+ '&field=datas&filename_field=name&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>
|
|
||||||
<form t-name="FormView.set_default" class="oe_forms oe_frame">
|
<form t-name="FormView.set_default" class="oe_forms oe_frame">
|
||||||
<t t-set="args" t-value="widget.dialog_options.args"/>
|
<t t-set="args" t-value="widget.dialog_options.args"/>
|
||||||
<table style="width: 100%">
|
<table style="width: 100%">
|
||||||
|
|
Loading…
Reference in New Issue