[FIX] Fixed invite button not working after an interal redirection, due to a non-existent action. All sahre buttons are now hidden, unless an action is defined.

bzr revid: tde@openerp.com-20120406094112-v2yz130irskanxuj
This commit is contained in:
Thibault Delavallée 2012-04-06 11:41:12 +02:00
parent 9627bc9a92
commit 576ce50356
3 changed files with 90 additions and 61 deletions

View File

@ -695,7 +695,7 @@ class mail_thread(osv.osv):
# escape if in install mode or note writing was not successfull
if 'install_mode' in context:
return True
if not isinstance(msg_ids(list)):
if not isinstance(msg_ids, (list)):
return True
# get already existing notigications
notification_ids = notification_obj.search(cr, uid, [('message_id', 'in', msg_ids)], context=context)

View File

@ -1,3 +1,8 @@
button.oe-share-mail {
width: 120px;
display: none;
}
a.oe-share_link, a.oe-share {
display: none;
}

View File

@ -1,7 +1,9 @@
openerp.share = function(session) {
function launch_wizard(self, view, user_type, invite) {
var has_action_id = false;
function launch_wizard(self, view, user_type, invite) {
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);
@ -30,68 +32,90 @@ function launch_wizard(self, view, user_type, invite) {
});
});
});
}
function has_share(yes, no) {
if (!session.connection.share_flag) {
session.connection.share_flag = $.Deferred(function() {
var func = new session.web.Model("share.wizard").get_func("has_share");
func(session.connection.uid).pipe(function(res) {
if(res) {
session.connection.share_flag.resolve();
} else {
session.connection.share_flag.reject();
}
});
});
}
session.connection.share_flag.done(yes).fail(no);
}
session.web.Sidebar = session.web.Sidebar.extend({
add_default_sections: function() {
this._super();
var self = this;
has_share(function() {
self.add_items('other', [{
label: 'Share',
callback: self.on_sidebar_click_share,
classname: 'oe-share',
}]);
});
},
on_sidebar_click_share: function(item) {
var view = this.getParent()
launch_wizard(this, view);
},
});
function has_share(yes, no) {
if (!session.connection.share_flag) {
session.connection.share_flag = $.Deferred(function() {
var func = new session.web.Model("share.wizard").get_func("has_share");
func(session.connection.uid).pipe(function(res) {
if(res) {
session.connection.share_flag.resolve();
} else {
session.connection.share_flag.reject();
}
});
});
}
session.connection.share_flag.done(yes).fail(no);
}
session.web.ViewManagerAction.include({
start: function() {
var self = this;
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('button.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();
});
return this._super.apply(this, arguments);
},
on_click_share_link: function(e) {
e.preventDefault();
launch_wizard(this, this.views[this.active_view].controller, 'embedded', false);
},
on_click_share: function(e) {
e.preventDefault();
launch_wizard(this, this.views[this.active_view].controller, 'emails', false);
},
on_click_share_mail: function(e) {
e.preventDefault();
launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
},
});
session.web.Sidebar = session.web.Sidebar.extend({
add_default_sections: function() {
this._super();
var self = this;
has_share(function() {
self.add_items('other', [{
label: 'Share',
callback: self.on_sidebar_click_share,
classname: 'oe-share',
}]);
});
},
on_sidebar_click_share: function(item) {
var view = this.getParent()
launch_wizard(this, view);
},
});
session.mail.RecordThread.include( {
start: function() {
start_res = this._super.apply(this, arguments);
if (has_action_id) {
this.$element.find('button.oe-share-mail').show();
}
return start_res;
}
});
session.web.ViewManagerAction.include({
start: function() {
var self = this;
this.check_if_action_is_defined();
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('button.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();
});
return this._super.apply(this, arguments);
},
check_if_action_is_defined: function() {
if (this.action && this.action.id) {
has_action_id = true;
this.$element.find('a.oe-share_link').show();
this.$element.find('a.oe-share').show();
}
else {
has_action_id = false;
}
},
on_click_share_link: function(e) {
e.preventDefault();
launch_wizard(this, this.views[this.active_view].controller, 'embedded', false);
},
on_click_share: function(e) {
e.preventDefault();
launch_wizard(this, this.views[this.active_view].controller, 'emails', false);
},
on_click_share_mail: function(e) {
e.preventDefault();
launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
},
});
};