merge
[odoo/odoo.git] / addons / web_uservoice / web / editors.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010-2011 OpenERP s.a. (<http://openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21 import openobject.templating
22
23 class BaseTemplateEditor(openobject.templating.TemplateEditor):
24     templates = ['/openobject/controllers/templates/base.mako']
25
26     def edit(self, template, template_text):
27         output = super(BaseTemplateEditor, self).edit(template, template_text)
28
29         end_head = output.index('</head>')
30
31         output = output[:end_head] + """
32 <link rel="stylesheet" type="text/css" href="/web_uservoice/static/css/uservoice.css"/>
33         """ + output[end_head:]
34
35
36         end_body = output.index('</body>')
37
38         # testing forum: 84397
39         output = output[:end_body] + """
40 <script type="text/javascript">
41   var uservoiceOptions = {
42     key: 'openerpsa',
43     host: 'feedback.openerp.com',
44     forum: '${getattr(cp.request, 'uservoice_forum', 77459)}',
45     lang: 'en',
46     showTab: false
47   };
48   function _loadUserVoice() {
49     var s = document.createElement('script');
50     s.src = ("https:" == document.location.protocol ? "https://" : "http://") + "cdn.uservoice.com/javascripts/widgets/tab.js";
51     document.getElementsByTagName('head')[0].appendChild(s);
52   }
53   _loadSuper = window.onload;
54   window.onload = (typeof window.onload != 'function') ? _loadUserVoice : function() { _loadSuper(); _loadUserVoice(); };
55 </script>
56         """ + output[end_body:]
57
58         return output
59
60
61 class HeaderTemplateEditor(openobject.templating.TemplateEditor):
62     templates = ['/openerp/controllers/templates/header.mako']
63
64     def edit(self, template, template_text):
65         output = super(HeaderTemplateEditor, self).edit(template, template_text)
66
67         PAT = '<ul class="tools">'
68
69         ul = output.index(PAT)
70         output = output[:ul] + ("""
71             <p class="logout feedback"><a href="#" onclick="UserVoice.Popin.show(uservoiceOptions); return false;"><img src="/web_uservoice/static/images/uv_favicon.png" />%s</a></p>
72         """ % _('feedback')) + output[ul:]
73
74
75         return output
76