From b5e1cb6060b5fbd521bdae3350b661f560851ab1 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 6 Oct 2011 15:44:08 +0200 Subject: [PATCH] [IMP] port pad module to 6.1 bzr revid: chs@openerp.com-20111006134408-5c2z2xhod6b998jv --- addons/pad/LICENSE | 4 +- addons/pad/__openerp__.py | 5 ++- addons/pad/static/src/js/pad.js | 71 +++++++++++++++++++++++++++++++ addons/pad/static/src/xml/pad.xml | 12 ++++++ addons/pad/web/__init__.py | 2 - addons/pad/web/controllers.py | 37 ---------------- addons/pad/web/editors.py | 46 -------------------- 7 files changed, 88 insertions(+), 89 deletions(-) create mode 100644 addons/pad/static/src/js/pad.js create mode 100644 addons/pad/static/src/xml/pad.xml delete mode 100644 addons/pad/web/__init__.py delete mode 100644 addons/pad/web/controllers.py delete mode 100644 addons/pad/web/editors.py diff --git a/addons/pad/LICENSE b/addons/pad/LICENSE index cff5dae3a7b..ff64be448e9 100644 --- a/addons/pad/LICENSE +++ b/addons/pad/LICENSE @@ -1,5 +1,5 @@ OpenERP, Open Source Management Solution -Copyright © 2010 OpenERP SA (). +Copyright © 2010-2011 OpenERP SA (). This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as @@ -12,4 +12,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public Lice -along with this program. If not, see . \ No newline at end of file +along with this program. If not, see . diff --git a/addons/pad/__openerp__.py b/addons/pad/__openerp__.py index 65035912d85..4671d16038f 100644 --- a/addons/pad/__openerp__.py +++ b/addons/pad/__openerp__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- { 'name': 'Collaborative Note Pad', - 'version': '1.0.3', + 'version': '2.0', 'category': 'Hidden', 'complexity': "easy", 'description': """ @@ -21,5 +21,6 @@ Lets the company customize which Pad installation should be used to link to new 'active': False, 'web': True, 'certificate' : '001183545978470526509', - 'images': ['images/pad_link_companies.jpeg'], + 'js': ['static/src/js/pad.js'], + 'images': ['static/src/img/pad_link_companies.jpeg'], } diff --git a/addons/pad/static/src/js/pad.js b/addons/pad/static/src/js/pad.js new file mode 100644 index 00000000000..c6b977b0f78 --- /dev/null +++ b/addons/pad/static/src/js/pad.js @@ -0,0 +1,71 @@ + +openerp.pad = function(instance) { + +var QWeb = instance.web.qweb; +QWeb.add_template('/pad/static/src/xml/pad.xml'); + +instance.web.form.SidebarAttachments = instance.web.form.SidebarAttachments.extend({ + + pad_prefix: undefined, + + on_add_pad: function() { + var self = this; + var $padbtn = this.$element.find('button.pad'); + $padbtn.attr('disabled', 'true').find('img, span').toggle(); + + this.do_load_pad_prefix(function() { + var attachment = new instance.web.DataSet(self, 'ir.attachment', self.view.dataset.get_context()); + var r = (((1+Math.random())*0x10000)|0).toString(16).substring(1); + attachment.create({ + res_model: self.view.dataset.model, + res_id: self.view.datarecord.id, + type: 'url', + name: 'Pad', + url: self.pad_prefix + r, + }, function() { + self.do_update(); + }); + }); + + }, + + do_load_pad_prefix: function(continuation) { + var self = this; + if (this.pad_prefix === undefined) { + var user = new instance.web.DataSet(this, 'res.users', this.view.dataset.get_context()); + var company = new instance.web.DataSet(this, 'res.company', this.view.dataset.get_context()); + user.read_ids([this.session.uid], ['company_id'], function(result) { + company.read_ids([result[0].company_id[0]], ['pad_index'], function(result) { + var pad_index = _(result[0].pad_index).strip().replace(/\/$/, "");; + if (pad_index) { + self.pad_prefix = _('%s/%s-%s-%d-').sprintf(pad_index, self.session.db, self.view.dataset.model, self.view.datarecord.id); + } else { + self.pad_prefix = null; + } + continuation(); + }); + }); + } else { + continuation(); + } + }, + + on_attachments_loaded: function(attachments) { + this._super(attachments); + var self = this; + this.do_load_pad_prefix(function() { + var $padbtn = self.$element.find('button.pad'); + var is_pad = function(a) { + return a.type == 'url' && _(a.url).startsWith(self.pad_prefix); + }; + if (!self.pad_prefix || _.any(attachments, is_pad)) { + $padbtn.hide(); + } else { + $padbtn.show().click(self.on_add_pad); + } + }); + + }, +}); + +}; diff --git a/addons/pad/static/src/xml/pad.xml b/addons/pad/static/src/xml/pad.xml new file mode 100644 index 00000000000..1923a01bc68 --- /dev/null +++ b/addons/pad/static/src/xml/pad.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/addons/pad/web/__init__.py b/addons/pad/web/__init__.py deleted file mode 100644 index 95542e91e3e..00000000000 --- a/addons/pad/web/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -import controllers -import editors diff --git a/addons/pad/web/controllers.py b/addons/pad/web/controllers.py deleted file mode 100644 index 082ab69b35a..00000000000 --- a/addons/pad/web/controllers.py +++ /dev/null @@ -1,37 +0,0 @@ -import urlparse - -import cherrypy - -from openobject import rpc -from openobject.tools import expose - -import openerp.controllers -from openerp.utils import TinyDict - -class Piratepad(openerp.controllers.SecuredController): - _cp_path = "/piratepad" - - def get_root(self): - return rpc.RPCProxy('res.company').read( - [rpc.get_session().company_id], ['pad_index'])[0]['pad_index'] - - def make_url(self, pad_name): - return urlparse.urljoin( - self.get_root(), '-'.join(pad_name.split()) - ) - - @expose('json', methods=('POST',)) - def link(self, pad_name): - params, data = TinyDict.split(cherrypy.session['params']) - ctx = dict(rpc.get_session().context, - default_res_model=params.model, default_res_id=params.id, - active_id=False, active_ids=[]) - - pad_name = pad_name.decode('utf8') - pad_link = self.make_url(pad_name) - attachment_id = rpc.RPCProxy('ir.attachment').create({ - 'name': pad_name, - 'url': pad_link, - 'type': 'url' - }, ctx) - return {'id': attachment_id, 'name': pad_name, 'url': pad_link} diff --git a/addons/pad/web/editors.py b/addons/pad/web/editors.py deleted file mode 100644 index e303dc4b3d7..00000000000 --- a/addons/pad/web/editors.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -import openobject.templating - -class SidebarTemplateEditor(openobject.templating.TemplateEditor): - templates = ['/openerp/widgets/templates/sidebar.mako'] - ADD_ATTACHMENT_BUTTON = u'id="add-attachment"' - BINARY_ATTACHMENTS_FORM = u'
${_("Write")}\n''' + \ - output[form_opener_insertion:] - return output - - def edit(self, template, template_text): - output = super(SidebarTemplateEditor, self).edit(template, template_text) - - output = self.insert_pad_link(output) - - form_insertion_point = output.index(self.BINARY_ATTACHMENTS_FORM) - return output[:form_insertion_point] + ''' - - - - -
- - ''' + output[form_insertion_point:]