Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to associate an image with a reward #170

Merged
merged 2 commits into from
Dec 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/admin.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Crowdhoster.admin =

$('#reward-add').on 'click', (e) ->
e.preventDefault()
$('#rewards ul').append('<li><table class="table"><tr><th>Reward</th><th>Number Claimed</th><th>Delete?</th></tr><tr><td><label>Minimum Contribution To Claim</label><div class="currency"><input name="reward[][price]" type="text" /><span style="position:absolute">$</span></div><label>Title</label><input name="reward[][title]" type="text" /><br/><label>Description</label><textarea name="reward[][description]"></textarea><br/><label>Estimated Delivery Date (i.e. May 2013)</label><input name="reward[][delivery_date]" type="text" /><br/><label>Number Available (leave blank if unlimited)</label><input name="reward[][number]" type="text" /></td><td>0</td><td><input type="checkbox" name="reward[][delete]" value="delete"/></td></tr></table></li>')
$('#rewards ul').append('<li><table class="table"><tr><th>Reward</th><th>Number Claimed</th><th>Delete?</th></tr><tr><td><label>Minimum Contribution To Claim</label><div class="currency"><input name="reward[][price]" type="text" /><span style="position:absolute">$</span></div><label>Title (required)</label><input name="reward[][title]" type="text" /><br/><label>Image URL (optional)</label><input placeholder="http://www.host.com/image.jpg" name="reward[][image_url]" type="text" /><br/><label>Description (required)</label><textarea name="reward[][description]"></textarea><br/><label>Estimated Delivery Date (required)</label><input placeholder="i.e. May 2013" name="reward[][delivery_date]" type="text" /><br/><label>Number Available (leave blank if unlimited)</label><input name="reward[][number]" type="text" /></td><td>0</td><td><input type="checkbox" name="reward[][delete]" value="delete"/></td></tr></table></li>')

$('.faq.sortable').sortable
stop: (e, ui) ->
Expand Down
25 changes: 25 additions & 0 deletions app/assets/javascripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ $( document ).ready(function() {
"campaign[fixed_payment_amount]": { required: true, number: true, min: 1 },
"campaign[additional_info_label]": { required: true },
"campaign[reward_reference]": { required: true },
"reward[][price]": { required: true, number: true },
"reward[][title]": { required: true },
"reward[][image_url]": { url: true },
"reward[][description]": { required: true },
"reward[][delivery_date]": { required: true },
"reward[][number]": { number: true },
"campaign[contributor_reference]": { required: true },
"campaign[video_embed_id]": { minlength: 11 , maxlength: 11},
"campaign[primary_call_to_action_button]": { required: true },
Expand Down Expand Up @@ -125,6 +131,25 @@ $( document ).ready(function() {
"campaign[reward_reference]": {
required: "You must choose a word"
},
"reward[][price]": {
required: "You must enter a price",
number: "The price must be a number"
},
"reward[][title]": {
required: "You must enter a title"
},
"reward[][image_url]": {
url: "This must be a valid image URL"
},
"reward[][description]": {
required: "You must enter a description"
},
"reward[][delivery_date]": {
required: "You must choose a delivery date"
},
"reward[][number]": {
number: "This must be a number"
},
"campaign[contributor_reference]": {
required: "You must choose a word"
},
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/admin.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
color: black;
font-size: 14px;
margin-bottom: 0px;
&.error {
color: #b94a48;
margin-bottom: 10px;
font-size: 14px;
}
}
table {
margin-bottom: 0px;
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/admin/campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def copy
# Completely refresh the rewards
old_campaign.rewards.each do |reward|
@campaign.rewards.create title: reward.title,
image_url: reward.image_url,
description: reward.description,
delivery_date: reward.delivery_date,
number: reward.number,
Expand Down Expand Up @@ -107,6 +108,7 @@ def create
params[:reward].each do |reward|
unless reward['delete'] && reward['delete'] == 'delete'
@campaign.rewards.create title: reward['title'],
image_url: reward['image_url'],
description: reward['description'],
delivery_date: reward['delivery_date'],
number: reward['number'].to_i,
Expand Down Expand Up @@ -180,6 +182,7 @@ def update
if reward['id']
r = Reward.find(reward['id'])
r.title = reward['title']
r.image_url = reward['image_url']
r.description = reward['description']
r.delivery_date = reward['delivery_date']
r.number = reward['number'].to_i
Expand All @@ -191,6 +194,7 @@ def update
end
else
@campaign.rewards.create title: reward['title'],
image_url: reward['image_url'],
description: reward['description'],
delivery_date: reward['delivery_date'],
number: reward['number'].to_i,
Expand Down
3 changes: 2 additions & 1 deletion app/models/reward.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Reward < ActiveRecord::Base
attr_accessible :title, :description, :delivery_date, :number, :price, :campaign_id, :visible_flag
attr_accessible :title, :description, :delivery_date, :number, :price, :campaign_id, :visible_flag, :image_url

validates :title, :description, :delivery_date, :price, presence: true
validates :image_url, :format => URI::regexp(%w(http https))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:allow_blank => true


belongs_to :campaign
has_many :payments
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/reward_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class RewardSerializer < ActiveModel::Serializer
attributes :id, :title, :description, :price, :delivery_date, :number, :campaign_id, :number_of_payments
attributes :id, :title, :description, :price, :delivery_date, :number, :campaign_id, :number_of_payments, :image_url
end
2 changes: 2 additions & 0 deletions app/views/admin/campaigns/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
</div>
<label>Title</label>
<input name="reward[][title]" type="text" value="<%= reward.title %>"/><br/>
<label>Image URL</label>
<input name="reward[][image_url]" type="text" value="<%= reward.image_url %>"/><br/>
<label>Description</label>
<textarea name="reward[][description]"><%= reward.description %></textarea><br/>
<label>Estimated Delivery Date (i.e. May 2013)</label>
Expand Down
3 changes: 3 additions & 0 deletions app/views/theme/assets/stylesheets/campaign.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@
font-weight: bold;
margin-bottom: 12px;
}
&.image {
margin-bottom: 12px;
}
&.description {
margin-bottom: 12px;
}
Expand Down
1 change: 1 addition & 0 deletions app/views/theme/views/campaign.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<a href="<%= url_for(checkout_amount_path(@campaign, reward: reward.id)) %>" onclick="<%= 'return false' if reward.sold_out? %>" class="<%= 'disabled' if reward.sold_out? %>">
<p class="price">$<%= number_with_precision(reward.price, precision: (reward.price*100%100==0.0 ? 0 : 2)) %></p>
<p class="title"><%= reward.title %></p>
<% if reward.image_url.present? %><p class="image"><img src="<%= reward.image_url %>"></p><% end %>
<p class="description"><%= reward.description %></p>
<p class="delivery">Estimated Delivery: <%= reward.delivery_date %></p>
<p class="claimed">
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20131220221035_add_image_to_reward.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddImageToReward < ActiveRecord::Migration
def change
add_column :rewards, :image_url, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20131206225359) do
ActiveRecord::Schema.define(:version => 20131220221035) do

create_table "campaigns", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -137,6 +137,7 @@
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "visible_flag", :default => true, :null => false
t.string "image_url"
end

create_table "settings", :force => true do |t|
Expand Down