[IMP] share
authorChristophe Simonis <chs@openerp.com>
Fri, 14 Oct 2011 12:12:12 +0000 (14:12 +0200)
committerChristophe Simonis <chs@openerp.com>
Fri, 14 Oct 2011 12:12:12 +0000 (14:12 +0200)
bzr revid: chs@openerp.com-20111014121212-zyipo1v68rm7f64c

addons/share/static/src/css/share.css
addons/share/static/src/js/share.js

index 781bfe1..3b47a06 100644 (file)
@@ -1,5 +1,13 @@
 
-.openerp li.oe_share {
+.openerp li.oe-share {
     background: url(../img/share.png) no-repeat;
     padding-left: 20px;
 }
+
+.openerp a.oe-share {
+    background: url(../img/share.png) no-repeat;
+    display: block;
+    float: left;
+    width: 20px;
+    height: 20px;
+}
index 68df8ee..391d2ce 100644 (file)
@@ -1,41 +1,91 @@
 
 openerp.share = function(instance) {
+var QWeb = instance.web.qweb;
+QWeb.add_template('/share/static/src/xml/share.xml');
 
-instance.web.Sidebar = instance.web.Sidebar.extend({
-
-    add_default_sections: function() {
-        this._super();
-        this.add_items('other', [{
-            label: 'Share',
-            callback: this.on_sidebar_click_share,
-            classname: 'oe_share',
-        }]);
-    },
+function launch_wizard(self, view) {
 
-    on_sidebar_click_share: function(item) {
-        var self = this;
-        var view = this.widget_parent
         var action = view.widget_parent.action;
+        var Share = new instance.web.DataSet(self, 'share.wizard', view.dataset.get_context());
 
-        var Share = new instance.web.DataSet(this, 'share.wizard', view.dataset.get_context());
+        console.log(view);
+        
+        domain = view.dataset.domain;
+        if (view.fields_view.type == 'form') {
+            domain = new instance.web.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
+        }
 
         Share.create({
             name: action.name,
-            domain: view.dataset.domain,
+            domain: domain,
             action_id: action.id,
         }, function(result) {
             var share_id = result.result;
-            console.log('share_id', share_id);
-
             var step1 = Share.call('go_step_1', [[share_id],], function(result) {
                 var action = result;
-                console.log('step1', action);
                 self.do_action(action);
             });
         });
+}
+
+var _has_share = null;
+function if_has_share(yes, no) {
+    if (!_has_share) {
+        _has_share = $.Deferred(function() {
+            var self = this;
+            var session = instance.webclient.session;
+            session.on_session_invalid.add_last(function() { _has_share = null; });
+            var func = new instance.web.Model(session, "share.wizard").get_func("has_share");
+            func(session.uid).pipe(function(res) {
+                if(res) {
+                    self.resolve();
+                } else {
+                    self.reject();
+                }
+            });
+        });
+    }
+    _has_share.done(yes).fail(no);
+}
 
+
+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);
     },
 
 });
 
+
+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);
+    },
+});
+
 };