2011-10-10 14:29:53 +00:00
|
|
|
|
|
|
|
openerp.share = function(instance) {
|
|
|
|
|
2011-10-14 12:12:12 +00:00
|
|
|
function launch_wizard(self, view) {
|
2011-10-10 14:29:53 +00:00
|
|
|
var action = view.widget_parent.action;
|
2011-10-14 12:12:12 +00:00
|
|
|
var Share = new instance.web.DataSet(self, 'share.wizard', view.dataset.get_context());
|
2011-10-25 10:06:07 +00:00
|
|
|
var domain = view.dataset.domain;
|
2011-10-10 14:29:53 +00:00
|
|
|
|
2011-10-14 12:12:12 +00:00
|
|
|
if (view.fields_view.type == 'form') {
|
|
|
|
domain = new instance.web.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
|
|
|
|
}
|
2011-10-10 14:29:53 +00:00
|
|
|
|
|
|
|
Share.create({
|
|
|
|
name: action.name,
|
2011-10-14 12:12:12 +00:00
|
|
|
domain: domain,
|
2011-10-10 14:29:53 +00:00
|
|
|
action_id: action.id,
|
2011-11-15 15:56:30 +00:00
|
|
|
view_type: view.fields_view.type,
|
2011-10-10 14:29:53 +00:00
|
|
|
}, function(result) {
|
|
|
|
var share_id = result.result;
|
|
|
|
var step1 = Share.call('go_step_1', [[share_id],], function(result) {
|
|
|
|
var action = result;
|
|
|
|
self.do_action(action);
|
|
|
|
});
|
|
|
|
});
|
2011-10-14 12:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _has_share = null;
|
|
|
|
function if_has_share(yes, no) {
|
|
|
|
if (!_has_share) {
|
|
|
|
_has_share = $.Deferred(function() {
|
|
|
|
var self = this;
|
2011-11-10 10:21:53 +00:00
|
|
|
instance.connection.on_session_invalid.add_last(function() { _has_share = null; });
|
|
|
|
var func = new instance.web.Model(null, "share.wizard").get_func("has_share");
|
|
|
|
func(instance.connection.uid).pipe(function(res) {
|
2011-10-14 12:12:12 +00:00
|
|
|
if(res) {
|
|
|
|
self.resolve();
|
|
|
|
} else {
|
|
|
|
self.reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
_has_share.done(yes).fail(no);
|
|
|
|
}
|
2011-10-10 14:29:53 +00:00
|
|
|
|
2011-10-14 12:12:12 +00:00
|
|
|
|
|
|
|
instance.web.Sidebar = instance.web.Sidebar.extend({
|
|
|
|
add_default_sections: function() {
|
|
|
|
this._super();
|
|
|
|
var self = this;
|
|
|
|
if_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.widget_parent
|
|
|
|
launch_wizard(this, view);
|
2011-10-10 14:29:53 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2011-10-14 12:12:12 +00:00
|
|
|
instance.web.ViewManagerAction.include({
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
if_has_share(function() {
|
|
|
|
self.$element.find('a.oe-share').click(self.on_click_share);
|
|
|
|
}, function() {
|
|
|
|
self.$element.find('a.oe-share').remove();
|
|
|
|
});
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
on_click_share: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
launch_wizard(this, this.views[this.active_view].controller);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2011-10-10 14:29:53 +00:00
|
|
|
};
|