[ADD] pad: web component
bzr revid: xmo@openerp.com-20101021103448-fyb0km0i147av93t
This commit is contained in:
commit
9030f5d625
|
@ -16,5 +16,5 @@ company customize which Pad installation should be used to link to new pads
|
|||
],
|
||||
'installable': True,
|
||||
'active': False,
|
||||
# 'web': True,
|
||||
'web': True,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
import controllers
|
||||
import editors
|
|
@ -0,0 +1,34 @@
|
|||
import urlparse
|
||||
|
||||
import cherrypy
|
||||
|
||||
from openobject.tools import expose
|
||||
|
||||
import openerp.controllers
|
||||
from openerp.utils import rpc, TinyDict
|
||||
|
||||
class Piratepad(openerp.controllers.SecuredController):
|
||||
_cp_path = "/piratepad"
|
||||
|
||||
def get_root(self):
|
||||
return rpc.RPCProxy('res.company').read(
|
||||
[rpc.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.session.context,
|
||||
default_res_model=params.model, default_res_id=params.id,
|
||||
active_id=False, active_ids=[])
|
||||
|
||||
pad_link = self.make_url(pad_name)
|
||||
attachment_id = rpc.RPCProxy('ir.attachment').create({
|
||||
'name': pad_name,
|
||||
'url': pad_link,
|
||||
}, ctx)
|
||||
return {'id': attachment_id, 'name': pad_name, 'url': pad_link}
|
|
@ -0,0 +1,46 @@
|
|||
# -*- 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"
|
||||
style="right: 44px;"
|
||||
>${_("Pad")}</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();
|
||||
e.preventDefault();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
''' + output[form_insertion_point:]
|
Loading…
Reference in New Issue