[IMP] share: update module to accept an 'invite' action, that is alike share, but used for OpenSocial. Share now also adds the 'invite' feature to OpenSocial.
bzr revid: tde@openerp.com-20120320180917-gj2c0tetyerfuprr
This commit is contained in:
parent
6ae73d5311
commit
3a1e1ce480
|
@ -1,7 +1,7 @@
|
|||
|
||||
openerp.share = function(session) {
|
||||
|
||||
function launch_wizard(self, view, user_type) {
|
||||
function launch_wizard(self, view, user_type, subscribe) {
|
||||
var action = view.getParent().action;
|
||||
var Share = new session.web.DataSet(self, 'share.wizard', view.dataset.get_context());
|
||||
var domain = new session.web.CompoundDomain(view.dataset.domain);
|
||||
|
@ -18,6 +18,7 @@ function launch_wizard(self, view, user_type) {
|
|||
action_id: action.id,
|
||||
user_type: user_type || 'embedded',
|
||||
view_type: view.fields_view.type,
|
||||
subscribe: subscribe || false,
|
||||
}, function(result) {
|
||||
var share_id = result.result;
|
||||
var step1 = Share.call('go_step_1', [[share_id],], function(result) {
|
||||
|
@ -68,6 +69,7 @@ session.web.ViewManagerAction.include({
|
|||
has_share(function() {
|
||||
self.$element.find('a.oe-share_link').click(self.on_click_share_link);
|
||||
self.$element.find('a.oe-share').click(self.on_click_share);
|
||||
self.$element.delegate('a.oe-share-mail', 'click', self.on_click_share_mail);
|
||||
}, function() {
|
||||
self.$element.find('a.oe-share_link').remove();
|
||||
self.$element.find('a.oe-share').remove();
|
||||
|
@ -82,6 +84,10 @@ session.web.ViewManagerAction.include({
|
|||
e.preventDefault();
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'emails');
|
||||
},
|
||||
on_click_share_mail: function(e) {
|
||||
e.preventDefault();
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -10,4 +10,11 @@
|
|||
</t>
|
||||
</t>
|
||||
|
||||
<t t-extend="RecordThread">
|
||||
<t t-jquery=".oe_mail_button_follow" t-operation="before">
|
||||
<a class="oe-share-mail" href="#share" title="Share with..."><img t-att-src='_s + "/share/static/src/img/share.png"'/></a>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
|
||||
</templates>
|
||||
|
|
|
@ -165,6 +165,10 @@ class share_wizard(osv.osv_memory):
|
|||
'user_type': fields.selection(lambda s, *a, **k: s._user_type_selection(*a, **k),'Sharing method', required=True,
|
||||
help="Select the type of user(s) you would like to share data with."),
|
||||
'new_users': fields.text("Emails"),
|
||||
'email_1': fields.char('New user email', size=64),
|
||||
'email_2': fields.char('New user email', size=64),
|
||||
'email_3': fields.char('New user email', size=64),
|
||||
'invite': fields.boolean('Invite users to OpenSocial record'),
|
||||
'access_mode': fields.selection([('readonly','Can view'),('readwrite','Can edit')],'Access Mode', required=True,
|
||||
help="Access rights to be granted on the shared documents."),
|
||||
'result_line_ids': fields.one2many('share.wizard.result.line', 'share_wizard_id', 'Summary', readonly=True),
|
||||
|
@ -181,6 +185,7 @@ class share_wizard(osv.osv_memory):
|
|||
_defaults = {
|
||||
'view_type': 'page',
|
||||
'user_type' : 'embedded',
|
||||
'invite': False,
|
||||
'domain': lambda self, cr, uid, context, *a: context.get('domain', '[]'),
|
||||
'action_id': lambda self, cr, uid, context, *a: context.get('action_id'),
|
||||
'access_mode': 'readonly',
|
||||
|
@ -192,11 +197,14 @@ class share_wizard(osv.osv_memory):
|
|||
return bool(self.pool.get('res.users').browse(cr, uid, uid, context=context).user_email)
|
||||
|
||||
def go_step_1(self, cr, uid, ids, context=None):
|
||||
user_type = self.browse(cr,uid,ids,context)[0].user_type
|
||||
if user_type == 'emails' and not self.has_email(cr, uid, context=context):
|
||||
wizard_data = self.browse(cr,uid,ids,context)[0]
|
||||
if wizard_data.user_type == 'emails' and not self.has_email(cr, uid, context=context):
|
||||
raise osv.except_osv(_('No e-mail address configured'),
|
||||
_('You must configure your e-mail address in the user preferences before using the Share button.'))
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1')
|
||||
if wizard_data.invite:
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1_mail')
|
||||
else:
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1')
|
||||
action = self.pool.get(model).read(cr, uid, res_id, context=context)
|
||||
action['res_id'] = ids[0]
|
||||
action.pop('context', '')
|
||||
|
@ -223,12 +231,18 @@ class share_wizard(osv.osv_memory):
|
|||
created_ids = []
|
||||
existing_ids = []
|
||||
if wizard_data.user_type == 'emails':
|
||||
for new_user in (wizard_data.new_users or '').split('\n'):
|
||||
# get new user list from email data
|
||||
new_users = (wizard_data.new_users or '').split('\n')
|
||||
new_users += [wizard_data.email_1 or '', wizard_data.email_2 or '', wizard_data.email_3 or '']
|
||||
for new_user in new_users:
|
||||
# Ignore blank lines
|
||||
new_user = new_user.strip()
|
||||
if not new_user: continue
|
||||
# Ignore the user if it already exists.
|
||||
existing = user_obj.search(cr, UID_ROOT, [('login', '=', new_user)])
|
||||
if not wizard_data.invite:
|
||||
existing = user_obj.search(cr, UID_ROOT, [('login', '=', new_user)])
|
||||
else:
|
||||
existing = user_obj.search(cr, UID_ROOT, [('user_email', '=', new_user)])
|
||||
existing_ids.extend(existing)
|
||||
if existing:
|
||||
new_line = { 'user_id': existing[0],
|
||||
|
@ -643,7 +657,7 @@ class share_wizard(osv.osv_memory):
|
|||
_('You must be a member of the Share/User group to use the share wizard'),
|
||||
context=context)
|
||||
if wizard_data.user_type == 'emails':
|
||||
self._assert(wizard_data.new_users,
|
||||
self._assert((wizard_data.new_users or wizard_data.email_1 or wizard_data.email_2 or wizard_data.email_3),
|
||||
_('Please indicate the emails of the persons to share with, one per line'),
|
||||
context=context)
|
||||
|
||||
|
@ -667,21 +681,21 @@ class share_wizard(osv.osv_memory):
|
|||
if new_ids:
|
||||
# new users need a new shortcut AND a home action
|
||||
self._setup_action_and_shortcut(cr, uid, wizard_data, new_ids, make_home=True, context=context)
|
||||
return group_id
|
||||
return group_id, new_ids, existing_ids
|
||||
|
||||
def go_step_2(self, cr, uid, ids, context=None):
|
||||
wizard_data = self.browse(cr, uid, ids[0], context=context)
|
||||
self._check_preconditions(cr, uid, wizard_data, context=context)
|
||||
|
||||
# Create shared group and users
|
||||
group_id = self._create_share_users_group(cr, uid, wizard_data, context=context)
|
||||
group_id, new_ids, existing_ids = self._create_share_users_group(cr, uid, wizard_data, context=context)
|
||||
|
||||
current_user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
|
||||
model_obj = self.pool.get('ir.model')
|
||||
model_id = model_obj.search(cr, uid, [('model','=', wizard_data.action_id.res_model)])[0]
|
||||
model = model_obj.browse(cr, uid, model_id, context=context)
|
||||
|
||||
|
||||
# ACCESS RIGHTS
|
||||
# We have several classes of objects that should receive different access rights:
|
||||
# Let:
|
||||
|
@ -731,6 +745,14 @@ class share_wizard(osv.osv_memory):
|
|||
|
||||
# refresh wizard_data
|
||||
wizard_data = self.browse(cr, uid, ids[0], context=context)
|
||||
|
||||
# Invite (OpenSocial): automatically subscribe users to the record
|
||||
res_id = 0
|
||||
for cond in safe_eval(main_domain):
|
||||
if cond[0] == 'id':
|
||||
res_id = cond[2]
|
||||
if wizard_data.invite and res_id > 0:
|
||||
self.pool.get(model.model).message_subscribe(cr, uid, [res_id], new_ids + existing_ids, context=context)
|
||||
|
||||
# send the confirmation emails:
|
||||
self.send_emails(cr, uid, wizard_data, context=context)
|
||||
|
|
|
@ -52,6 +52,37 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record id="share_step1_mail_form" model="ir.ui.view">
|
||||
<field name="name">share.step1_mail.form</field>
|
||||
<field name="model">share.wizard</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="user_type" invisible="1"/>
|
||||
<group colspan="4" name="emails_group" attrs="{'invisible':[('user_type', '!=', 'emails')]}">
|
||||
<separator colspan="4" string="Share with these people (one e-mail per line)"/>
|
||||
<field name="email_1"/>
|
||||
<field name="email_2"/>
|
||||
<field name="email_3"/>
|
||||
</group>
|
||||
<group colspan="4" col="4" attrs="{'invisible':[('user_type', '=', 'embedded')]}">
|
||||
<separator colspan="4" string="Optional: include a personal message"/>
|
||||
<field name="message" colspan="4" nolabel="1"/>
|
||||
</group>
|
||||
<separator colspan="4" string="Sharing Options"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="access_mode" colspan="4"/>
|
||||
</group>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
|
||||
<button name="go_step_2" string="Share" colspan="1" type="object" icon="gtk-go-forward"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="share_step2_form" model="ir.ui.view">
|
||||
<field name="name">share.step2.form</field>
|
||||
<field name="model">share.wizard</field>
|
||||
|
@ -121,5 +152,16 @@
|
|||
<field name="context">False</field>
|
||||
</record>
|
||||
|
||||
<record id="action_share_wizard_step1_mail" model="ir.actions.act_window">
|
||||
<field name="name">Share your documents</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">share.wizard</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="share_step1_mail_form"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">False</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue