homepage outfit features
This commit is contained in:
parent
f11f6374da
commit
04a328e6ee
7 changed files with 104 additions and 28 deletions
|
@ -7,6 +7,8 @@ var preview_el = $('#pet-preview'),
|
||||||
response_el = preview_el.find('span'),
|
response_el = preview_el.find('span'),
|
||||||
name_el = $('#main-pet-name');
|
name_el = $('#main-pet-name');
|
||||||
|
|
||||||
|
var defaultPreviewUrl = img_el.attr('src');
|
||||||
|
|
||||||
preview_el.click(function () {
|
preview_el.click(function () {
|
||||||
Preview.Job.current.visit();
|
Preview.Job.current.visit();
|
||||||
});
|
});
|
||||||
|
@ -42,14 +44,32 @@ var Preview = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$.getJSON('http://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
function loadNotable() {
|
||||||
|
$.getJSON('http://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
||||||
var notables = response.notables;
|
var notables = response.notables;
|
||||||
var i = Math.floor(Math.random() * notables.length);
|
var i = Math.floor(Math.random() * notables.length);
|
||||||
Preview.Job.fallback = new Preview.Job.Name(notables[i].petName);
|
Preview.Job.fallback = new Preview.Job.Name(notables[i].petName);
|
||||||
if(!Preview.Job.current) {
|
if(!Preview.Job.current) {
|
||||||
Preview.Job.fallback.setAsCurrent();
|
Preview.Job.fallback.setAsCurrent();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadFeature() {
|
||||||
|
$.getJSON('/donations/features', function(features) {
|
||||||
|
if (features.length > 0) {
|
||||||
|
var feature = features[Math.floor(Math.random() * features.length)];
|
||||||
|
Preview.Job.fallback = new Preview.Job.Feature(feature);
|
||||||
|
if (!Preview.Job.current) {
|
||||||
|
Preview.Job.fallback.setAsCurrent();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loadNotable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
loadFeature();
|
||||||
|
|
||||||
Preview.Job = function (key, base) {
|
Preview.Job = function (key, base) {
|
||||||
var job = this,
|
var job = this,
|
||||||
|
@ -61,8 +81,12 @@ Preview.Job = function (key, base) {
|
||||||
// lol lazy code for prank image :P
|
// lol lazy code for prank image :P
|
||||||
return "http://swfimages.impress.openneo.net" +
|
return "http://swfimages.impress.openneo.net" +
|
||||||
"/biology/000/000/0-2/" + key.substr(2) + "/300x300.png";
|
"/biology/000/000/0-2/" + key.substr(2) + "/300x300.png";
|
||||||
} else {
|
} else if (base === 'cp' || base === 'cpn') {
|
||||||
return petImage(base + '/' + key, quality);
|
return petImage(base + '/' + key, quality);
|
||||||
|
} else if (base === 'url') {
|
||||||
|
return key;
|
||||||
|
} else {
|
||||||
|
throw new Error("unrecognized image base " + base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +106,10 @@ Preview.Job = function (key, base) {
|
||||||
Preview.Job.current = job;
|
Preview.Job.current = job;
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.notFound = function() {
|
||||||
|
Preview.notFound('pet-not-found');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Preview.Job.Name = function (name) {
|
Preview.Job.Name = function (name) {
|
||||||
|
@ -102,6 +130,25 @@ Preview.Job.Hash = function (hash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Preview.Job.Feature = function(feature) {
|
||||||
|
Preview.Job.apply(this, [feature.outfit_image_url, 'url']);
|
||||||
|
this.name = "Thanks for donating, " + feature.donor_name + "!"; // TODO: i18n
|
||||||
|
|
||||||
|
this.visit = function() {
|
||||||
|
window.location = '/donate';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.notFound = function() {
|
||||||
|
// The outfit thumbnail hasn't generated or is missing or something.
|
||||||
|
// Let's fall back to a boring image for now.
|
||||||
|
var boring = new Preview.Job.Feature({
|
||||||
|
donor_name: feature.donor_name,
|
||||||
|
outfit_image_url: defaultPreviewUrl
|
||||||
|
});
|
||||||
|
boring.setAsCurrent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
var previewWithNameTimeout;
|
var previewWithNameTimeout;
|
||||||
|
@ -127,7 +174,7 @@ $(function () {
|
||||||
}).error(function () {
|
}).error(function () {
|
||||||
if(Preview.Job.current.loading) {
|
if(Preview.Job.current.loading) {
|
||||||
Preview.Job.loading = false;
|
Preview.Job.loading = false;
|
||||||
Preview.notFound('pet-not-found');
|
Preview.Job.current.notFound();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,10 @@ body.static-donate
|
||||||
text-align: center
|
text-align: center
|
||||||
width: $outfit-banner-inner-width
|
width: $outfit-banner-inner-width
|
||||||
|
|
||||||
|
img
|
||||||
|
height: $outfit-inner-height
|
||||||
|
width: $outfit-inner-width
|
||||||
|
|
||||||
#fine-print
|
#fine-print
|
||||||
font-size: 85%
|
font-size: 85%
|
||||||
margin-top: 2em
|
margin-top: 2em
|
||||||
|
|
8
app/controllers/donation_features_controller.rb
Normal file
8
app/controllers/donation_features_controller.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class DonationFeaturesController < ApplicationController
|
||||||
|
def index
|
||||||
|
# TODO: scope by campaign?
|
||||||
|
@features = DonationFeature.includes(:donation).includes(:outfit).
|
||||||
|
where('outfit_id IS NOT NULL')
|
||||||
|
render json: @features
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,3 +1,6 @@
|
||||||
class StaticController < ApplicationController
|
class StaticController < ApplicationController
|
||||||
|
def donate
|
||||||
|
# TODO: scope by campaign?
|
||||||
|
@donations = Donation.includes(features: :outfit).order('created_at DESC')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,12 @@ class DonationFeature < ActiveRecord::Base
|
||||||
|
|
||||||
validates :outfit, presence: true, if: :outfit_id?
|
validates :outfit, presence: true, if: :outfit_id?
|
||||||
|
|
||||||
|
delegate :donor_name, to: :donation
|
||||||
|
|
||||||
|
def as_json(options={})
|
||||||
|
{donor_name: donor_name, outfit_image_url: outfit.image.medium.url}
|
||||||
|
end
|
||||||
|
|
||||||
def outfit_url=(outfit_url)
|
def outfit_url=(outfit_url)
|
||||||
self.outfit_id = outfit_url.split('/').last rescue nil
|
self.outfit_id = outfit_url.split('/').last rescue nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
toward our hosting costs this year. Thanks so much!
|
toward our hosting costs this year. Thanks so much!
|
||||||
|
|
||||||
= form_tag donations_path, method: 'POST', id: 'donation-form',
|
= form_tag donations_path, method: 'POST', id: 'donation-form',
|
||||||
'data-checkout-image' => image_path('default-preview.png'),
|
'data-checkout-image' => image_path('default_preview.png'),
|
||||||
'data-checkout-publishable-key' => Rails.configuration.stripe[:publishable_key] do
|
'data-checkout-publishable-key' => Rails.configuration.stripe[:publishable_key] do
|
||||||
= hidden_field_tag 'donation[stripe_token]'
|
= hidden_field_tag 'donation[stripe_token]'
|
||||||
= hidden_field_tag 'donation[donor_email]'
|
= hidden_field_tag 'donation[donor_email]'
|
||||||
|
@ -63,16 +63,15 @@
|
||||||
%h2 Thanks to our lovely donors!
|
%h2 Thanks to our lovely donors!
|
||||||
|
|
||||||
%ul#outfits
|
%ul#outfits
|
||||||
= Outfit.includes(:user).find_each do |outfit| # TODO: donors only
|
- @donations.each do |donation|
|
||||||
= outfit_li_for(outfit) do
|
- donation.features.each do |feature|
|
||||||
- if outfit.image?
|
%li
|
||||||
= link_to image_tag(outfit.image.small.url), outfit
|
- if feature.outfit_id? && feature.outfit.image?
|
||||||
|
= link_to image_tag(feature.outfit.image.small.url), feature.outfit
|
||||||
%header
|
|
||||||
- if outfit.user
|
|
||||||
Thanks, #{outfit.user.name}!
|
|
||||||
- else
|
- else
|
||||||
Thanks, anonymous!
|
= image_tag 'default_preview.png'
|
||||||
|
|
||||||
|
%header Thanks, #{donation.donor_name.presence || 'Anonymous'}!
|
||||||
|
|
||||||
#fine-print
|
#fine-print
|
||||||
%h2 Some notes on featured outfits
|
%h2 Some notes on featured outfits
|
||||||
|
@ -97,14 +96,19 @@
|
||||||
|
|
||||||
We reserve the right to refuse to post any outfit for any reason, and we
|
We reserve the right to refuse to post any outfit for any reason, and we
|
||||||
reserve the right to remove any previously posted outfit for any reason.
|
reserve the right to remove any previously posted outfit for any reason.
|
||||||
(That said, so long as your outfit is appropriate for Neopians of all ages,
|
Same goes for the name attached to your donation.
|
||||||
we don't expect any trouble.)
|
(That said, we intend to allow most any name and outfit that are
|
||||||
|
appropriate for Neopians of all ages.)
|
||||||
|
|
||||||
If you change your mind about donating, no worries: we'll refund any
|
If you change your mind about donating, no worries: we'll refund any
|
||||||
donation within 30 days of the moment you donated.
|
good-faith donation within 60 days of the day you donated.
|
||||||
(Please don't be that person who repeatedly donates and refunds.
|
(For example, changing your mind and requesting a refund *is* acting in
|
||||||
We'll stop posting your outfits
|
good faith, and we'd love to help you out.
|
||||||
<img src="http://images.neopets.com/neoboards/smilies/tongue.gif" />)
|
Posting an obscene outfit then requesting a refund once we take it down is
|
||||||
|
*not* acting in good faith, and we don't want to encourage that behavior
|
||||||
|
<img src="http://images.neopets.com/neoboards/smilies/tongue.gif" />
|
||||||
|
We determine "good faith" at our sole discretion—not limited to those
|
||||||
|
examples—but we're generally pretty understanding.)
|
||||||
|
|
||||||
**TL;DR: We love to help and acknowledge our good-faith donors,
|
**TL;DR: We love to help and acknowledge our good-faith donors,
|
||||||
but reserve the right not to do those things,
|
but reserve the right not to do those things,
|
||||||
|
|
|
@ -78,7 +78,11 @@ OpenneoImpressItems::Application.routes.draw do
|
||||||
only: [:create, :destroy]
|
only: [:create, :destroy]
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :donations, only: [:create, :show, :update]
|
resources :donations, only: [:create, :show, :update] do
|
||||||
|
collection do
|
||||||
|
resources :donation_features, path: 'features', only: [:index]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
match 'users/current-user/closet' => 'closet_hangers#index', :as => :your_items
|
match 'users/current-user/closet' => 'closet_hangers#index', :as => :your_items
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue