[MIG] document_url: Migration to 12.0

This commit is contained in:
ernesto
2019-04-25 15:07:56 -04:00
committed by FernandoRomera
parent e4bb12d11f
commit f3298b6508
9 changed files with 95 additions and 97 deletions

View File

@@ -1,76 +1,39 @@
/* Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
* Copyright 2019 Tecnativa - Ernesto Tejeda
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('document_url', function (require) {
"use strict";
var core = require('web.core');
var Sidebar = require('web.Sidebar');
var ActionManager = require('web.ActionManager');
var Context = require('web.Context');
var pyeval = require('web.pyeval');
var AttachmentBox = require('mail.AttachmentBox');
var _t = core._t,
QWeb = core.qweb;
Sidebar.include({
_redraw: function () {
var self = this;
this._super.apply(this, arguments);
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}));
self.$el.find('.o_sidebar_add_url').on('click', function (e) {
self.on_url_doc();
AttachmentBox.include({
events: _.extend(AttachmentBox.prototype.events, {
"click span.o_add_url_button": "_onAddUrl",
}),
/**
* Opens wizard to add an URL attachment to the current record
*
* @private
* @param {MouseEvent} ev
*/
_onAddUrl: function (ev) {
this.do_action('document_url.action_ir_attachment_add_url', {
additional_context: {
'active_id': this.currentResID,
'active_ids': [this.currentResID],
'active_model': this.currentResModel,
},
on_close: this._onAddedUrl.bind(this),
});
},
on_url_doc: function (event) {
var self = this;
var env = self.env;
var view = self.getParent();
var ids = self.env.activeIds;
if (!_.isEmpty(ids)) {
var activeIdsContext = {
active_id: env.activeIds[0],
active_ids: env.activeIds,
active_model: env.model,
};
if (env.domain) {
activeIdsContext.active_domain = env.domain;
}
var context = new Context(env.context, activeIdsContext);
context = pyeval.eval('context', context);
self._rpc({
route: "/web/action/load",
params: {
action_id: "document_url.action_ir_attachment_add_url",
context: context,
},
}).done(function (result) {
self.getParent().do_action(result, {
additional_context: {
'active_ids': ids,
'active_id': [ids[0]],
'active_model': env.model,
},
});
});
}
},
/**
* @private
*/
_onAddedUrl: function () {
this.trigger_up('reload_attachment_box');
}
});
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,9 +0,0 @@
.o_cp_sidebar {
.o_sidebar_add_url span {
padding: 3px 25px;
color: @btn-default-color;
}
.o_sidebar_add_url:hover {
background-color: @table-bg-hover;
}
}

View File

@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates id="template" xml:space="preserve">
<t t-name="AddUrlDocumentItem">
<li class="o_sidebar_add_url">
<span>Add URL...</span>
</li>
<t t-extend="mail.chatter.AttachmentBox">
<t t-jquery="span.o_upload_attachments_button" t-operation="after">
<span class="btn btn-link o_add_url_button"><span class="fa fa-plus-square"/> Add URL</span>
</t>
</t>
</templates>