mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 03:56:56 -06:00
[FIX][document_url] Remove error when clicking on add URL (#102)
[FIX][document_url] Remove error when clicking on add URL
BTW, completely refactored 😉. It turns out Odoo's framework is not that bad when you discover it. It's just not documented.
This commit is contained in:
parent
27ea491285
commit
0aa97eff14
@ -4,11 +4,11 @@
|
|||||||
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
|
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||||
{
|
{
|
||||||
'name': 'URL attachment',
|
'name': 'URL attachment',
|
||||||
'version': '9.0.1.0.0',
|
'version': '9.0.2.0.0',
|
||||||
'category': 'Tools',
|
'category': 'Tools',
|
||||||
'author': "Tecnativa,"
|
'author': "Tecnativa,"
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
'website': 'http://www.serviciosbaeza.com',
|
'website': 'http://www.tecnativa.com',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'depends': [
|
'depends': [
|
||||||
'document',
|
'document',
|
||||||
|
@ -1,56 +1,31 @@
|
|||||||
/* © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
|
/* © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
|
||||||
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
|
||||||
* © 2016 ACSONE SA/NV (<http://acsone.eu>)
|
* © 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||||
|
* Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
* 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();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
on_url_doc: function() {
|
|
||||||
var self = this;
|
|
||||||
var view = self.getParent();
|
|
||||||
var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ];
|
|
||||||
if( !_.isEmpty(ids) ){
|
|
||||||
view.sidebar_eval_context().done(function (context) {
|
|
||||||
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,
|
|
||||||
},
|
},
|
||||||
});
|
];
|
||||||
});
|
return result;
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
|
||||||
|
|
||||||
ActionManager = ActionManager.include({
|
redraw: function () {
|
||||||
ir_actions_act_close_wizard_and_reload_view: function (action, options) {
|
var result = this._super();
|
||||||
if (!this.dialog) {
|
// Open URLs in a different browser tab
|
||||||
options.on_close();
|
this.$el.find("a[href]").attr('target', '_blank');
|
||||||
}
|
return result;
|
||||||
this.dialog_stop();
|
|
||||||
this.inner_widget.views[this.inner_widget.active_view.type].controller.reload();
|
|
||||||
return $.when();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
<?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>
|
||||||
|
<t t-extend="Sidebar">
|
||||||
|
<!-- oe_ for Odoo CE, and o_ for Odoo EE -->
|
||||||
|
<t t-jquery=".oe_sidebar_add_attachment, .o_sidebar_add_attachment" t-operation="after">
|
||||||
<li class="oe_sidebar_add_url">
|
<li class="oe_sidebar_add_url">
|
||||||
<a class="oe_file_attachment">Add URL...</a>
|
<a class="oe_file_attachment"
|
||||||
|
data-section="url_doc"
|
||||||
|
data-index="0">Add URL...</a>
|
||||||
</li>
|
</li>
|
||||||
</t>
|
</t>
|
||||||
|
</t>
|
||||||
</templates>
|
</templates>
|
||||||
|
@ -39,4 +39,5 @@ class AddUrlWizard(orm.TransientModel):
|
|||||||
'res_model': context['active_model'],
|
'res_model': context['active_model'],
|
||||||
}
|
}
|
||||||
attachment_obj.create(cr, uid, attachment, context=context)
|
attachment_obj.create(cr, uid, attachment, context=context)
|
||||||
return {'type': 'ir.actions.act_close_wizard_and_reload_view'}
|
# Close client dialog
|
||||||
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user