[IMP] Piratepad web addons.

bzr revid: cpa@tinyerp.com-20101015101626-e23fxuyvzwsx9ao2
This commit is contained in:
cpa-openerp
2010-10-15 15:46:26 +05:30
commit 39574b1d41
4 changed files with 86 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
import controllers
import editors
+8
View File
@@ -0,0 +1,8 @@
{
"name" : "Piratepad Controller methods",
"version" : "1.0",
"depends" : ["openerp"],
"author" : "Tiny",
"website": 'http://www.openerp.com/',
"active": True,
}
+22
View File
@@ -0,0 +1,22 @@
from openobject.tools import expose
from openerp.controllers import form
from openerp.utils import rpc, common, TinyDict
import cherrypy
class Form(form.Form):
_cp_path = "/piratepad/form"
@expose('json', methods=('POST',))
def save(self, **kwargs):
params, data = TinyDict.split(cherrypy.session['params'])
pad_name=kwargs.get('pad_name')
ctx = dict(rpc.session.context,
default_res_model=params.model, default_res_id=params.id,
active_id=False, active_ids=[])
pad_link = "http://piratepad.net/"+'-'.join(pad_name.split())
attachment_id = rpc.RPCProxy('ir.attachment').create({
'name': pad_name,
'url': pad_link,
}, ctx)
return {'id': attachment_id, 'name': pad_name, 'url': pad_link}
+54
View File
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from openobject.widgets import JSLink
import openobject.templating
class SidebarTemplateEditor(openobject.templating.TemplateEditor):
templates = ['/openerp/widgets/templates/sidebar.mako']
SIDEBAR_START = u'<div id="piratepad-box">'
def edit(self, template, template_text):
output = super(SidebarTemplateEditor, self).edit(template, template_text)
insertion_point = output.index(self.SIDEBAR_START) + len(self.SIDEBAR_START)
return output[:insertion_point] + '''
<script type="text/javascript">
jQuery(document).ready(function() {
var padForm = jQuery('#pad-box').hide();
jQuery('#sidebar-attachments').append(
jQuery('<a>',{
'href': '#',
'id': 'add-pad',
'class': 'button-a',
}).text('${_("Pad")}')
);
jQuery('#sidebar_pad_ok').bind('click', function(){
padForm.submit();
});
jQuery('#add-pad').click(function(e){
padForm.show();
e.preventDefault();
});
padForm.bind({
submit: createAttachment
});
});
</script>
<form id="pad-box" action="/piratepad/form/save" method="post">
<label for="sidebar_pad_datas">${_("Name")}:</label>
<table width="100%">
<tr>
<td width=60% style="padding-right:8px;">
<input type="text" id="sidebar_pad_datas" class="binary"
name="pad_name" kind="url" size="5" />
</td>
<td>
<a href="#" id="sidebar_pad_ok" class="button-a">${_("Ok")}</a>
</td>
</tr>
</table>
</form>
''' + output[insertion_point:]