[IMP] shorter embed code
authorAntony Lesuisse <al@openerp.com>
Fri, 16 Dec 2011 15:37:36 +0000 (16:37 +0100)
committerAntony Lesuisse <al@openerp.com>
Fri, 16 Dec 2011 15:37:36 +0000 (16:37 +0100)
bzr revid: al@openerp.com-20111216153736-z10to08j5zcb1lw4

addons/web/static/src/js/chrome.js

index 412e74a..0e25e09 100644 (file)
@@ -1093,15 +1093,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
     },
 });
 
-openerp.currentScript = function() {
-    var currentScript = document.currentScript;
-    if (!currentScript) {
-        var sc = document.getElementsByTagName('script');
-        currentScript = sc[sc.length-1];
-    }
-    return currentScript;
-};
-
 openerp.web.EmbeddedClient = openerp.web.Widget.extend({
     template: 'EmptyComponent',
     init: function(action_id, options) {
@@ -1114,9 +1105,7 @@ openerp.web.EmbeddedClient = openerp.web.Widget.extend({
 
     start: function() {
         var self = this;
-
         this.am.appendTo(this.$element.addClass('openerp'));
-
         return this.rpc("/web/action/load", { action_id: this.action_id }, function(result) {
             var action = result.result;
             action.flags = _.extend({
@@ -1133,6 +1122,19 @@ openerp.web.EmbeddedClient = openerp.web.Widget.extend({
 
 });
 
+openerp.web.embed = function (origin, dbname, login, key, action, options) {
+    var currentScript = document.currentScript;
+    if (!currentScript) {
+        var sc = document.getElementsByTagName('script');
+        currentScript = sc[sc.length-1];
+    }
+    openerp.connection.bind(origin).then(function () {
+        openerp.connection.session_authenticate(dbname, login, key).then(function () {
+            var client = new session.web.EmbeddedClient(action_id, options);
+            client.insertAfter(currentScript);
+        });
+    });
+}
 
 };