[FIX] url handling of record id
authorChristophe Simonis <chs@openerp.com>
Thu, 15 Dec 2011 14:29:39 +0000 (15:29 +0100)
committerChristophe Simonis <chs@openerp.com>
Thu, 15 Dec 2011 14:29:39 +0000 (15:29 +0100)
bzr revid: chs@openerp.com-20111215142939-j2lz1irzoj10fy3v

addons/web/static/src/js/view_form.js
addons/web/static/src/js/views.js

index 607bf7b..2e00e34 100644 (file)
@@ -117,6 +117,18 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
         }
         this.has_been_loaded.resolve();
     },
+
+    do_load_state: function(state) {
+        if (state.id && this.datarecord.id != state.id) {
+            var idx = this.dataset.get_id_index(state.id);
+            if (idx === null) {
+                this.dataset.ids.push(state.id)
+                this.dataset.index = this.dataset.ids.length - 1;
+            }
+            this.do_show();
+        }
+    },
+
     do_show: function () {
         var promise;
         if (this.dataset.index === null) {
index 36edec7..76082f3 100644 (file)
@@ -56,31 +56,38 @@ session.web.ActionManager = session.web.Widget.extend({
         }
     },
     do_load_state: function(state) {
+        var self = this,
+            action_loaded;
         if (state.action_id) {
-            this.null_action();
-            this.do_action(state.action_id);
+            var run_action = (!this.inner_viewmanager) || this.inner_viewmanager.action.id !== state.action_id;
+            if (run_action) {
+                this.null_action();
+                action_loaded = this.do_action(state.action_id);
+            }
         }
         else if (state.model && state.id) {
             // TODO implement it
             //this.null_action();
-            // action = {}
+            //action = {res_model: state.model, res_id: state.id};
+            //action_loaded = this.do_action(action);
         }
         else if (state.client_action) {
             this.null_action();
             this.ir_actions_client(state.client_action);
         }
 
-        if (this.inner_viewmanager) {
-            this.inner_viewmanager.do_load_state(state);
-        }
+        $.when(action_loaded || null).then(function() {
+            if (self.inner_viewmanager) {
+                self.inner_viewmanager.do_load_state(state);
+            }
+        });
     },
     do_action: function(action, on_close) {
         if (_.isNumber(action)) {
             var self = this;
-            self.rpc("/web/action/load", { action_id: action }, function(result) {
+            return self.rpc("/web/action/load", { action_id: action }, function(result) {
                 self.do_action(result.result, on_close);
             });
-            return;
         }
         if (!action.type) {
             console.error("No type for action", action);
@@ -583,8 +590,13 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
         }
     },
     do_load_state: function(state) {
-        var self = this;
-        $.when(this.on_mode_switch(state.view_type, true)).done(function() {
+        var self = this,
+            defs = [];
+        if (state.view_type && state.view_type !== this.active_view) {
+            defs.push(this.on_mode_switch(state.view_type, true));
+        } 
+
+        $.when(defs).then(function() {
             self.views[self.active_view].controller.do_load_state(state);
         });
     },