[MERGE] backport of share and pad modules bugfixes
[odoo/odoo.git] / addons / share / web / editors.py
1 # -*- coding: utf-8 -*-
2 import openobject.templating
3
4 class ShareActionEditor(openobject.templating.TemplateEditor):
5     templates = ['/openerp/widgets/templates/sidebar.mako']
6     ADD_SHARE_SECTION = u'id="sidebar"'
7
8     def insert_share_link(self, output):
9         # Insert the link on the line right after the link to open the
10         # attachment form
11         share_opener_insertion = output.index(
12                 '\n',
13                 output.index(self.ADD_SHARE_SECTION)) + 1
14         return output[:share_opener_insertion] + \
15                '''<div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
16                      <ul class="clean-a">
17                          <li>
18                              <a id="sharing" href="#share">${_("Share")}</a>
19                          </li>
20                      </ul>
21                        <script type="text/javascript">
22                            jQuery(document).ready(function() {
23                                jQuery("#sharing").click(function() {
24                                    jQuery(this).attr(
25                                        "href",
26                                        openobject.http.getURL('/share', {
27                                            context: jQuery("#_terp_context").val(),
28                                            domain: jQuery("#_terp_domain").val(),
29                                            view_id: jQuery("#_terp_view_id").val(),
30                                            search_domain: jQuery("#_terp_search_domain").val(),
31                                    }));
32                                });
33                            });
34                        </script>
35                        \n''' + \
36                 output[share_opener_insertion:]
37
38     def edit(self, template, template_text):
39         return self.insert_share_link(
40             super(ShareActionEditor, self).edit(template, template_text))