From ea7171b32250b12d321e52a205b46c2cbc41e02d Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 31 Jul 2011 23:45:57 -0400 Subject: [PATCH 1/3] fix ambiguous item_link partial throwing errors in outfits#show --- app/views/items/_item.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/items/_item.html.haml b/app/views/items/_item.html.haml index a3de7727..7b497011 100644 --- a/app/views/items/_item.html.haml +++ b/app/views/items/_item.html.haml @@ -1,3 +1,3 @@ .object - = render :partial => 'item_link', :locals => {:item => item} + = render :partial => 'items/item_link', :locals => {:item => item} From 2f0b0743e868df74cb4b003d9a82e4eadc67508d Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 31 Jul 2011 23:50:33 -0400 Subject: [PATCH 2/3] throw a search error on user:owns when user owns no items --- app/models/item.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/item.rb b/app/models/item.rb index ff025ad4..c4055588 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -710,6 +710,12 @@ class Item < ActiveRecord::Base # version of Arel, and other conditions will overwrite this one. Since IDs # are guaranteed to be integers, let's just build our own string condition # and be done with it. + + if item_ids.empty? + raise SearchError, "You don't #{ClosetHanger.verb :you, owned_value} " + + "any items yet. Head to Your Items to add some!" + end + "id IN (#{item_ids.join(',')})" end From be5bdb1eec00e5e71f18c3fa057b419214b9093a Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 1 Aug 2011 00:00:39 -0400 Subject: [PATCH 3/3] handle search errors better in wardrobe --- app/controllers/items_controller.rb | 1 + app/stylesheets/outfits/_edit.sass | 4 +++ public/javascripts/wardrobe.js | 38 ++++++++++++++++++-------- public/stylesheets/compiled/screen.css | 35 ++++++++++++++---------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 05ff567b..c3ecfcf5 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -20,6 +20,7 @@ class ItemsController < ApplicationController rescue Item::SearchError respond_to do |format| format.html { flash.now[:alert] = $!.message } + format.json { render :json => {:error => $!.message} } format.js { render :json => {:error => $!.message}, :callback => params[:callback] } end end diff --git a/app/stylesheets/outfits/_edit.sass b/app/stylesheets/outfits/_edit.sass index b29a8a9f..45812524 100644 --- a/app/stylesheets/outfits/_edit.sass +++ b/app/stylesheets/outfits/_edit.sass @@ -546,6 +546,10 @@ body.outfits-edit .outfit-url font-size: 75% + #preview-search-form-error + +error + padding: .25em .5em + &.user-signed-in #preview-sidebar-nav-outfits display: block diff --git a/public/javascripts/wardrobe.js b/public/javascripts/wardrobe.js index 2a2d6988..f9668a4b 100644 --- a/public/javascripts/wardrobe.js +++ b/public/javascripts/wardrobe.js @@ -210,18 +210,34 @@ function Wardrobe() { Item.loadByQuery = function (query, offset, success, error) { var page = Math.round(offset / Item.PER_PAGE) + 1; - $.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++) { - item_data = data.items[i]; - item = Item.find(item_data.id); - item.update(item_data); - items.push(item); + $.ajax({ + url: '/items.json', + data: {q: query, per_page: Item.PER_PAGE, page: page}, + dataType: 'json', + success: function (data) { + var items = [], item, item_data; + if(data.items) { + for(var i = 0; i < data.items.length; i++) { + item_data = data.items[i]; + item = Item.find(item_data.id); + item.update(item_data); + items.push(item); + } + success(items, data.total_pages, page); + } else if(data.error) { + error(data.error); } - success(items, data.total_pages, page); - } else if(data.error) { - error(data.error); + }, + error: function (xhr) { + console.log($.parseJSON(xhr.responseText)); + try { + var json = $.parseJSON(xhr.responseText); + } catch(e) { + $.jGrowl("There was an error running that search, probably on our end. Try again?"); + return false; + } + + if(json.error) error(json.error); } }); } diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index 906a6599..329855cc 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -650,7 +650,7 @@ body.closet_hangers-index #closet-hangers-contact { /* line 33, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers-contact a, body.closet_hangers-index #closet-hangers-contact > span { text-decoration: none; - background-image: url('/images/neomail.png?1311877030'); + background-image: url('/images/neomail.png?1312167956'); background-position: left center; background-repeat: no-repeat; color: inherit; @@ -664,7 +664,7 @@ body.closet_hangers-index #closet-hangers-contact a:hover, body.closet_hangers-i } /* line 44, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers-contact > span { - background-image: url('/images/neomail_edit.png?1312153508'); + background-image: url('/images/neomail_edit.png?1312167956'); } /* line 47, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers-contact input[type=text], body.closet_hangers-index #closet-hangers-contact body.pets-bulk #bulk-pets-form textarea, body.pets-bulk #bulk-pets-form body.closet_hangers-index #closet-hangers-contact textarea { @@ -2413,7 +2413,7 @@ body.outfits-edit .object:hover ul, body.outfits-edit .object:hover .object-info } /* line 419, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit .nc-icon { - background: url('/images/nc.png?1311877029') no-repeat; + background: url('/images/nc.png?1312167956') no-repeat; height: 16px; position: absolute; right: 16px; @@ -3127,35 +3127,42 @@ body.outfits-edit form#save-outfit-form .outfit-star { body.outfits-edit .outfit-url { font-size: 75%; } -/* line 550, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 549, ../../../app/stylesheets/outfits/_edit.sass */ +body.outfits-edit #preview-search-form-error { + background: #fbe3e4; + border: 1px solid #fbc2c4; + color: #8a1f11; + padding: 0.25em 0.5em; +} +/* line 554, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #preview-sidebar-nav-outfits { display: block; } -/* line 552, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 556, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #save-outfit { display: inline-block; } -/* line 556, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 560, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #save-outfit-wrapper.active-outfit #save-outfit { display: none; } -/* line 558, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 562, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #save-outfit-wrapper.active-outfit #save-current-outfit, body.outfits-edit.user-signed-in #save-outfit-wrapper.active-outfit #save-outfit-copy { display: inline-block; } -/* line 560, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 564, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #save-outfit-wrapper.active-outfit #current-outfit-permalink { display: inline-block; } -/* line 563, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 567, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #save-outfit-form { display: block; } -/* line 565, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 569, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #save-outfit, body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #save-current-outfit, body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #save-outfit-copy, body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #current-outfit-permalink, body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #shared-outfit-permalink, body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #share-outfit, body.outfits-edit.user-signed-in #save-outfit-wrapper.saving-outfit #shared-outfit-url { display: none; } -/* line 567, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 571, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-signed-in .preview-search-form-your-items { display: -moz-inline-box; -moz-box-orient: vertical; @@ -3164,15 +3171,15 @@ body.outfits-edit.user-signed-in .preview-search-form-your-items { *display: inline; *vertical-align: auto; } -/* line 571, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 575, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit.user-not-signed-in #save-outfit-not-signed-in { display: inline-block; } -/* line 575, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 579, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit #save-outfit-wrapper.shared-outfit #shared-outfit-permalink, body.outfits-edit #save-outfit-wrapper.shared-outfit #shared-outfit-url { display: inline-block; } -/* line 577, ../../../app/stylesheets/outfits/_edit.sass */ +/* line 581, ../../../app/stylesheets/outfits/_edit.sass */ body.outfits-edit #save-outfit-wrapper.shared-outfit #current-outfit-permalink { display: none !important; }