From f009c765984eb8b409dc42f7bb601acf14e6b577 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 2 May 2012 15:43:12 +0200 Subject: [PATCH] [ADD] focus last input if the user clicks somewhere in the search view, outside of a search view control bzr revid: xmo@openerp.com-20120502134312-0tuspwcmtlw5el3o --- addons/web/static/src/css/base.css | 7 +++++++ addons/web/static/src/css/base.sass | 5 +++++ addons/web/static/src/js/search.js | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 20b4cb92ff4..6788c532d9d 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1046,6 +1046,7 @@ white-space: nowrap; } .openerp .oe_searchview { + cursor: text; position: relative; float: right; padding-right: 20px; @@ -1059,6 +1060,12 @@ -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) inset; -box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) inset; } +.openerp .oe_searchview.oe_focused { + border-color: #a6a6fe; + -moz-box-shadow: 0 1px 2px #a6a6fe inset; + -webkit-box-shadow: 0 1px 2px #a6a6fe inset; + -box-shadow: 0 1px 2px #a6a6fe inset; +} .openerp .oe_searchview .oe_searchview_clear { cursor: pointer; position: absolute; diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index eabcae107b7..0f420b1aea3 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -819,6 +819,7 @@ $colour4: #8a89ba // }}} // SearchView xmo {{{ .oe_searchview + cursor: text position: relative float: right padding-right: 20px @@ -828,6 +829,10 @@ $colour4: #8a89ba @include radius(1em) @include box-shadow(0 1px 2px rgba(0,0,0,0.2) inset) + &.oe_focused + border-color: $facets-border-selected + @include box-shadow(0 1px 2px $facets-border-selected inset) + .oe_searchview_clear cursor: pointer position: absolute diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 21cb4a71196..72b05df1317 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -155,6 +155,7 @@ my.FacetView = instance.web.Widget.extend({ if ($(e.target).is('.oe_facet_remove')) { return; } + e.stopPropagation(); self.$element.siblings().trigger('deselect'); self.$element.addClass('oe_selected'); }); @@ -259,7 +260,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea }); } - this.$element.on('click', '.oe_searchview_unfold_drawer', function () { + this.$element.on('click', '.oe_searchview_unfold_drawer', function (e) { + e.stopImmediatePropagation(); self.$element.toggleClass('oe_searchview_open_drawer'); }); this.$element.on('click', '.oe_facet_remove', function (e) { @@ -271,6 +273,19 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea self.query.remove( self.query.at(index), {trigger_search: true}); }); + this.$element.on('click', function (e) { + // Focus last input if the view itself is clicked (but not one of + // its children, that would be weird) + if (e.target === self.$element[0]) { + self.$element.find('.oe_searchview_input:last').focus(); + } + }); + this.$element.on('focus', function () { + self.$element.addClass('oe_focused'); + }); + this.$element.on('blur', function () { + self.$element.removeClass('oe_focused'); + }); return $.when(p, this.ready); },