[MERGE] pad port to 6.1 chs

bzr revid: al@openerp.com-20111010211124-mjta0o42rarn87tw
This commit is contained in:
Antony Lesuisse 2011-10-10 23:11:24 +02:00
commit e38054527c
10 changed files with 91 additions and 92 deletions

View File

@ -1,5 +1,5 @@
OpenERP, Open Source Management Solution
Copyright © 2010 OpenERP SA (<http://openerp.com>).
Copyright © 2010-2011 OpenERP SA (<http://openerp.com>).
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 <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.

View File

@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
import company_pad
import res_company

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
{
'name': 'Collaborative Note Pad',
'version': '1.0.3',
'version': '2.0',
'category': 'Hidden',
'complexity': "easy",
'description': """
@ -15,11 +15,12 @@ Lets the company customize which Pad installation should be used to link to new
'website': 'http://openerp.com',
'depends': ['base'],
'data': [
'company_pad.xml'
'res_company.xml'
],
'installable': True,
'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'],
}

View File

@ -12,4 +12,3 @@ class company_pad(osv.osv):
'pad_index': 'http://ietherpad.com/'
}
company_pad()

View File

@ -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);
}
});
},
});
};

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-extend="FormView.sidebar.attachments">
<t t-jquery="div.oe-binary-file-set" t-operation="append">
<button class="button pad" type="button">
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
<span>Add Pad</span>
</button>
</t>
</t>
</templates>

View File

@ -1,2 +0,0 @@
import controllers
import editors

View File

@ -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}

View File

@ -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'<form id="attachment-box"'
def insert_pad_link(self, output):
# Insert the link on the line right after the link to open the
# attachment form
form_opener_insertion = output.index(
'\n',
output.index(self.ADD_ATTACHMENT_BUTTON)) + 1
output = output[:form_opener_insertion] + \
'''<a href="#" id="add-pad" class="button-a
attachment-button">${_("Write")}</a>\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] + '''
<form id="pad-form" action="/piratepad/link" method="post">
<label for="sidebar_pad_datas">${_("Name")}:</label>
<input id="sidebar_pad_datas"
name="pad_name" size="5" />
<button>${_("Ok")}</button>
</form>
<script type="text/javascript">
jQuery(document).ready(function() {
var $padForm = jQuery('#pad-form')
.hide()
.submit(createAttachment);
jQuery('#add-pad').click(function(e){
$padForm.show();
jQuery('#sidebar_pad_datas').focus();
e.preventDefault();
});
});
</script>
''' + output[form_insertion_point:]