1 # -*- coding: utf-8 -*-
2 import openobject.templating
4 class FormEditor(openobject.templating.TemplateEditor):
5 templates = ['/openerp/controllers/templates/form.mako']
6 MAIN_FORM_BODY = u'id="main_form_body"'
8 def insert_share_button(self, output):
9 # Insert the share button on the form title H1 line, at the very end,
10 # but only if the user is a member of the sharing group
11 share_opener_insertion = output.index('% endif', output.index(
12 '/view_diagram/process',
13 output.index(self.MAIN_FORM_BODY))) + len('% endif')
14 return output[:share_opener_insertion] + '''
16 if 'has_share' not in cp.session:
17 cp.session['has_share'] = rpc.RPCProxy('share.wizard').has_share()
19 % if cp.session['has_share'] and buttons.toolbar and not is_dashboard:
20 <a id="share-opener" href="#share" title="${_('Share this in 2 clicks...')}">
21 <img id="share-opener-img" src="/share/static/images/share.png"/>
23 <script type="text/javascript">
24 jQuery(document).ready(function() {
25 jQuery("#share-opener").click(function() {
28 openobject.http.getURL('/share', {
29 context: jQuery("#_terp_context").val(),
30 domain: jQuery("#_terp_domain").val(),
31 view_id: jQuery("#_terp_view_id").val(),
32 action_id: jQuery("#_terp_action_id").val(),
33 search_domain: jQuery("#_terp_view_type").val() == "form" ?
34 ("[('id','=',"+jQuery("#_terp_id").val()+")]") :
35 jQuery("#_terp_search_domain").val(),
42 ''' + output[share_opener_insertion:]
44 def edit(self, template, template_text):
45 return self.insert_share_button(
46 super(FormEditor, self).edit(template, template_text))
49 class SidebarEditor(openobject.templating.TemplateEditor):
50 templates = ['/openerp/widgets/templates/sidebar.mako']
51 ADD_SHARE_SECTION = u'id="sidebar"'
53 def insert_share_link(self, output):
54 # Insert the link on the line, right after the link to open the
55 # attachment form, but only if the user is a member of the sharing group
56 share_opener_insertion = output.index(
58 output.index(self.ADD_SHARE_SECTION)) + 1
59 return output[:share_opener_insertion] + '''
61 if 'has_share' not in cp.session:
62 cp.session['has_share'] = rpc.RPCProxy('share.wizard').has_share()
64 % if cp.session['has_share']:
65 <div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
68 <a id="sharing" href="#share">${_("Share")}</a>
71 <script type="text/javascript">
72 jQuery(document).ready(function() {
73 jQuery("#sharing").click(function() {
76 openobject.http.getURL('/share', {
77 context: jQuery("#_terp_context").val(),
78 domain: jQuery("#_terp_domain").val(),
79 view_id: jQuery("#_terp_view_id").val(),
80 action_id: jQuery("#_terp_action_id").val(),
81 search_domain: jQuery("#_terp_view_type").val() == "form" ?
82 ("[('id','=',"+jQuery("#_terp_id").val()+")]") :
83 jQuery("#_terp_search_domain").val(),
90 ''' + output[share_opener_insertion:]
92 def edit(self, template, template_text):
93 return self.insert_share_link(
94 super(SidebarEditor, self).edit(template, template_text))