From 5dfdd6495569af2b533af6bfe754943562c003a3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 16 Mar 2012 12:16:08 +0100 Subject: [PATCH] [IMP] update VisualSearch to most recent master for various fixes & improvements exported revision is master 3fca87101db55b6f8bb2f845ed90416e3da3ff4a bzr revid: xmo@openerp.com-20120316111608-tvmce2rh64tpa2wm --- addons/web/__openerp__.py | 19 +++++- .../build/visualsearch-datauri.css | 13 +++++ .../lib/visualsearch/build/visualsearch.css | 13 +++++ .../lib/visualsearch/build/visualsearch.js | 58 ++++++++++++++----- addons/web/static/lib/visualsearch/demo.html | 1 - addons/web/static/lib/visualsearch/index.html | 14 ++++- addons/web/static/src/js/search.js | 5 ++ 7 files changed, 102 insertions(+), 21 deletions(-) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index c6d5e8f85f1..b6a3a7c9a6c 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -36,7 +36,20 @@ "static/lib/underscore/underscore.js", "static/lib/underscore/underscore.string.js", "static/lib/backbone/backbone.js", - "static/lib/visualsearch/build/visualsearch.js", + + "static/lib/visualsearch/lib/js/visualsearch.js", + "static/lib/visualsearch/lib/js/utils/backbone_extensions.js", + "static/lib/visualsearch/lib/js/utils/hotkeys.js", + "static/lib/visualsearch/lib/js/utils/inflector.js", + "static/lib/visualsearch/lib/js/utils/jquery_extensions.js", + "static/lib/visualsearch/lib/js/utils/search_parser.js", + "static/lib/visualsearch/lib/js/models/search_facets.js", + "static/lib/visualsearch/lib/js/models/search_query.js", + "static/lib/visualsearch/lib/js/templates/templates.js", + "static/lib/visualsearch/lib/js/views/search_facet.js", + "static/lib/visualsearch/lib/js/views/search_input.js", + "static/lib/visualsearch/lib/js/views/search_box.js", + "static/lib/labjs/LAB.src.js", "static/lib/py.js/lib/py.js", "static/lib/novajs/src/nova.js", @@ -63,7 +76,9 @@ "static/lib/jquery.ui.timepicker/css/jquery-ui-timepicker-addon.css", "static/lib/jquery.ui.notify/css/ui.notify.css", "static/lib/jquery.tipsy/tipsy.css", - "static/lib/visualsearch/build/visualsearch-datauri.css", + "static/lib/visualsearch/lib/css/reset.css", + "static/lib/visualsearch/lib/css/workspace.css", + "static/lib/visualsearch/lib/css/icons.css", "static/src/css/base_old.css", "static/src/css/base.css", "static/src/css/data_export.css", diff --git a/addons/web/static/lib/visualsearch/build/visualsearch-datauri.css b/addons/web/static/lib/visualsearch/build/visualsearch-datauri.css index 1ae6ed28215..3e3edd0063f 100755 --- a/addons/web/static/lib/visualsearch/build/visualsearch-datauri.css +++ b/addons/web/static/lib/visualsearch/build/visualsearch-datauri.css @@ -244,6 +244,8 @@ Source: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ background-color: #F6F6F6; cursor: pointer; z-index: 10000; + padding: 0; + margin: 0; width: auto; min-width: 80px; max-width: 220px; @@ -267,11 +269,16 @@ Source: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ color: white; cursor: default; } + .VS-interface.ui-autocomplete .ui-menu-item { + float: none; + } .VS-interface.ui-autocomplete .ui-menu-item a { color: #000; outline: none; display: block; padding: 3px 4px 5px; + border-radius: none; + line-height: 1; background-color: #F8F8F8; background-image: -moz-linear-gradient(top, #F8F8F8, #F3F3F3); /* FF3.6 */ background-image: -webkit-gradient(linear, left top, left bottom, from(#F8F8F8), to(#F3F3F3)); /* Saf4+, Chrome */ @@ -289,7 +296,13 @@ Source: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ background-image: linear-gradient(top, #648bF5, #2465f3); border-top: 1px solid #5b83ec; border-bottom: 1px solid #1459e9; + border-left: none; + border-right: none; color: white; + margin: 0; + } + .VS-interface.ui-autocomplete .ui-corner-all { + border-radius: 0; } .VS-interface.ui-autocomplete li { list-style: none; diff --git a/addons/web/static/lib/visualsearch/build/visualsearch.css b/addons/web/static/lib/visualsearch/build/visualsearch.css index f4f404388c3..079ff122300 100755 --- a/addons/web/static/lib/visualsearch/build/visualsearch.css +++ b/addons/web/static/lib/visualsearch/build/visualsearch.css @@ -244,6 +244,8 @@ Source: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ background-color: #F6F6F6; cursor: pointer; z-index: 10000; + padding: 0; + margin: 0; width: auto; min-width: 80px; max-width: 220px; @@ -267,11 +269,16 @@ Source: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ color: white; cursor: default; } + .VS-interface.ui-autocomplete .ui-menu-item { + float: none; + } .VS-interface.ui-autocomplete .ui-menu-item a { color: #000; outline: none; display: block; padding: 3px 4px 5px; + border-radius: none; + line-height: 1; background-color: #F8F8F8; background-image: -moz-linear-gradient(top, #F8F8F8, #F3F3F3); /* FF3.6 */ background-image: -webkit-gradient(linear, left top, left bottom, from(#F8F8F8), to(#F3F3F3)); /* Saf4+, Chrome */ @@ -289,7 +296,13 @@ Source: http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/ background-image: linear-gradient(top, #648bF5, #2465f3); border-top: 1px solid #5b83ec; border-bottom: 1px solid #1459e9; + border-left: none; + border-right: none; color: white; + margin: 0; + } + .VS-interface.ui-autocomplete .ui-corner-all { + border-radius: 0; } .VS-interface.ui-autocomplete li { list-style: none; diff --git a/addons/web/static/lib/visualsearch/build/visualsearch.js b/addons/web/static/lib/visualsearch/build/visualsearch.js index a60b107efa9..319d978db3c 100755 --- a/addons/web/static/lib/visualsearch/build/visualsearch.js +++ b/addons/web/static/lib/visualsearch/build/visualsearch.js @@ -5,14 +5,13 @@ // The annotated source HTML is generated by // [Docco](http://jashkenas.github.com/docco/). -/** @license VisualSearch.js 0.2.1 +/** @license VisualSearch.js 0.2.2 * (c) 2011 Samuel Clay, @samuelclay, DocumentCloud Inc. * VisualSearch.js may be freely distributed under the MIT license. * For all details and documentation: * http://documentcloud.github.com/visualsearch */ -var VS = {}; (function() { var $ = jQuery; // Handle namespaced jQuery @@ -25,7 +24,7 @@ var VS = {}; if (!VS.utils) VS.utils = {}; // Sets the version for VisualSearch to be used programatically elsewhere. - VS.VERSION = '0.2.1'; + VS.VERSION = '0.2.2'; VS.VisualSearch = function(options) { var defaults = { @@ -96,8 +95,12 @@ VS.ui.SearchBox = Backbone.View.extend({ this.facetViews = []; this.inputViews = []; _.bindAll(this, 'renderFacets', '_maybeDisableFacets', 'disableFacets', - 'deselectAllFacets'); - this.app.searchQuery.bind('reset', this.renderFacets); + 'deselectAllFacets', 'addedFacet', 'removedFacet', 'changedFacet'); + this.app.searchQuery + .bind('reset', this.renderFacets) + .bind('add', this.addedFacet) + .bind('remove', this.removedFacet) + .bind('change', this.changedFacet); $(document).bind('keydown', this._maybeDisableFacets); }, @@ -167,13 +170,17 @@ VS.ui.SearchBox = Backbone.View.extend({ category = VS.utils.inflector.trim(category); initialQuery = VS.utils.inflector.trim(initialQuery || ''); if (!category) return; - + var model = new VS.model.SearchFacet({ category : category, value : initialQuery || '', app : this.app }); this.app.searchQuery.add(model, {at: position}); + }, + + // Renders a newly added facet, and selects it. + addedFacet : function (model) { this.renderFacets(); var facetView = _.detect(this.facetViews, function(view) { if (view.model == model) return true; @@ -184,6 +191,17 @@ VS.ui.SearchBox = Backbone.View.extend({ }); }, + // Changing a facet programmatically re-renders it. + changedFacet: function () { + this.renderFacets(); + }, + + // When removing a facet, potentially do something. For now, the adjacent + // remaining facet is selected, but this is handled by the facet's view, + // since its position is unknown by the time the collection triggers this + // remove callback. + removedFacet : function (facet, query, options) {}, + // Renders each facet as a searchFacet view. renderFacets : function() { this.facetViews = []; @@ -470,6 +488,7 @@ VS.ui.SearchBox = Backbone.View.extend({ }); })(); + (function() { var $ = jQuery; // Handle namespaced jQuery @@ -624,13 +643,17 @@ VS.ui.SearchFacet = Backbone.View.extend({ matches = matches || []; if (searchTerm && value != searchTerm) { - var re = VS.utils.inflector.escapeRegExp(searchTerm || ''); - var matcher = new RegExp('\\b' + re, 'i'); - matches = $.grep(matches, function(item) { - return matcher.test(item) || - matcher.test(item.value) || - matcher.test(item.label); + if (options.preserveMatches) { + return matches; + } else { + var re = VS.utils.inflector.escapeRegExp(searchTerm || ''); + var matcher = new RegExp('\\b' + re, 'i'); + matches = $.grep(matches, function(item) { + return matcher.test(item) || + matcher.test(item.value) || + matcher.test(item.label); }); + } } if (options.preserveOrder) { @@ -1603,13 +1626,15 @@ if ($.browser.msie && false) { var $ = jQuery; // Handle namespaced jQuery // Used to extract keywords and facets from the free text search. +var FREETEXT_RE = '(\'[^\']+\'|"[^"]+"|[^\'"\\s]\\S*)'; +var CATEGORY_RE = FREETEXT_RE + ':\\s*'; VS.app.SearchParser = { // Matches `category: "free text"`, with and without quotes. - ALL_FIELDS : /('.+?'|".+?"|[^'"\s]{2}\S*):\s*('.+?'|".+?"|[^'"\s]\S*)/g, + ALL_FIELDS : new RegExp(CATEGORY_RE + FREETEXT_RE, 'g'), // Matches a single category without the text. Used to correctly extract facets. - CATEGORY : /('.+?'|".+?"|[^'"\s]{2}\S*):\s*/, + CATEGORY : new RegExp(CATEGORY_RE), // Called to parse a query into a collection of `SearchFacet` models. parse : function(instance, query) { @@ -1658,7 +1683,7 @@ VS.app.SearchParser = { // Extracts the first field found, capturing any free text that comes // before the category. _extractNextField : function(query) { - var textRe = /^\s*(\S+)\s+(?=\w+:\s?(('.+?'|".+?")|([^'"]{2}\S*)))/; + var textRe = new RegExp('^\\s*(\\S+)\\s+(?=' + CATEGORY_RE + FREETEXT_RE + ')'); var textMatch = query.match(textRe); if (textMatch && textMatch.length >= 1) { return textMatch[1]; @@ -1683,6 +1708,7 @@ VS.app.SearchParser = { }; })(); + (function() { var $ = jQuery; // Handle namespaced jQuery @@ -1816,4 +1842,4 @@ window.JST = window.JST || {}; window.JST['search_box'] = _.template(''); window.JST['search_facet'] = _.template('<% if (model.has(\'category\')) { %>\n
<%= model.get(\'category\') %>:
\n<% } %>\n\n
\n \n
\n\n
'); window.JST['search_input'] = _.template(''); -})(); +})(); \ No newline at end of file diff --git a/addons/web/static/lib/visualsearch/demo.html b/addons/web/static/lib/visualsearch/demo.html index 25c930e213b..212fb7cee28 100755 --- a/addons/web/static/lib/visualsearch/demo.html +++ b/addons/web/static/lib/visualsearch/demo.html @@ -11,7 +11,6 @@ background: #FEF3CA; color: #022; height: 100%; - overflow: hidden; font-family: "Palatino Linotype", "Book Antiqua", Palatino, FreeSerif, serif; } div.container { diff --git a/addons/web/static/lib/visualsearch/index.html b/addons/web/static/lib/visualsearch/index.html index e8ec3108955..07cc8de20e8 100755 --- a/addons/web/static/lib/visualsearch/index.html +++ b/addons/web/static/lib/visualsearch/index.html @@ -326,11 +326,11 @@ 1. VisualSearch JavaScript (visualsearch.js) - Production Version (0.2.1) + Production Version (0.2.2) 8kb, Minified and Gzipped - Development Version (0.2.1) + Development Version (0.2.2) 45kb, Uncompressed with Comments @@ -486,6 +486,10 @@ visualSearch.searchQuery.facets() // [FacetModel<country:"South Africa">, // FacetModel<account:5-samuel>, // FacetModel<title:"Pentagon Papers">] + +// Set the search query with raw text +visualSearch.searchBox.value("Country: US State: \"New York\" Key: Value") + @@ -493,6 +497,12 @@ visualSearch.searchQuery.facets()

Change Log

+

+ 0.2.2 March 10th, 2012
+ If you do not want to automatically filter the value matches, you can pass an + options hash with preserveMatches: true as the second argument to the callback. + See pull request #44 for details. +

0.2.1 November 14th, 2011
The autocompleted facets and values that are provided by your callbacks facetMatches diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 179e80091c8..56d12cbcce7 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -3,6 +3,11 @@ var QWeb = openerp.web.qweb, _t = openerp.web._t, _lt = openerp.web._lt; +// Replace VS.ui.SearchFacet by a factory function returning potentially +// customized backbone views for custom facets +var SearchFacet = VS.ui.SearchFacet; +VS.ui.SearchFacet = function (options) { return new SearchFacet(options); }; + openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.SearchView# */{ template: "EmptyComponent", /**