Victor Tabuenca (OpenERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-searchview_fix-vta into lp:openerp-web.

Requested reviews:
  Xavier (Open ERP) (xmo)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-searchview_fix-vta/+merge/130546

Fixed strange behavior when clicking the 'Apply' button in the advanced search 
(the browser crashed).
Also fixed when clicking to 'remove' a condition (the whole drawer got closed).
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-searchview_fix-vta/+merge/130546
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-searchview_fix-vta.
=== modified file 'addons/web/static/src/js/search.js'
--- addons/web/static/src/js/search.js	2012-10-19 11:15:58 +0000
+++ addons/web/static/src/js/search.js	2012-10-19 13:41:21 +0000
@@ -1671,28 +1671,28 @@
         var self = this;
         // Get domain sections from all propositions
         var children = this.getChildren();
-        var propositions = _.invoke(children, 'get_proposition');
-        var domain = _(propositions).pluck('value');
-        for (var i = domain.length; --i;) {
-            domain.unshift('|');
-        }
-
-        this.view.query.add({
-            category: _t("Advanced"),
-            values: propositions,
-            field: {
-                get_context: function () { },
-                get_domain: function () { return domain;},
-                get_groupby: function () { }
+        if (children.length > 0) {
+            var propositions = _.invoke(children, 'get_proposition');
+            var domain = _(propositions).pluck('value');
+            for (var i = domain.length; --i;) {
+                domain.unshift('|');
             }
-        });
-
-        // remove all propositions
-        _.invoke(children, 'destroy');
-        // add new empty proposition
-        this.append_proposition();
-        // TODO: API on searchview
-        this.view.$el.removeClass('oe_searchview_open_drawer');
+            this.view.query.add({
+                category: _t("Advanced"),
+                values: propositions,
+                field: {
+                    get_context: function () { },
+                    get_domain: function () { return domain;},
+                    get_groupby: function () { }
+                }
+            });
+            // remove all propositions
+            _.invoke(children, 'destroy');
+            // add new empty proposition
+            this.append_proposition();
+            // TODO: API on searchview
+            this.view.$el.removeClass('oe_searchview_open_drawer');
+        }        
     }
 });
 
@@ -1719,8 +1719,12 @@
         this.$el.find(".searchview_extended_prop_field").change(function() {
             _this.changed();
         });
-        this.$el.find('.searchview_extended_delete_prop').click(function () {
-            _this.destroy();
+        this.$el.find('.searchview_extended_delete_prop').click(function (e) {
+            // prevent browser crashing            
+            if (_this.$el.parent().children().length > 1) {
+                e.stopPropagation();
+                _this.destroy();
+            }
         });
         this.changed();
     },

=== modified file 'addons/web/static/test/search.js'
--- addons/web/static/test/search.js	2012-10-19 11:15:58 +0000
+++ addons/web/static/test/search.js	2012-10-19 13:41:21 +0000
@@ -1215,5 +1215,46 @@
                           "advanced search facet should return proposed domain");
             });
     });
+    asyncTest('remove-advanced', 5, function () {
+        var view = makeSearchView();
+        var $fix = $('#qunit-fixture');
+
+        view.appendTo($fix)
+            .always(start)
+            .fail(function (error) { ok(false, error.message); })
+            .done(function () {
+                var $advanced = $fix.find('.oe_searchview_advanced');
+                // open advanced search (not actually useful)
+                $advanced.find('> h4').click();
+                // a condition added when search created
+                equal($advanced.find('> form li').length, 1, "A condition is added when the search is created.");
+
+                // select first condition
+                var $prop1 = $advanced.find('> form li:first');
+                // try to remove condition
+                $prop1.find('.searchview_extended_delete_prop').click();
+                // the first condition never gets deleted
+                equal($advanced.find('> form li').length, 1, "The first condition never gets deleted, now the 'Apply' button can be safely clicked");
+
+                // add a three more conditions
+                $advanced.find('button.oe_add_condition').click();
+                $advanced.find('button.oe_add_condition').click();
+                $advanced.find('button.oe_add_condition').click();
+                equal($advanced.find('> form li').length, 4, "Added three more conditions, now there are four.");
+
+                // delete conditions
+                var $prop2 = $advanced.find('> form li:last');
+                $prop2.find('.searchview_extended_delete_prop').click();
+                var $prop2 = $advanced.find('> form li:last');
+                $prop2.find('.searchview_extended_delete_prop').click();
+                var $prop2 = $advanced.find('> form li:last');
+                $prop2.find('.searchview_extended_delete_prop').click();
+                var $prop2 = $advanced.find('> form li:last');
+                equal($advanced.find('> form li').length, 1, "Deleted the three conditions, now there is one");
+                
+                $prop1.find('.searchview_extended_delete_prop').click();
+                equal($advanced.find('> form li').length, 1, "The first condition never gets deleted, remember?");
+        });
+    });
     // TODO: UI tests?
 });

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to