1
0
Fork 0
forked from OpenNeo/impress

basic advanced search behavior; only name supported right now

This commit is contained in:
Emi Matchu 2014-04-02 20:05:18 -05:00
parent 3f4f0eb06e
commit 9cae578ef7
3 changed files with 46 additions and 9 deletions

View file

@ -1088,7 +1088,8 @@ View.Search = function (wardrobe) {
PER_PAGE: 21,
TEMPLATE: $('#pagination-template')
}, object_width = 112, last_request,
current_query = "";
current_query = "",
advanced_form = $('#preview-search-advanced');
PAGINATION.EL = $(PAGINATION.EL_ID);
@ -1135,6 +1136,24 @@ View.Search = function (wardrobe) {
loadPage(1);
});
advanced_form.submit(function(e) {
e.preventDefault();
current_query = {
name: {
require: $('#advanced-search-name-require').val(),
exclude: $('#advanced-search-name-exclude').val()
},
nc: $('#advanced-search-nc').val(),
occupies: $('#advanced-search-occupies').val(),
restricts: $('#advanced-search-restricts').val(),
species: $('#advanced-search-species').val(),
owns: $('#advanced-search-owns').val(),
wants: $('#advanced-search-wants').val()
};
wrapper.removeClass('advanced');
loadPage(1);
});
clear_el.click(function (e) {
e.preventDefault();
input_el.val('');
@ -1160,14 +1179,21 @@ View.Search = function (wardrobe) {
fit();
});
function updateQuery(query) {
current_query = query || '';
var human_query = typeof query === 'string' ? query : '';
input_el.val(human_query);
no_results_span.text(human_query);
}
wardrobe.search.bind('updateQuery', updateQuery);
wardrobe.search.bind('updateRequest', function (request) {
last_request = request;
error_el.hide('fast');
help_el.hide();
no_results_el.hide();
current_query = request.query || '';
input_el.val(current_query);
no_results_span.text(current_query);
updateQuery(request.query);
clear_el.toggle(!!request.query);
});

View file

@ -216,11 +216,21 @@ function Wardrobe() {
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});
return filters;
}
Item.loadByQuery = function (query, offset, success, error) {
var page = Math.round(offset / Item.PER_PAGE) + 1;
$.ajax({
url: '/items.json',
data: {q: query, per_page: Item.PER_PAGE, page: page},
data: {q: queryToFilters(query), per_page: Item.PER_PAGE, page: page},
dataType: 'json',
success: function (data) {
var items = [], item, item_data;
@ -231,7 +241,7 @@ function Wardrobe() {
item.update(item_data);
items.push(item);
}
success(items, data.total_pages, page);
success(items, data.total_pages, page, data.query);
} else if(data.error) {
error(data.error);
}
@ -1319,8 +1329,9 @@ function Wardrobe() {
this.request = {};
function itemsOnLoad(items, total_pages, page) {
function itemsOnLoad(items, total_pages, page, query) {
search.events.trigger('updateItems', items);
search.events.trigger('updateQuery', query);
search.events.trigger('updatePagination', page, total_pages);
}

View file

@ -136,12 +136,12 @@
%label{for: 'advanced-search-occupies'} Occupies
-# TODO: populate
%select{id: 'advanced-search-occupies'}
%option any zone
%option{value: ''} any zone
%li.select
%label{for: 'advanced-search-restricts'} Restricts
-# TODO: populate
%select{id: 'advanced-search-restricts'}
%option any or no zones
%option{value: ''} any or no zones
%div
%ul
%li.checkbox