[IMP] share: convert web part to v6.1

bzr revid: chs@openerp.com-20111010142953-90ylj17cc1416o5f
This commit is contained in:
Christophe Simonis 2011-10-10 16:29:53 +02:00
parent a1e5797727
commit cb7cc66a2e
6 changed files with 53 additions and 147 deletions

View File

@ -3,6 +3,7 @@
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2010-2011 OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@ -22,7 +23,7 @@
{
"name" : "Web Share",
"version" : "1.5",
"version" : "2.0",
"depends" : ["base", "mail"],
"author" : "OpenERP SA",
"category": 'Hidden',
@ -53,7 +54,9 @@ synchronization with other companies, etc.
'installable': True,
'web': True,
'certificate' : '001301246528927038493',
'images': ['images/share_wizard.jpeg','images/sharing_wizard_step1.jpeg', 'images/sharing_wizard_step2.jpeg'],
'js': ['static/src/js/share.js'],
'css': ['static/src/css/share.css'],
'images': ['static/src/img/share_wizard.jpeg','static/src/img/sharing_wizard_step1.jpeg', 'static/src/img/sharing_wizard_step2.jpeg'],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,5 @@
.openerp li.oe_share {
background: url(../img/share.png) no-repeat;
padding-left: 20px;
}

View File

@ -0,0 +1,43 @@
openerp.share = function(instance) {
instance.web.Sidebar = instance.web.Sidebar.extend({
add_default_sections: function() {
this._super();
this.add_items('Sharing', [{
label: 'Share',
callback: this.on_sidebar_click_share,
classname: 'oe_share',
}]);
},
on_sidebar_click_share: function(item) {
var self = this;
var view = this.widget_parent
var action = view.widget_parent.action;
var share_url_template = _('%s//%s/?db=%%(dbname)s&login=%%(login)s').sprintf(document.location.protocol, document.location.host);
var Share = new instance.web.DataSet(this, 'share.wizard', view.dataset.get_context());
Share.create({
name: action.name,
domain: view.dataset.domain,
action_id: action.id,
share_url_template: share_url_template,
}, function(result) {
var share_id = result.result;
console.log('share_id', share_id);
var step1 = Share.call('go_step_1', [[share_id],], function(result) {
var action = result;
console.log('step1', action);
self.do_action(action);
});
});
},
});
};

View File

@ -1,2 +0,0 @@
import controllers
import editors

View File

@ -1,49 +0,0 @@
import urlparse
import cherrypy
from openobject import rpc
from openobject.tools import expose, ast
import openerp.controllers
class ShareWizardController(openerp.controllers.SecuredController):
_cp_path = "/share"
@expose()
def index(self, domain, context, view_id, search_domain='[]', action_id=None):
context = ast.literal_eval(context)
if not action_id:
# This should not be needed anymore, but just in case users are
# running the module with an older version of the web client...
# to remove soon-ish
action_id = rpc.RPCProxy('ir.actions.act_window').search(
[('view_id','=',int(view_id))], context=context)
if not action_id: return ""
action_id = action_id[0]
domain = ast.literal_eval(domain)
domain.extend(ast.literal_eval(search_domain))
scheme, netloc, _, _, _ = urlparse.urlsplit(cherrypy.request.base)
share_root_url = urlparse.urlunsplit((
scheme, netloc, '/openerp/login',
'db=%(dbname)s&user=%(login)s&password=%(password)s', ''))
context.update(
#active_ids=share_wiz_id,
#active_id=share_wiz_id[0],
_terp_view_name='Share Wizard',
share_root_url=share_root_url)
Share = rpc.RPCProxy('share.wizard')
sharing_view_id = Share.create({
'domain': str(domain),
'action_id': action_id and int(action_id)
}, context)
return openerp.controllers.actions.execute(
Share.go_step_1([sharing_view_id], context),
ids=[sharing_view_id], context=context)

View File

@ -1,94 +0,0 @@
# -*- coding: utf-8 -*-
import openobject.templating
class FormEditor(openobject.templating.TemplateEditor):
templates = ['/openerp/controllers/templates/form.mako']
MAIN_FORM_BODY = u'id="main_form_body"'
def insert_share_button(self, output):
# Insert the share button on the form title H1 line, at the very end,
# but only if the user is a member of the sharing group
share_opener_insertion = output.index('% endif', output.index(
'/view_diagram/process',
output.index(self.MAIN_FORM_BODY))) + len('% endif')
return output[:share_opener_insertion] + '''
<%
if 'has_share' not in cp.session:
cp.session['has_share'] = rpc.RPCProxy('share.wizard').has_share()
%>
% if cp.session['has_share'] and buttons.toolbar and not is_dashboard:
<a id="share-opener" href="#share" title="${_('Share this in 2 clicks...')}">
<img id="share-opener-img" src="/share/static/images/share.png"/>
</a>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#share-opener").click(function() {
jQuery(this).attr(
"href",
openobject.http.getURL('/share', {
context: jQuery("#_terp_context").val(),
domain: jQuery("#_terp_domain").val(),
view_id: jQuery("#_terp_view_id").val(),
action_id: jQuery("#_terp_action_id").val(),
search_domain: jQuery("#_terp_view_type").val() == "form" ?
("[('id','=',"+jQuery("#_terp_id").val()+")]") :
jQuery("#_terp_search_domain").val(),
}));
});
});
</script>
\n
% endif
''' + output[share_opener_insertion:]
def edit(self, template, template_text):
return self.insert_share_button(
super(FormEditor, self).edit(template, template_text))
class SidebarEditor(openobject.templating.TemplateEditor):
templates = ['/openerp/widgets/templates/sidebar.mako']
ADD_SHARE_SECTION = u'id="sidebar"'
def insert_share_link(self, output):
# Insert the link on the line, right after the link to open the
# attachment form, but only if the user is a member of the sharing group
share_opener_insertion = output.index(
'\n',
output.index(self.ADD_SHARE_SECTION)) + 1
return output[:share_opener_insertion] + '''
<%
if 'has_share' not in cp.session:
cp.session['has_share'] = rpc.RPCProxy('share.wizard').has_share()
%>
% if cp.session['has_share']:
<div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
<ul class="clean-a">
<li>
<a id="sharing" href="#share">${_("Share")}</a>
</li>
</ul>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#sharing").click(function() {
jQuery(this).attr(
"href",
openobject.http.getURL('/share', {
context: jQuery("#_terp_context").val(),
domain: jQuery("#_terp_domain").val(),
view_id: jQuery("#_terp_view_id").val(),
action_id: jQuery("#_terp_action_id").val(),
search_domain: jQuery("#_terp_view_type").val() == "form" ?
("[('id','=',"+jQuery("#_terp_id").val()+")]") :
jQuery("#_terp_search_domain").val(),
}));
});
});
</script>
\n
% endif
''' + output[share_opener_insertion:]
def edit(self, template, template_text):
return self.insert_share_link(
super(SidebarEditor, self).edit(template, template_text))