[IMP] use templates manipulation to add the link to open the pad form, rather than using JS
bzr revid: xmo@openerp.com-20101020124133-36olqe3hp1e1xp3t
This commit is contained in:
+17
-12
@@ -5,13 +5,27 @@ 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">${_("Pad")}</a>\n' + \
|
||||
output[form_opener_insertion:]
|
||||
return output
|
||||
|
||||
def edit(self, template, template_text):
|
||||
output = super(SidebarTemplateEditor, self).edit(template, template_text)
|
||||
|
||||
insertion_point = output.index(self.BINARY_ATTACHMENTS_FORM)
|
||||
return output[:insertion_point] + '''
|
||||
output = self.insert_pad_link(output)
|
||||
|
||||
form_insertion_point = output.index(self.BINARY_ATTACHMENTS_FORM)
|
||||
return output[:form_insertion_point] + '''
|
||||
<form id="pad-box" action="/piratepad/link" method="post">
|
||||
<label for="sidebar_pad_datas">${_("Name")}:</label>
|
||||
<table width="100%">
|
||||
@@ -28,16 +42,7 @@ class SidebarTemplateEditor(openobject.templating.TemplateEditor):
|
||||
</form>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function() {
|
||||
|
||||
var padForm = jQuery('#pad-box').hide();
|
||||
|
||||
jQuery('#attachments').prev().append(
|
||||
jQuery('<a>',{
|
||||
'href': '#',
|
||||
'id': 'add-pad',
|
||||
'class': 'button-a',
|
||||
}).text('${_("Pad")}')
|
||||
);
|
||||
jQuery('#sidebar_pad_ok').bind('click', function(){
|
||||
padForm.submit();
|
||||
});
|
||||
@@ -50,4 +55,4 @@ class SidebarTemplateEditor(openobject.templating.TemplateEditor):
|
||||
});
|
||||
});
|
||||
</script>
|
||||
''' + output[insertion_point:]
|
||||
''' + output[form_insertion_point:]
|
||||
|
||||
Reference in New Issue
Block a user