[IMP] update VisualSearch to most recent master for various fixes & improvements

exported revision is master 3fca87101db55b6f8bb2f845ed90416e3da3ff4a

bzr revid: xmo@openerp.com-20120316111608-tvmce2rh64tpa2wm
This commit is contained in:
Xavier Morel 2012-03-16 12:16:08 +01:00
parent c2511f4241
commit 5dfdd64955
7 changed files with 102 additions and 21 deletions

View File

@ -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",

View File

@ -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;

View File

@ -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;

View File

@ -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('<div class="VS-search">\n <div class="VS-search-box-wrapper VS-search-box">\n <div class="VS-icon VS-icon-search"></div>\n <div class="VS-search-inner"></div>\n <div class="VS-icon VS-icon-cancel VS-cancel-search-box" title="clear search"></div>\n </div>\n</div>');
window.JST['search_facet'] = _.template('<% if (model.has(\'category\')) { %>\n <div class="category"><%= model.get(\'category\') %>:</div>\n<% } %>\n\n<div class="search_facet_input_container">\n <input type="text" class="search_facet_input VS-interface" value="" />\n</div>\n\n<div class="search_facet_remove VS-icon VS-icon-cancel"></div>');
window.JST['search_input'] = _.template('<input type="text" />');
})();
})();

View File

@ -11,7 +11,6 @@
background: #FEF3CA;
color: #022;
height: 100%;
overflow: hidden;
font-family: "Palatino Linotype", "Book Antiqua", Palatino, FreeSerif, serif;
}
div.container {

View File

@ -326,11 +326,11 @@
<th colspan="2">1. VisualSearch JavaScript (<tt>visualsearch.js</tt>)</th>
</tr>
<tr>
<td><a href="build-min/visualsearch.js">Production Version (0.2.1)</a></td>
<td><a href="build-min/visualsearch.js">Production Version (0.2.2)</a></td>
<td><i>8kb, Minified and Gzipped</i></td>
</tr>
<tr>
<td><a href="build/visualsearch.js">Development Version (0.2.1)</a></td>
<td><a href="build/visualsearch.js">Development Version (0.2.2)</a></td>
<td><i>45kb, Uncompressed with Comments</i></td>
</tr>
@ -486,6 +486,10 @@ visualSearch.searchQuery.facets()
// [FacetModel&lt;country:"South Africa">,
// FacetModel&lt;account:5-samuel>,
// FacetModel&lt;title:"Pentagon Papers">]
// Set the search query with raw text
visualSearch.searchBox.value("Country: US State: \"New York\" Key: Value")
</code></pre>
</li>
</ol>
@ -493,6 +497,12 @@ visualSearch.searchQuery.facets()
<h2 id="changelog">Change Log</h2>
<p>
<b class="header">0.2.2</b> <i>March 10th, 2012</i><br />
If you do not want to automatically filter the value matches, you can pass an
options hash with <tt>preserveMatches: true</tt> as the second argument to the callback.
<a href="https://github.com/documentcloud/visualsearch/pull/44">See pull request #44</a> for details.
</p>
<p>
<b class="header">0.2.1</b> <i>November 14th, 2011</i><br />
The autocompleted facets and values that are provided by your callbacks <tt>facetMatches</tt>

View File

@ -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",
/**