Fix Url sidebar

This commit is contained in:
Nicolás 2016-11-15 22:57:32 +00:00
parent 65e4a1998f
commit 6caf5e74aa
3 changed files with 34 additions and 57 deletions

View File

@ -1,56 +1,25 @@
/* © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* © 2016 ACSONE SA/NV (<http://acsone.eu>)
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('document_url', function(require) { odoo.define('document_url', function(require) {
"use strict";
var core = require('web.core');
var Sidebar = require('web.Sidebar'); var Sidebar = require('web.Sidebar');
var ActionManager = require('web.ActionManager');
var _t = core._t,
QWeb = core.qweb;
Sidebar.include({ Sidebar.include({
redraw: function() { init: function (parent, options) {
var self = this; var result = this._super(parent, options);
this._super.apply(this, arguments); this.items.url_doc = [
self.$el.find("a[href]").attr('target', '_blank'); {
self.$el.find('.oe_sidebar_add_attachment, .o_sidebar_add_attachment').after(QWeb.render('AddUrlDocumentItem', {widget: self})) action: {
self.$el.find('.oe_sidebar_add_url').on('click', function (e) { id: "document_url.action_ir_attachment_add_url",
self.on_url_doc(); },
}); },
];
return result;
}, },
on_url_doc: function() {
var self = this; redraw: function () {
var view = self.getParent(); var result = this._super();
var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ]; // Open URLs in a different browser tab
if( !_.isEmpty(ids) ){ this.$el.find("a[href]").attr('target', '_blank');
view.sidebar_eval_context().done(function (context) { return result;
self.rpc("/web/action/load", { action_id: "document_url.action_ir_attachment_add_url" }).done(function(result) {
self.getParent().do_action(result, {
additional_context: {
'active_ids': ids,
'active_id': [ids[0]],
'active_model': view.dataset.model,
},
});
});
});
}
}, },
}); });
ActionManager = ActionManager.include({
ir_actions_act_close_wizard_and_reload_view: function (action, options) {
if (!this.dialog) {
options.on_close();
}
this.dialog_stop();
this.inner_widget.views[this.inner_widget.active_view.type].controller.reload();
return $.when();
},
});
}); });

View File

@ -1,8 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="AddUrlDocumentItem"> <templates>
<li class="oe_sidebar_add_url"> <t t-extend="Sidebar">
<span class="oe_url_attachment">Add URL...</span> <!-- oe_ for Odoo CE, and o_ for Odoo EE -->
</li> <t t-jquery=".oe_sidebar_add_attachment, .o_sidebar_add_attachment"
</t> t-operation="after">
<li class="oe_sidebar_add_url"
t-if="section.name == 'files' and widget.options.editable">
<a class="oe_file_attachment"
data-section="url_doc"
data-index="0">Add URL...</a>
</li>
</t>
</t>
</templates> </templates>