2 openerp.share = function(session) {
3 var _t = session.web._t;
4 var has_action_id = false;
6 function launch_wizard(self, view, user_type, invite) {
7 var action = view.getParent().action;
8 var Share = new session.web.DataSet(self, 'share.wizard', view.dataset.get_context());
9 var domain = new session.web.CompoundDomain(view.dataset.domain);
10 if (view.fields_view.type == 'form') {
11 domain = new session.web.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
13 if (view.fields_view.type == 'form') rec_name = view.datarecord.name;
15 session.web.pyeval.eval_domains_and_contexts({
17 contexts: [Share.get_context()]
18 }).done(function (result) {
21 record_name: rec_name,
22 domain: result.domain,
24 user_type: user_type || 'embedded',
25 view_type: view.fields_view.type,
26 invite: invite || false,
27 }).done(function(share_id) {
28 var step1 = Share.call('go_step_1', [[share_id], Share.get_context()]).done(function(result) {
30 self.do_action(action);
36 function has_share(yes, no) {
37 if (!session.session.share_flag) {
38 session.session.share_flag = $.Deferred(function() {
39 var func = new session.web.Model("share.wizard").get_func("has_share");
40 func(session.session.uid).then(function(res) {
42 session.session.share_flag.resolve();
44 session.session.share_flag.reject();
49 session.session.share_flag.done(yes).fail(no);
52 /* Extend the Sidebar to add Share and Embed links in the 'More' menu */
53 session.web.Sidebar = session.web.Sidebar.extend({
58 has_share(function() {
59 self.add_items('other', [
61 callback: self.on_click_share,
62 classname: 'oe_share' },
64 callback: self.on_click_share_link,
65 classname: 'oe_share' },
70 on_click_share: function(item) {
71 var view = this.getParent()
72 launch_wizard(this, view, 'emails', false);
75 on_click_share_link: function(item) {
76 var view = this.getParent()
77 launch_wizard(this, view, 'embedded', false);
82 * Extends mail (Chatter widget)
83 * - show the 'invite' button' only we came on the form view through
84 * an action. We do this because 'invite' is based on the share
85 * mechanism, and it tries to share an action.
87 session.mail.RecordThread.include( {
89 start_res = this._super.apply(this, arguments);
91 this.$el.find('button.oe_share_invite').show();
97 session.web.ViewManagerAction.include({
100 this.check_if_action_is_defined();
101 has_share(function() {
102 self.$el.delegate('button.oe_share_invite', 'click', self.on_click_share_invite);
104 return this._super.apply(this, arguments);
107 check_if_action_is_defined: function() {
108 if (this.action && this.action.id) {
109 has_action_id = true;
112 has_action_id = false;
116 on_click_share_invite: function(e) {
118 launch_wizard(this, this.views[this.active_view].controller, 'emails', true);