diff options
Diffstat (limited to 'web/viewsjs')
-rw-r--r-- | web/viewsjs/search.js.erb | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/web/viewsjs/search.js.erb b/web/viewsjs/search.js.erb index 5ce7e72..9dcafa2 100644 --- a/web/viewsjs/search.js.erb +++ b/web/viewsjs/search.js.erb @@ -3,17 +3,22 @@ misc = @trans.t.misc search = @trans.t.pages.search %> -function link_to_key_with_highlight(key, highlight) { + +function highlight(str, query) { + return str.replace(new RegExp('(' + query + ')', 'gi'), "<b>$1</b>") +} + +function link_to_key_with_highlight(key, query) { return link( url_for_key(key), - key.replace(new RegExp('(' + highlight + ')', 'gi'), "<b>$1</b>") + highlight(key, query) ); } -function link_to_value_with_highlight(key, value, highlight) { +function link_to_value_with_highlight(key, value, query) { return link( url_for_tag(key, value), - value.replace(new RegExp('(' + highlight + ')', 'gi'), "<b>$1</b>") + highlight(value, query) ); } @@ -60,6 +65,28 @@ var create_flexigrid_for = { } }); }, + roles: function(query) { + create_flexigrid('grid-roles', { + url: '/api/4/search/by_role?query=' + encodeURIComponent(query), + colModel: [ + { display: '<%= misc.count %>', name: 'count_all', width: 80, sortable: true, align: 'right' }, + { display: '<%= osm.relation_types %>', name: 'rtype', width: 250, sortable: true }, + { display: '<%= osm.relation_member_roles %>', name: 'role', width: 500, sortable: true } + ], + sortname: 'count_all', + sortorder: 'desc', + preProcess: function(data) { + data.rows = jQuery.map(data.data, function(row, i) { + return { 'cell': [ + fmt_with_ts(row.count_all), + link_to_rtype(row.rtype), + highlight(html_escape(row.role), query) + ] }; + }); + return data; + } + }); + }, tags: function(query) { var q = query.split('=', 2); create_flexigrid('grid-tags', { |