From d984f844454f648e18194de07100c2136f21b760 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 11 Oct 2010 18:37:20 -0400 Subject: [PATCH] prep wardrobe js for standalone server use --- app/controllers/items_controller.rb | 1 + config/routes.rb | 3 ++- public/javascripts/outfits/edit.js | 2 +- public/javascripts/wardrobe.js | 9 +++------ 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index bf0acf9d..c626ea36 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -13,6 +13,7 @@ class ItemsController < ApplicationController @items = Item.search(@query).alphabetize.paginate :page => params[:page], :per_page => per_page respond_to do |format| format.html { render } + format.json { render :json => {:items => @items, :total_pages => @items.total_pages} } format.js { render :json => {:items => @items, :total_pages => @items.total_pages}, :callback => params[:callback] } end rescue diff --git a/config/routes.rb b/config/routes.rb index 3ce5b77d..05aaa14e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,8 +2,10 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/' => 'items#index', :as => :items match '/index.js' => 'items#index', :format => :js match '/items.json' => 'items#index', :format => :json + match '/items/:id' => 'items#show', :as => :item match '/item_zone_sets.js' => 'ItemZoneSets#index' + match '/item_zone_sets.json' => 'ItemZoneSets#index' match '/bodies/:body_id/swf_assets.json' => 'swf_assets#index', :as => :body_swf_assets match '/items/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets @@ -17,5 +19,4 @@ OpenneoImpressItems::Application.routes.draw do |map| resources :pets, :only => [:show] match '/wardrobe' => 'outfits#edit', :as => :wardrobe - match '/:id' => 'items#show', :as => :item end diff --git a/public/javascripts/outfits/edit.js b/public/javascripts/outfits/edit.js index 6c3325dc..6d247aa0 100644 --- a/public/javascripts/outfits/edit.js +++ b/public/javascripts/outfits/edit.js @@ -69,7 +69,7 @@ Partial.ItemSet = function ItemSet(wardrobe, selector) { info_link = $('', { 'class': 'object-info', html: 'i', - href: ITEMS_SERVER + '/' + item.id, + href: '/items/' + item.id, target: '_blank' }); if( diff --git a/public/javascripts/wardrobe.js b/public/javascripts/wardrobe.js index 3a439acd..75e99cc1 100644 --- a/public/javascripts/wardrobe.js +++ b/public/javascripts/wardrobe.js @@ -1,5 +1,4 @@ -var ITEMS_SERVER = '', - SHORT_URL_HOST = 'http://bit.ly/'; +var SHORT_URL_HOST = 'http://bit.ly/'; window.log = window.SWFLog = $.noop; @@ -184,13 +183,11 @@ function Wardrobe() { return items; } - var ITEMS_URL = ITEMS_SERVER + '/index.js?callback=?'; - Item.PER_PAGE = 21; Item.loadByQuery = function (query, offset, success, error) { var page = Math.round(offset / Item.PER_PAGE) + 1; - $.getJSON(ITEMS_URL, {q: query, per_page: Item.PER_PAGE, page: page}, function (data) { + $.getJSON('/items.json', {q: query, per_page: Item.PER_PAGE, page: page}, function (data) { var items = [], item, item_data; if(data.items) { for(var i = 0; i < data.items.length; i++) { @@ -213,7 +210,7 @@ function Wardrobe() { } ItemZoneSet.loadAll = function (success) { - $.getJSON(ITEMS_SERVER + '/item_zone_sets.js?callback=?', function (data) { + $.getJSON('/item_zone_sets.json', function (data) { for(var i = 0, l = data.length; i < l; i++) { ItemZoneSet.all.push(new ItemZoneSet(data[i])); }