From c5103b6557087b66082660de7ccda43bb6ae8cfa Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 20 Jul 2011 15:16:22 -0400 Subject: [PATCH] neomail link on closets --- app/controllers/application_controller.rb | 4 ++ app/controllers/closet_hangers_controller.rb | 10 +-- app/controllers/users_controller.rb | 19 ++++++ app/helpers/closet_hangers_helper.rb | 6 ++ app/models/user.rb | 2 + app/stylesheets/closet_hangers/_index.sass | 26 +++++++- app/views/closet_hangers/index.html.haml | 29 ++++++--- config/routes.rb | 2 +- ...720183722_add_neopets_username_to_users.rb | 9 +++ db/schema.rb | 4 +- public/images/neomail.png | Bin 0 -> 754 bytes public/stylesheets/compiled/screen.css | 58 +++++++++++++----- 12 files changed, 137 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20110720183722_add_neopets_username_to_users.rb create mode 100644 public/images/neomail.png diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d7e2fc80..5f2d3a89 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,6 +19,10 @@ class ApplicationController < ActionController::Base render :file => 'public/403.html', :layout => false, :status => :forbidden end + def redirect_back!(default=:back) + redirect_to(params[:return_to] || default) + end + def user_is?(user) user_signed_in? && user == current_user end diff --git a/app/controllers/closet_hangers_controller.rb b/app/controllers/closet_hangers_controller.rb index 87435307..fdc53c07 100644 --- a/app/controllers/closet_hangers_controller.rb +++ b/app/controllers/closet_hangers_controller.rb @@ -36,7 +36,7 @@ class ClosetHangersController < ApplicationController respond_to do |format| format.html { flash[:success] = "Success! You own #{@closet_hanger.quantity} #{@item.name.pluralize}." - redirect_back! + redirect_back!(@item) } format.json { render :json => true } @@ -45,7 +45,7 @@ class ClosetHangersController < ApplicationController respond_to do |format| format.html { flash[:alert] = "We couldn't save how many of this item you own: #{@closet_hanger.errors.full_messages.to_sentence}" - redirect_back! + redirect_back!(@item) } format.json { render :json => {:errors => @closet_hanger.errors.full_messages}, :status => :unprocessable_entity } @@ -75,11 +75,7 @@ class ClosetHangersController < ApplicationController def redirect_after_destroy! flash[:success] = "Success! You do not own #{@item.name}." - redirect_back! - end - - def redirect_back! - redirect_to params[:return_to] || @item + redirect_back!(@item) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 70ed203d..e76b953c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,24 @@ class UsersController < ApplicationController + before_filter :find_and_authorize_user!, :only => [:update] + def top_contributors @users = User.top_contributors.paginate :page => params[:page], :per_page => 20 end + + def update + @user.update_attributes params[:user] + flash[:success] = "Settings successfully saved" + redirect_back! user_closet_hangers_path(@user) + end + + protected + + def find_and_authorize_user! + if current_user.id == params[:id].to_i + @user = current_user + else + raise AccessDenied + end + end end + diff --git a/app/helpers/closet_hangers_helper.rb b/app/helpers/closet_hangers_helper.rb index d5f173ae..a7d77982 100644 --- a/app/helpers/closet_hangers_helper.rb +++ b/app/helpers/closet_hangers_helper.rb @@ -1,4 +1,10 @@ +require 'cgi' + module ClosetHangersHelper + def send_neomail_url(user) + "http://www.neopets.com/neomessages.phtml?type=send&recipient=#{CGI.escape @user.neopets_username}" + end + def public_perspective? @public_perspective end diff --git a/app/models/user.rb b/app/models/user.rb index 1bdad3ab..a2ab633f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,8 @@ class User < ActiveRecord::Base devise :rememberable + attr_accessible :neopets_username + def contribute!(pet) new_contributions = [] new_points = 0 diff --git a/app/stylesheets/closet_hangers/_index.sass b/app/stylesheets/closet_hangers/_index.sass index 2b61baf3..7fd8aa3d 100644 --- a/app/stylesheets/closet_hangers/_index.sass +++ b/app/stylesheets/closet_hangers/_index.sass @@ -4,7 +4,7 @@ body.closet_hangers-index #title float: left - margin-bottom: .5em + margin-bottom: 0 .flash clear: both @@ -28,6 +28,30 @@ body.closet_hangers-index repeat: no-repeat padding-left: $icon-width + 4px + #closet-hangers-contact + clear: both + font-size: 85% + margin-bottom: 1em + margin-left: 2em + min-height: image-height("neomail.png") + + a + background: + image: image-url("neomail.png") + position: left center + repeat: no-repeat + padding-left: image-width("neomail.png") + 2px + + input[type=text] + width: 10em + + label + font-weight: bold + margin-right: .5em + + &:after + content: ":" + #closet-hangers clear: both text-align: center diff --git a/app/views/closet_hangers/index.html.haml b/app/views/closet_hangers/index.html.haml index 0bf4cd89..1b44a3da 100644 --- a/app/views/closet_hangers/index.html.haml +++ b/app/views/closet_hangers/index.html.haml @@ -8,15 +8,27 @@ - else - title "#{@user.name}'s Items" +- content_for :before_flashes do + #closet-hangers-contact + - if public_perspective? + - if @user.neopets_username? + = link_to "Neomail #{@user.neopets_username}", send_neomail_url(@user) + - else + = form_for @user do |f| + = f.label :neopets_username + = f.text_field :neopets_username + = f.submit "Save" + #closet-hangers{:class => public_perspective? ? nil : 'current-user'} - - if !@closet_hangers.empty? - - unless public_perspective? + - if public_perspective? + - if @closet_hangers.empty? + %p #{@user.name} hasn't tracked any items on Dress to Impress. + - else + - unless @closet_hangers.empty? %p These are the items you own. Hover over an item to remove it from the list or to change the quantity. - = render :partial => 'closet_hanger', :collection => @closet_hangers, :locals => {:show_controls => user_is?(@user)} - - else - - unless public_perspective? + - else %p You haven't tracked any items on Dress to Impress. %p Here you can keep track of what items you already own, so that as you @@ -27,8 +39,11 @@ It's easy to get started! = link_to "Just import your Neopets closet in a few quick steps.", new_closet_page_path Have fun! - - else - %p #{@user.name} hasn't tracked any items on Dress to Impress. + %p + You can share + = link_to "this page", request.fullpath + with the world, and they'll be able to see what items you own. + = render :partial => 'closet_hanger', :collection => @closet_hangers, :locals => {:show_controls => user_is?(@user)} - content_for :stylesheets do = stylesheet_link_tag 'south-street/jquery-ui' diff --git a/config/routes.rb b/config/routes.rb index f3fe0d21..e8c8d245 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,7 +35,7 @@ OpenneoImpressItems::Application.routes.draw do |map| match '/logout' => 'sessions#destroy', :as => :logout match '/users/authorize' => 'sessions#create' - resources :user, :only => [] do + resources :users, :path => 'user', :only => [:update] do resources :contributions, :only => [:index] resources :closet_hangers, :only => [:index], :path => 'closet' diff --git a/db/migrate/20110720183722_add_neopets_username_to_users.rb b/db/migrate/20110720183722_add_neopets_username_to_users.rb new file mode 100644 index 00000000..5cef44b9 --- /dev/null +++ b/db/migrate/20110720183722_add_neopets_username_to_users.rb @@ -0,0 +1,9 @@ +class AddNeopetsUsernameToUsers < ActiveRecord::Migration + def self.up + add_column :users, :neopets_username, :string + end + + def self.down + remove_column :users, :neopets_username + end +end diff --git a/db/schema.rb b/db/schema.rb index 931e3818..6b144a06 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110712232259) do +ActiveRecord::Schema.define(:version => 20110720183722) do create_table "auth_servers", :force => true do |t| t.string "short_name", :limit => 10, :null => false @@ -177,6 +177,7 @@ ActiveRecord::Schema.define(:version => 20110712232259) do t.boolean "forum_admin", :default => false, :null => false t.boolean "forum_moderator" t.boolean "image_mode_tester", :default => false, :null => false + t.string "neopets_username" end create_table "zones", :force => true do |t| @@ -187,3 +188,4 @@ ActiveRecord::Schema.define(:version => 20110712232259) do end end + diff --git a/public/images/neomail.png b/public/images/neomail.png new file mode 100644 index 0000000000000000000000000000000000000000..4a6c5d396ad024567a769d1f2285c525bef8c88b GIT binary patch literal 754 zcmV~0d>kmp9&fG9>#5EaEn(MD9Xvl47<{Rb2T3D!0$wpy4@P!Tnn zB0fxQ2!aPL_fZ@!=Wv9zmj8jnf5JO`<=MmZs@#@p z5O*{}9L5B6J+L7ORza<+9h)-B~<&cwIhUkd?cp4is-ziNrfY^u-7xdbFt=#%1534Oi8ajBBo}VZvCxd1 zTu*VtX+~P45)Om?dG5aS`PPW(%?lDPBwaz$6C^$8$_Q#plJTjpbgj;_rYi*?oK~m+ zDD`C->dkZKh0j6|Q^-0bJxIFHnHJOo$@r8{VNIUWU>31rp3@BVvYIZG2D0>Yuj2Y- zg?b?AObc>pK`oG+zkPsr3x_BTWXX8H*w}0@e;@>?SdsP&!-HMidhRn*4VkHi+<58} zTg6ae0~aSoNqRq(^;(g}0#Yiz)&q*YIg-f)mmeJA&3%nD3aJ$X-6L%1+fEQRIeTL* zS5K6|3cOaNtTtBowSZzzj!ZfM7L<|f+jtyp4ccf7mf6J$n}&ALkZlfLEYRoNvtG0Q zzJh|U~_Rdjkv}0kGt_?V}5$?sXN`N zTt|nOa)sx)IIf_-7XW**;!X9`USPjuUUsJrREk)6q*M9ZHEb zl2A!T3LBjrrTx74{FsUNcVA1zw%IWoiGNMw=s9P8>+qh!B*saR2}S literal 0 HcmV?d00001 diff --git a/public/stylesheets/compiled/screen.css b/public/stylesheets/compiled/screen.css index 4037da2a..b7596113 100644 --- a/public/stylesheets/compiled/screen.css +++ b/public/stylesheets/compiled/screen.css @@ -552,7 +552,7 @@ div.jGrowl div.jGrowl-closer { /* line 5, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #title { float: left; - margin-bottom: 0.5em; + margin-bottom: 0; } /* line 9, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index .flash { @@ -611,11 +611,39 @@ body.closet_hangers-index #closet-hangers-items-search input[type=search].loadin padding-left: 20px; } /* line 31, ../../../app/stylesheets/closet_hangers/_index.sass */ +body.closet_hangers-index #closet-hangers-contact { + clear: both; + font-size: 85%; + margin-bottom: 1em; + margin-left: 2em; + min-height: 16px; +} +/* line 38, ../../../app/stylesheets/closet_hangers/_index.sass */ +body.closet_hangers-index #closet-hangers-contact a { + background-image: url('/images/neomail.png?1311187553'); + background-position: left center; + background-repeat: no-repeat; + padding-left: 18px; +} +/* line 45, ../../../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 { + width: 10em; +} +/* line 48, ../../../app/stylesheets/closet_hangers/_index.sass */ +body.closet_hangers-index #closet-hangers-contact label { + font-weight: bold; + margin-right: 0.5em; +} +/* line 52, ../../../app/stylesheets/closet_hangers/_index.sass */ +body.closet_hangers-index #closet-hangers-contact label:after { + content: ":"; +} +/* line 55, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers { clear: both; text-align: center; } -/* line 36, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 60, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers .object .quantity { -moz-opacity: 0.75; -webkit-opacity: 0.75; @@ -629,26 +657,26 @@ body.closet_hangers-index #closet-hangers .object .quantity { text-align: left; top: 60px; } -/* line 46, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 70, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers .object .quantity span, body.closet_hangers-index #closet-hangers .object .quantity input[type=number] { font-size: 16px; font-weight: bold; } -/* line 50, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 74, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers .object form { display: none; } -/* line 55, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 79, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover form { display: inline; } -/* line 58, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 82, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover .closet-hanger-destroy { position: absolute; right: 18px; top: 0; } -/* line 63, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 87, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover .closet-hanger-destroy input { /* http://www.zurb.com/blog_uploads/0000/0617/buttons-03.html */ -moz-border-radius: 5px; @@ -689,7 +717,7 @@ body.closet_hangers-index #closet-hangers.current-user .object:hover .closet-han body.closet_hangers-index #closet-hangers.current-user .object:hover .closet-hanger-destroy input:hover { background-color: #999999; } -/* line 66, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 90, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover .quantity { -moz-opacity: 1; -webkit-opacity: 1; @@ -699,33 +727,33 @@ body.closet_hangers-index #closet-hangers.current-user .object:hover .quantity { top: 56px; padding: 0; } -/* line 72, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 96, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover .quantity span { display: none; } -/* line 75, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 99, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover .quantity input[type=number] { padding: 2px; width: 2em; } -/* line 79, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 103, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user .object:hover .quantity input[type=submit] { font-size: 85%; } -/* line 84, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 108, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user.js .object:hover .quantity input[type=number] { width: 2.5em; } -/* line 87, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 111, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user.js .object:hover .quantity input[type=submit] { display: none; } -/* line 90, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 114, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user.js .object.loading { background: #eeffee; outline: 1px solid #006600; } -/* line 94, ../../../app/stylesheets/closet_hangers/_index.sass */ +/* line 118, ../../../app/stylesheets/closet_hangers/_index.sass */ body.closet_hangers-index #closet-hangers.current-user.js .object.loading .quantity span:after { content: "…"; }