populate occupies/restricts selects

This commit is contained in:
Emi Matchu 2014-04-02 20:26:53 -05:00
parent 769f5d19e2
commit d7af6cfd4a
5 changed files with 37 additions and 14 deletions

View file

@ -201,10 +201,6 @@ View.Fullscreen = function (wardrobe) {
$('#preview').data('fit', fit);
win.resize(fit).load(fit);
// run fit after search updates select fields
function fitSoon() { setTimeout(fit, 0) }
wardrobe.item_zone_sets.bind('update', fitSoon);
wardrobe.pet_attributes.bind('update', fitSoon);
fit();
}
@ -1250,6 +1246,21 @@ View.Search = function (wardrobe) {
wrapper.toggleClass('advanced');
fit();
});
wardrobe.item_zone_sets.bind('update', function (item_zone_sets) {
var selects = $('#advanced-search-occupies, #advanced-search-restricts');
console.log("yo", selects, item_zone_sets);
var sorted_item_zone_sets = item_zone_sets.slice(0);
item_zone_sets.sort(function(a, b) {
if (a.label < b.label) return -1;
else if (a.label > b.label) return 1;
else return 0;
});
item_zone_sets.forEach(function(set) {
$('<option/>', {value: set.plainLabel, text: set.label}).
appendTo(selects);
});
});
}
View.PrankColorMessage = function(wardrobe) {

View file

@ -263,15 +263,13 @@ function Wardrobe() {
Item.cache = {};
function ItemZoneSet(name) {
this.name = name;
}
var ItemZoneSet = {};
ItemZoneSet.loadAll = function (success) {
$.getJSON('/item_zone_sets.json', function (data) {
for(var i = 0, l = data.length; i < l; i++) {
ItemZoneSet.all.push(new ItemZoneSet(data[i]));
}
Object.keys(data).forEach(function(key) {
ItemZoneSet.all.push({plainLabel: key, label: data[key]});
});
success(ItemZoneSet.all);
});
}

View file

@ -1,5 +1,5 @@
class ItemZoneSetsController < ApplicationController
def index
render :json => Zone.for_items.all_plain_labels
render :json => Zone.for_items.sets
end
end

View file

@ -243,8 +243,18 @@ class Item
filters = params.values.map { |filter_params|
if filter_params.has_key?(:key)
key = filter_params[:key].to_sym
value = filter_params[:value]
# Ew, the hackiest of hacks!
if key == :occupied_zone_set_name
key = :occupied_zone_id
value = TEXT_QUERY_RESOURCE_FINDERS[:zone].call(value)
elsif key == :restricted_zone_set_name
key = :restricted_zone_id
value = TEXT_QUERY_RESOURCE_FINDERS[:zone].call(value)
end
if FIELD_KEYS.include?(key)
value = filter_params[:value]
# Ugh, this bit feels so hacky :P
if key == :user_closet_hanger_ownership
value = (value == 'true')

View file

@ -19,8 +19,12 @@ class Zone < ActiveRecord::Base
@sometimes ? "#{label} sometimes" : label
end
def self.all_plain_labels
select([:id]).includes(:translations).all.map(&:plain_label).uniq.sort
def self.sets
{}.tap do |sets|
select([:id]).includes(:translations).each do |zone|
sets[zone.plain_label] = zone.label
end
end
end
def self.plainify_label(label)