1
0
Fork 0
forked from OpenNeo/impress

assign biology assets to restricts and item assets to occupies

This commit is contained in:
Emi Matchu 2014-04-02 20:56:42 -05:00
parent fc76e7cfe3
commit 3c36cd6aef
6 changed files with 43 additions and 46 deletions

View file

@ -1096,7 +1096,7 @@ View.Search = function (wardrobe) {
loadPage($(this).data('page')); loadPage($(this).data('page'));
}); });
this.initialize = $.proxy(wardrobe.item_zone_sets, 'load'); this.initialize = $.proxy(wardrobe.zones, 'load');
wardrobe.search.setPerPage(PAGINATION.PER_PAGE); wardrobe.search.setPerPage(PAGINATION.PER_PAGE);
@ -1247,17 +1247,38 @@ View.Search = function (wardrobe) {
fit(); fit();
}); });
wardrobe.item_zone_sets.bind('update', function (item_zone_sets) { wardrobe.zones.bind('update', function (zones) {
var selects = $('#advanced-search-occupies, #advanced-search-restricts'); var occupies = $('#advanced-search-occupies');
var sorted_item_zone_sets = item_zone_sets.slice(0); var restricts = $('#advanced-search-restricts');
item_zone_sets.sort(function(a, b) {
// 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};
});
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; if (a.label < b.label) return -1;
else if (a.label > b.label) return 1; else if (a.label > b.label) return 1;
else return 0; else return 0;
}); });
item_zone_sets.forEach(function(set) { });
sets.items.forEach(function(set) {
$('<option/>', {value: set.plainLabel, text: set.label}). $('<option/>', {value: set.plainLabel, text: set.label}).
appendTo(selects); appendTo(occupies);
});
sets.biology.forEach(function(set) {
$('<option/>', {value: set.plainLabel, text: set.label}).
appendTo(restricts);
}); });
}); });
} }

View file

@ -251,19 +251,6 @@ function Wardrobe() {
Item.cache = {}; 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) { function Outfit(data) {
var outfit = this, previous_pet_type, worn_item_ids = [], var outfit = this, previous_pet_type, worn_item_ids = [],
closet_item_ids = [], new_record = true; closet_item_ids = [], new_record = true;
@ -1300,15 +1287,13 @@ function Wardrobe() {
} }
} }
Controller.all.ItemZoneSets = function ItemZoneSetsController() { Controller.all.Zones = function ZonesController() {
var item_zone_sets = this; var zones = this;
function onLoad(sets) {
item_zone_sets.events.trigger('update', sets);
}
this.load = function () { this.load = function () {
ItemZoneSet.loadAll(onLoad); $.getJSON('/zones.json', function(data) {
zones.events.trigger('update', data);
});
} }
} }

View file

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

View file

@ -0,0 +1,5 @@
class ZonesController < ApplicationController
def index
render json: Zone.all
end
end

View file

@ -19,14 +19,6 @@ class Zone < ActiveRecord::Base
@sometimes ? "#{label} sometimes" : label @sometimes ? "#{label} sometimes" : label
end 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) def self.plainify_label(label)
label.delete('\- /').parameterize label.delete('\- /').parameterize
end end

View file

@ -11,8 +11,6 @@ OpenneoImpressItems::Application.routes.draw do
devise_for :users devise_for :users
match '/item_zone_sets.json' => 'ItemZoneSets#index'
# DEPRECATED # DEPRECATED
match '/bodies/:body_id/swf_assets.json' => 'swf_assets#index', :as => :body_swf_assets 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 :outfits, :only => [:show, :create, :update, :destroy]
resources :pet_attributes, :only => [:index] resources :pet_attributes, :only => [:index]
resources :swf_assets, :only => [:index, :show] resources :swf_assets, :only => [:index, :show]
resources :zones, only: [:index]
scope 'import' do scope 'import' do
resources :closet_pages, :only => [:new, :create], resources :closet_pages, :only => [:new, :create],