[FIX] disable sorting (column-click) in an editable listview being edited
authorXavier Morel <xmo@openerp.com>
Tue, 27 Nov 2012 09:41:09 +0000 (10:41 +0100)
committerXavier Morel <xmo@openerp.com>
Tue, 27 Nov 2012 09:41:09 +0000 (10:41 +0100)
To do so, extract sort handling to its own method (bound using the
events hash) and override-and-disable in editable.

bzr revid: xmo@openerp.com-20121127094109-mojnq50mzsrcj3q0

addons/web/static/src/js/view_list.js
addons/web/static/src/js/view_list_editable.js

index 55e3c17..13c41d4 100644 (file)
@@ -25,6 +25,9 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
         'disable_editable_mode': false,
     },
     view_type: 'tree',
+    events: {
+        'click thead th.oe_sortable[data-id]': 'sort_by_column'
+    },
     /**
      * Core class for list-type displays.
      *
@@ -264,21 +267,6 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
                 'selected', [selection.ids, selection.records]);
         });
 
-        // Sorting columns
-        this.$el.find('thead').delegate('th.oe_sortable[data-id]', 'click', function (e) {
-            e.stopPropagation();
-            var $this = $(this);
-            self.dataset.sort($this.data('id'));
-            if($this.hasClass("sortdown") || $this.hasClass("sortup"))  {
-                $this.toggleClass("sortdown").toggleClass("sortup");
-            } else {
-                $this.toggleClass("sortdown");
-            }
-            $this.siblings('.oe_sortable').removeClass("sortup sortdown");
-
-            self.reload_content();
-        });
-
         // Add button
         if (!this.$buttons) {
             this.$buttons = $(QWeb.render("ListView.buttons", {'widget':self}));
@@ -360,6 +348,19 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
         }
         this.trigger('list_view_loaded', data, this.grouped);
     },
+    sort_by_column: function (e) {
+        e.stopPropagation();
+        var $column = $(e.currentTarget);
+        this.dataset.sort($column.data('id'));
+        if($column.hasClass("sortdown") || $column.hasClass("sortup"))  {
+            $column.toggleClass("sortup sortdown");
+        } else {
+            $column.addClass("sortdown");
+        }
+        $column.siblings('.oe_sortable').removeClass("sortup sortdown");
+
+        this.reload_content();
+    },
     /**
      * Configures the ListView pager based on the provided dataset's information
      *
index db7e22e..7fe6a8e 100644 (file)
@@ -63,6 +63,12 @@ openerp.web.list_editable = function (instance) {
             }
             this._super();
         },
+        sort_by_column: function (e) {
+            e.stopPropagation();
+            if (!this.editor.is_editing()) {
+                this._super.apply(this, arguments);
+            }
+        },
         /**
          * Handles the activation of a record in editable mode (making a record
          * editable), called *after* the record has become editable.