2011-10-10 14:29:53 +00:00
|
|
|
|
2011-12-27 20:36:18 +00:00
|
|
|
openerp.share = function(session) {
|
2011-10-10 14:29:53 +00:00
|
|
|
|
2012-04-06 09:41:12 +00:00
|
|
|
var has_action_id = false;
|
|
|
|
|
|
|
|
function launch_wizard(self, view, user_type, invite) {
|
2012-02-21 16:45:36 +00:00
|
|
|
var action = view.getParent().action;
|
2011-12-27 20:36:18 +00:00
|
|
|
var Share = new session.web.DataSet(self, 'share.wizard', view.dataset.get_context());
|
|
|
|
var domain = new session.web.CompoundDomain(view.dataset.domain);
|
2011-10-14 12:12:12 +00:00
|
|
|
if (view.fields_view.type == 'form') {
|
2011-12-27 20:36:18 +00:00
|
|
|
domain = new session.web.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
|
2011-10-14 12:12:12 +00:00
|
|
|
}
|
2012-03-28 09:00:52 +00:00
|
|
|
if (view.fields_view.type == 'form') rec_name = view.datarecord.name;
|
|
|
|
else rec_name = '';
|
2011-12-14 17:35:29 +00:00
|
|
|
self.rpc('/web/session/eval_domain_and_context', {
|
|
|
|
domains: [domain],
|
|
|
|
contexts: [view.dataset.context]
|
|
|
|
}, function (result) {
|
|
|
|
Share.create({
|
|
|
|
name: action.name,
|
2012-03-28 09:00:52 +00:00
|
|
|
record_name: rec_name,
|
2011-12-14 17:35:29 +00:00
|
|
|
domain: result.domain,
|
|
|
|
action_id: action.id,
|
2011-12-21 16:11:35 +00:00
|
|
|
user_type: user_type || 'embedded',
|
2011-12-16 15:49:12 +00:00
|
|
|
view_type: view.fields_view.type,
|
2012-03-27 10:14:53 +00:00
|
|
|
invite: invite || false,
|
2011-12-14 17:35:29 +00:00
|
|
|
}, function(result) {
|
|
|
|
var share_id = result.result;
|
2011-12-21 16:11:35 +00:00
|
|
|
var step1 = Share.call('go_step_1', [[share_id],], function(result) {
|
2011-12-14 17:35:29 +00:00
|
|
|
var action = result;
|
|
|
|
self.do_action(action);
|
|
|
|
});
|
2011-10-10 14:29:53 +00:00
|
|
|
});
|
|
|
|
});
|
2012-04-06 09:41:12 +00:00
|
|
|
}
|
2011-10-14 12:12:12 +00:00
|
|
|
|
2012-04-06 09:41:12 +00:00
|
|
|
function has_share(yes, no) {
|
2012-08-14 15:30:53 +00:00
|
|
|
if (!session.session.share_flag) {
|
|
|
|
session.session.share_flag = $.Deferred(function() {
|
2012-04-06 09:41:12 +00:00
|
|
|
var func = new session.web.Model("share.wizard").get_func("has_share");
|
2012-08-14 15:30:53 +00:00
|
|
|
func(session.session.uid).pipe(function(res) {
|
2012-04-06 09:41:12 +00:00
|
|
|
if(res) {
|
2012-08-14 15:30:53 +00:00
|
|
|
session.session.share_flag.resolve();
|
2012-04-06 09:41:12 +00:00
|
|
|
} else {
|
2012-08-14 15:30:53 +00:00
|
|
|
session.session.share_flag.reject();
|
2012-04-06 09:41:12 +00:00
|
|
|
}
|
|
|
|
});
|
2011-12-27 20:36:18 +00:00
|
|
|
});
|
2012-04-06 09:41:12 +00:00
|
|
|
}
|
2012-08-14 15:30:53 +00:00
|
|
|
session.session.share_flag.done(yes).fail(no);
|
2011-12-27 20:36:18 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 12:25:30 +00:00
|
|
|
/* Extend the Sidebar to add Share and Embed links in the 'More' menu */
|
2012-04-06 09:41:12 +00:00
|
|
|
session.web.Sidebar = session.web.Sidebar.extend({
|
2012-06-29 12:25:30 +00:00
|
|
|
|
|
|
|
start: function() {
|
2012-04-06 09:41:12 +00:00
|
|
|
var self = this;
|
2012-06-29 12:25:30 +00:00
|
|
|
this._super(this);
|
2012-04-06 09:41:12 +00:00
|
|
|
has_share(function() {
|
2012-06-29 12:25:30 +00:00
|
|
|
self.add_items('other', [
|
|
|
|
{ label: 'Share',
|
2012-06-29 13:56:57 +00:00
|
|
|
callback: self.on_click_share,
|
2012-06-29 12:33:26 +00:00
|
|
|
classname: 'oe_share' },
|
2012-06-29 12:25:30 +00:00
|
|
|
{ label: 'Embed',
|
2012-06-29 13:56:57 +00:00
|
|
|
callback: self.on_click_share_link,
|
2012-06-29 12:33:26 +00:00
|
|
|
classname: 'oe_share' },
|
2012-06-29 12:25:30 +00:00
|
|
|
]);
|
2012-04-06 09:41:12 +00:00
|
|
|
});
|
|
|
|
},
|
2012-06-29 12:25:30 +00:00
|
|
|
|
2012-06-29 13:56:57 +00:00
|
|
|
on_click_share: function(item) {
|
2012-04-06 09:41:12 +00:00
|
|
|
var view = this.getParent()
|
2012-06-29 13:56:57 +00:00
|
|
|
launch_wizard(this, view, 'emails', false);
|
|
|
|
},
|
|
|
|
|
|
|
|
on_click_share_link: function(item) {
|
|
|
|
var view = this.getParent()
|
|
|
|
launch_wizard(this, view, 'embedded', false);
|
2012-04-06 09:41:12 +00:00
|
|
|
},
|
|
|
|
});
|
2011-10-10 14:29:53 +00:00
|
|
|
|
2012-06-29 08:06:07 +00:00
|
|
|
/**
|
|
|
|
* Extends mail (Chatter widget)
|
|
|
|
* - show the 'invite' button' only we came on the form view through
|
|
|
|
* an action. We do this because 'invite' is based on the share
|
|
|
|
* mechanism, and it tries to share an action.
|
|
|
|
*/
|
2012-04-06 09:41:12 +00:00
|
|
|
session.mail.RecordThread.include( {
|
|
|
|
start: function() {
|
|
|
|
start_res = this._super.apply(this, arguments);
|
|
|
|
if (has_action_id) {
|
2012-06-29 13:56:57 +00:00
|
|
|
this.$element.find('button.oe_share_invite').show();
|
2012-04-06 09:41:12 +00:00
|
|
|
}
|
|
|
|
return start_res;
|
|
|
|
}
|
|
|
|
});
|
2011-10-14 12:12:12 +00:00
|
|
|
|
2012-04-06 09:41:12 +00:00
|
|
|
session.web.ViewManagerAction.include({
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this.check_if_action_is_defined();
|
|
|
|
has_share(function() {
|
2012-06-29 13:56:57 +00:00
|
|
|
self.$element.delegate('button.oe_share_invite', 'click', self.on_click_share_invite);
|
2012-04-06 09:41:12 +00:00
|
|
|
});
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
check_if_action_is_defined: function() {
|
|
|
|
if (this.action && this.action.id) {
|
|
|
|
has_action_id = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
has_action_id = false;
|
|
|
|
}
|
|
|
|
},
|
2012-06-29 13:56:57 +00:00
|
|
|
|
|
|
|
on_click_share_invite: function(e) {
|
2012-04-06 09:41:12 +00:00
|
|
|
e.preventDefault();
|
|
|
|
launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
|
|
|
|
},
|
|
|
|
});
|
2011-10-10 14:29:53 +00:00
|
|
|
};
|
2011-12-27 20:36:18 +00:00
|
|
|
|