[ADD] EmbedClient widget for ease the use of embed code
authorChristophe Simonis <chs@openerp.com>
Tue, 22 Nov 2011 12:22:50 +0000 (13:22 +0100)
committerChristophe Simonis <chs@openerp.com>
Tue, 22 Nov 2011 12:22:50 +0000 (13:22 +0100)
bzr revid: chs@openerp.com-20111122122250-v0cys6fdv42222l0

addons/web/__openerp__.py
addons/web/static/src/js/boot.js
addons/web/static/src/js/embed.js [new file with mode: 0644]

index a9aeea1..43700b0 100644 (file)
@@ -46,7 +46,8 @@
         "static/src/js/view_list.js",
         "static/src/js/view_list_editable.js",
         "static/src/js/view_tree.js",
-        "static/src/js/view_editor.js"
+        "static/src/js/view_editor.js",
+        "static/src/js/embed.js",
     ],
     'css' : [
         "static/lib/jquery.superfish/css/superfish.css",
index 58dcd92..7440ae4 100644 (file)
@@ -59,7 +59,7 @@ openerp.web = function(instance) {
     openerp.web.formats(instance);
     openerp.web.chrome(instance);
     openerp.web.data(instance);
-    var files = ["views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import","view_editor"];
+    var files = ["views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import","view_editor", 'embed'];
     for(var i=0; i<files.length; i++) {
         if(openerp.web[files[i]]) {
             openerp.web[files[i]](instance);
diff --git a/addons/web/static/src/js/embed.js b/addons/web/static/src/js/embed.js
new file mode 100644 (file)
index 0000000..ce6ad8b
--- /dev/null
@@ -0,0 +1,49 @@
+openerp.web.embed = function(session) {
+
+    session.util = session.util || {}
+    session.util.currentScript = function() {
+        var currentScript = document.currentScript;
+        if (!currentScript) {
+            var sc = document.getElementsByTagName('script');
+            currentScript = sc[sc.length-1];
+        }
+        return currentScript;
+    };
+
+
+    /*
+    session.connection.on_session_invalid.add_last(function() {
+        console.error("invalid session", arguments);
+    });
+    // */
+
+    
+    session.web.EmbedClient = session.web.Widget.extend({
+        template: 'EmptyComponent',
+        init: function(action_id) {
+            this._super();
+            this.action_id = action_id;
+            this.am = new session.web.ActionManager();
+        },
+
+        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({
+                    //views_switcher : false,
+                    search_view : false,
+                    action_buttons : false,
+                    sidebar : false
+                    //pager : false
+                }, action.flags || {});
+
+                self.am.do_action(action);
+            });
+        },
+
+    });
+};