diff --git a/app/assets/javascripts/outfits/edit.js b/app/assets/javascripts/outfits/edit.js
index b1210e50..296e1bb0 100644
--- a/app/assets/javascripts/outfits/edit.js
+++ b/app/assets/javascripts/outfits/edit.js
@@ -1096,7 +1096,7 @@ View.Search = function (wardrobe) {
loadPage($(this).data('page'));
});
- this.initialize = $.proxy(wardrobe.item_zone_sets, 'load');
+ this.initialize = $.proxy(wardrobe.zones, 'load');
wardrobe.search.setPerPage(PAGINATION.PER_PAGE);
@@ -1247,17 +1247,38 @@ View.Search = function (wardrobe) {
fit();
});
- wardrobe.item_zone_sets.bind('update', function (item_zone_sets) {
- var selects = $('#advanced-search-occupies, #advanced-search-restricts');
- 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;
+ wardrobe.zones.bind('update', function (zones) {
+ var occupies = $('#advanced-search-occupies');
+ var restricts = $('#advanced-search-restricts');
+
+ // Get sorted unique zone sets by their labels
+ var labelMap = {};
+ zones.forEach(function(zone) {
+ labelMap[zone.plain_label] = {label: zone.label, typeId: zone.type_id};
});
- item_zone_sets.forEach(function(set) {
+
+ var sets = {items: [], biology: []};
+ Object.keys(labelMap).forEach(function(plainLabel) {
+ var relevantSets = labelMap[plainLabel].typeId > 1 ?
+ sets.items : sets.biology;
+ relevantSets.push({plainLabel: plainLabel,
+ label: labelMap[plainLabel].label});
+ });
+ Object.keys(sets).forEach(function(key) {
+ sets[key].sort(function(a, b) {
+ if (a.label < b.label) return -1;
+ else if (a.label > b.label) return 1;
+ else return 0;
+ });
+ });
+
+ sets.items.forEach(function(set) {
$('', {value: set.plainLabel, text: set.label}).
- appendTo(selects);
+ appendTo(occupies);
+ });
+ sets.biology.forEach(function(set) {
+ $('', {value: set.plainLabel, text: set.label}).
+ appendTo(restricts);
});
});
}
diff --git a/app/assets/javascripts/wardrobe.js b/app/assets/javascripts/wardrobe.js
index 6e8797b5..b247f486 100644
--- a/app/assets/javascripts/wardrobe.js
+++ b/app/assets/javascripts/wardrobe.js
@@ -251,19 +251,6 @@ function Wardrobe() {
Item.cache = {};
- var ItemZoneSet = {};
-
- ItemZoneSet.loadAll = function (success) {
- $.getJSON('/item_zone_sets.json', function (data) {
- Object.keys(data).forEach(function(key) {
- ItemZoneSet.all.push({plainLabel: key, label: data[key]});
- });
- success(ItemZoneSet.all);
- });
- }
-
- ItemZoneSet.all = [];
-
function Outfit(data) {
var outfit = this, previous_pet_type, worn_item_ids = [],
closet_item_ids = [], new_record = true;
@@ -1300,15 +1287,13 @@ function Wardrobe() {
}
}
- Controller.all.ItemZoneSets = function ItemZoneSetsController() {
- var item_zone_sets = this;
-
- function onLoad(sets) {
- item_zone_sets.events.trigger('update', sets);
- }
+ Controller.all.Zones = function ZonesController() {
+ var zones = this;
this.load = function () {
- ItemZoneSet.loadAll(onLoad);
+ $.getJSON('/zones.json', function(data) {
+ zones.events.trigger('update', data);
+ });
}
}
diff --git a/app/controllers/item_zone_sets_controller.rb b/app/controllers/item_zone_sets_controller.rb
deleted file mode 100644
index 6e346810..00000000
--- a/app/controllers/item_zone_sets_controller.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class ItemZoneSetsController < ApplicationController
- def index
- render :json => Zone.for_items.sets
- end
-end
diff --git a/app/controllers/zones_controller.rb b/app/controllers/zones_controller.rb
new file mode 100644
index 00000000..6e81a775
--- /dev/null
+++ b/app/controllers/zones_controller.rb
@@ -0,0 +1,5 @@
+class ZonesController < ApplicationController
+ def index
+ render json: Zone.all
+ end
+end
diff --git a/app/models/zone.rb b/app/models/zone.rb
index a8632583..56af9ffe 100644
--- a/app/models/zone.rb
+++ b/app/models/zone.rb
@@ -14,19 +14,11 @@ class Zone < ActiveRecord::Base
includes(:translations).where(t[:plain_label].eq(Zone.plainify_label(label)))
}
scope :for_items, lambda { where(arel_table[:type_id].gt(1)) }
-
+
def uncertain_label
@sometimes ? "#{label} sometimes" : label
end
- 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)
label.delete('\- /').parameterize
end
diff --git a/config/routes.rb b/config/routes.rb
index 801b97e8..f7d0121a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,8 +11,6 @@ OpenneoImpressItems::Application.routes.draw do
devise_for :users
- match '/item_zone_sets.json' => 'ItemZoneSets#index'
-
# DEPRECATED
match '/bodies/:body_id/swf_assets.json' => 'swf_assets#index', :as => :body_swf_assets
@@ -35,6 +33,7 @@ OpenneoImpressItems::Application.routes.draw do
resources :outfits, :only => [:show, :create, :update, :destroy]
resources :pet_attributes, :only => [:index]
resources :swf_assets, :only => [:index, :show]
+ resources :zones, only: [:index]
scope 'import' do
resources :closet_pages, :only => [:new, :create],