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); $('#preview').data('fit', fit);
win.resize(fit).load(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(); fit();
} }
@ -1250,6 +1246,21 @@ View.Search = function (wardrobe) {
wrapper.toggleClass('advanced'); wrapper.toggleClass('advanced');
fit(); 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.PrankColorMessage = function(wardrobe) {

View file

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

View file

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

View file

@ -243,8 +243,18 @@ class Item
filters = params.values.map { |filter_params| filters = params.values.map { |filter_params|
if filter_params.has_key?(:key) if filter_params.has_key?(:key)
key = filter_params[:key].to_sym key = filter_params[:key].to_sym
if FIELD_KEYS.include?(key)
value = filter_params[:value] 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)
# Ugh, this bit feels so hacky :P # Ugh, this bit feels so hacky :P
if key == :user_closet_hanger_ownership if key == :user_closet_hanger_ownership
value = (value == 'true') value = (value == 'true')

View file

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