forked from OpenNeo/impress
when advanced query is empty, go blank instead of saying no results
This commit is contained in:
parent
d7af6cfd4a
commit
d47ec7a0cd
3 changed files with 32 additions and 23 deletions
|
@ -1166,7 +1166,7 @@ View.Search = function (wardrobe) {
|
||||||
var fit = $('#preview').data('fit') || $.noop;
|
var fit = $('#preview').data('fit') || $.noop;
|
||||||
stopLoading();
|
stopLoading();
|
||||||
item_set.setItems(items);
|
item_set.setItems(items);
|
||||||
if(wardrobe.search.request.query) {
|
if(wardrobe.search.request.query.length > 0) {
|
||||||
if(!items.length) {
|
if(!items.length) {
|
||||||
no_results_el.show();
|
no_results_el.show();
|
||||||
}
|
}
|
||||||
|
@ -1186,7 +1186,7 @@ View.Search = function (wardrobe) {
|
||||||
var human_query = typeof current_query === 'string' ? current_query : '';
|
var human_query = typeof current_query === 'string' ? current_query : '';
|
||||||
input_el.val(human_query);
|
input_el.val(human_query);
|
||||||
no_results_span.text(human_query);
|
no_results_span.text(human_query);
|
||||||
clear_el.toggle(!!request.query);
|
clear_el.toggle(!!request.query && request.query.length > 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
wardrobe.search.bind('updatePagination', function (current_page, total_pages) {
|
wardrobe.search.bind('updatePagination', function (current_page, total_pages) {
|
||||||
|
|
|
@ -216,23 +216,11 @@ function Wardrobe() {
|
||||||
|
|
||||||
Item.PER_PAGE = 21;
|
Item.PER_PAGE = 21;
|
||||||
|
|
||||||
function queryToFilters(query) {
|
|
||||||
if (typeof query === "string") return query;
|
|
||||||
var filters = [];
|
|
||||||
if (query.name.require)
|
|
||||||
filters.push({key: "name", value: query.name.require, is_positive: true});
|
|
||||||
if (query.name.exclude)
|
|
||||||
filters.push({key: "name", value: query.name.exclude, is_positive: false});
|
|
||||||
if (query.nc)
|
|
||||||
filters.push({key: "is_nc", is_positive: (query.nc === "nc")});
|
|
||||||
return filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
Item.loadByQuery = function (query, offset, success, error) {
|
Item.loadByQuery = function (query, offset, success, error) {
|
||||||
var page = Math.round(offset / Item.PER_PAGE) + 1;
|
var page = Math.round(offset / Item.PER_PAGE) + 1;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/items.json',
|
url: '/items.json',
|
||||||
data: {q: queryToFilters(query), per_page: Item.PER_PAGE, page: page},
|
data: {q: query, per_page: Item.PER_PAGE, page: page},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
var items = [], item, item_data;
|
var items = [], item, item_data;
|
||||||
|
@ -1342,6 +1330,24 @@ function Wardrobe() {
|
||||||
search.events.trigger('error', error);
|
search.events.trigger('error', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function queryToFilters(query) {
|
||||||
|
if (typeof query === "string") return query;
|
||||||
|
var filters = [];
|
||||||
|
if (query.name.require)
|
||||||
|
filters.push({key: "name", value: query.name.require, is_positive: true});
|
||||||
|
if (query.name.exclude)
|
||||||
|
filters.push({key: "name", value: query.name.exclude, is_positive: false});
|
||||||
|
if (query.nc)
|
||||||
|
filters.push({key: "is_nc", is_positive: (query.nc === "nc")});
|
||||||
|
if (query.occupies)
|
||||||
|
filters.push({key: "occupied_zone_set_name", value: query.occupies,
|
||||||
|
is_positive: true});
|
||||||
|
if (query.restricts)
|
||||||
|
filters.push({key: "restricted_zone_set_name", value: query.restricts,
|
||||||
|
is_positive: true});
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
this.setItemsByQuery = function (query, where) {
|
this.setItemsByQuery = function (query, where) {
|
||||||
var offset = (typeof where.offset != 'undefined') ? where.offset : (Item.PER_PAGE * (where.page - 1));
|
var offset = (typeof where.offset != 'undefined') ? where.offset : (Item.PER_PAGE * (where.page - 1));
|
||||||
search.request = {
|
search.request = {
|
||||||
|
@ -1349,12 +1355,15 @@ function Wardrobe() {
|
||||||
offset: offset
|
offset: offset
|
||||||
};
|
};
|
||||||
search.events.trigger('updateRequest', search.request);
|
search.events.trigger('updateRequest', search.request);
|
||||||
if(query) {
|
if (typeof query !== "undefined") {
|
||||||
Item.loadByQuery(query, offset, itemsOnLoad, itemsOnError);
|
var newQuery = queryToFilters(query);
|
||||||
search.events.trigger('startRequest');
|
if(newQuery.length > 0) { // works for strings *or* filters lists!
|
||||||
} else {
|
Item.loadByQuery(newQuery, offset, itemsOnLoad, itemsOnError);
|
||||||
search.events.trigger('updateItems', []);
|
search.events.trigger('startRequest');
|
||||||
search.events.trigger('updatePagination', 0, 0);
|
} else {
|
||||||
|
search.events.trigger('updateItems', []);
|
||||||
|
search.events.trigger('updatePagination', 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,8 +166,8 @@ class Item
|
||||||
species: lambda { |id|
|
species: lambda { |id|
|
||||||
Species.find(id).name
|
Species.find(id).name
|
||||||
},
|
},
|
||||||
zone: lambda { |id|
|
zone: lambda { |ids|
|
||||||
Zone.find(id).plain_label
|
Zone.find(ids.first).plain_label
|
||||||
},
|
},
|
||||||
ownership: lambda { |owned|
|
ownership: lambda { |owned|
|
||||||
owned_key = owned ? 'owns' : 'wants'
|
owned_key = owned ? 'owns' : 'wants'
|
||||||
|
|
Loading…
Reference in a new issue