Skip to content

Commit

Permalink
Merge 73729b5 into df41bbb
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilbonet committed Sep 29, 2018
2 parents df41bbb + 73729b5 commit e61ea68
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 77 deletions.
Empty file modified document_page/views/document_page_category.xml 100755 → 100644
Empty file.
Empty file modified document_page/views/document_page_history.xml 100755 → 100644
Empty file.
Empty file modified document_page/views/report_document_page.xml 100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions document_url/README.rst
Expand Up @@ -23,15 +23,15 @@ To use this module, you need to:

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/118/9.0
:target: https://runbot.odoo-community.org/runbot/118/10.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`here <https://github.com/OCA/knowledge/issues/new?body=module:%20document_url%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Credits
=======
Expand All @@ -40,7 +40,7 @@ Contributors
------------

* Jonathan Nemry <jonathan.nemry@acsone.eu>
* Pedro M. Baeza <pedro.baeza@tecnativa.com
* Pedro M. Baeza <pedro.baeza@tecnativa.com>

Maintainer
----------
Expand Down
4 changes: 2 additions & 2 deletions document_url/__manifest__.py
Expand Up @@ -4,7 +4,7 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
{
'name': 'URL attachment',
'version': '9.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'Tools',
'author': "Tecnativa,"
"Odoo Community Association (OCA)",
Expand All @@ -19,5 +19,5 @@
'qweb': [
'static/src/xml/url.xml',
],
'installable': False,
'installable': True,
}
62 changes: 62 additions & 0 deletions document_url/i18n/document_url.pot
@@ -0,0 +1,62 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * document_url
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-04-05 01:48+0000\n"
"PO-Revision-Date: 2014-04-05 03:49+0100\n"
"Last-Translator: Pedro Manuel Baeza <pedro.baeza@serviciosbaeza.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"

#. module: document_url
#: view:ir.attachment.add_url:0
msgid "Add"
msgstr ""

#. module: document_url
#: model:ir.actions.act_window,name:document_url.action_ir_attachment_add_url
#: view:ir.attachment.add_url:0
msgid "Add URL"
msgstr ""

#. module: document_url
#. openerp-web
#: code:addons/document_url/static/src/xml/url.xml:6
#, python-format
msgid "Add URL..."
msgstr ""

#. module: document_url
#: view:ir.attachment.add_url:0
msgid "Cancel"
msgstr ""

#. module: document_url
#: field:ir.attachment.add_url,name:0
msgid "Name"
msgstr ""

#. module: document_url
#: field:ir.attachment.add_url,url:0
msgid "URL"
msgstr ""

#. module: document_url
#: code:_description:0
#: model:ir.model,name:document_url.model_ir_attachment_add_url
#, python-format
msgid "ir.attachment.add_url"
msgstr ""

#. module: document_url
#: view:ir.attachment.add_url:0
msgid "or"
msgstr ""

60 changes: 17 additions & 43 deletions document_url/static/src/js/url.js
Expand Up @@ -4,53 +4,27 @@
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define('document_url', function(require) {

var core = require('web.core');
"use strict";
var Sidebar = require('web.Sidebar');
var ActionManager = require('web.ActionManager');

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('.oe_sidebar_add_url').on('click', function (e) {
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,
},
});
});
});
}
init: function (parent, options) {
var result = this._super(parent, options);
this.items.url_doc = [
{
action: {
id: "document_url.action_ir_attachment_add_url"
}
}
];
return result;
},
});

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();
},
redraw: function () {
var result = this._super();
// Open URLs in a different browser tab
this.$el.find("a[href]").attr('target', '_blank');
return result;
}
});

});
19 changes: 13 additions & 6 deletions document_url/static/src/xml/url.xml
@@ -1,8 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="AddUrlDocumentItem">
<li class="oe_sidebar_add_url">
<a class="oe_file_attachment">Add URL...</a>
</li>
</t>
<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"
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>
8 changes: 2 additions & 6 deletions document_url/view/document_url_view.xml
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<odoo>
<template id="assets_backend" name="google_drive assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/document_url/static/src/js/url.js"></script>
Expand Down Expand Up @@ -34,6 +32,4 @@
</form>
</field>
</record>

</data>
</openerp>
</odoo>
31 changes: 14 additions & 17 deletions document_url/wizard/document_url.py
Expand Up @@ -2,41 +2,38 @@
# © 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
from openerp.osv import fields, orm
from odoo import models, fields, api
try:
# Python 3
from urllib import parse as urlparse
except:
from urlparse import urlparse


class AddUrlWizard(orm.TransientModel):
class AddUrlWizard(models.TransientModel):
_name = 'ir.attachment.add_url'

_columns = {
'name': fields.char('Name', required=True),
'url': fields.char('URL', required=True),
}
name = fields.Char('Name', required=True)
url = fields.Char('URL', required=True)

def action_add_url(self, cr, uid, ids, context=None):
@api.multi
def action_add_url(self):
"""Adds the URL with the given name as an ir.attachment record."""
if context is None:
context = {}
if not context.get('active_model'):

if not self._context.get('active_model'):
return
attachment_obj = self.pool['ir.attachment']
for form in self.browse(cr, uid, ids, context=context):
attachment_obj = self.env['ir.attachment']
for form in self:
url = urlparse(form.url)
if not url.scheme:
url = urlparse('%s%s' % ('http://', form.url))
for active_id in context.get('active_ids', []):
for active_id in self._context.get('active_ids', []):
attachment = {
'name': form.name,
'type': 'url',
'url': url.geturl(),
'user_id': uid,
'res_id': active_id,
'res_model': context['active_model'],
'res_model': self._context.get('active_model')
}
attachment_obj.create(cr, uid, attachment, context=context)
return {'type': 'ir.actions.act_close_wizard_and_reload_view'}
attachment_obj.create(attachment)
return False

0 comments on commit e61ea68

Please sign in to comment.