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

#43 Admin can delete a reward with a button on campaign edit page #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Binary file added app/assets/images/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions app/controllers/campaigns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ def checkout_confirmation
redirect_to campaign_home_url(@campaign)
end
end

def delete_reward
if @campaign.expired?
redirect_to campaign_home_url(@campaign), :flash => { :error => "Reward can't be Deleted, Campaign is Expired !" }
else
@r = Reward.find(params[:reward])
if(@r.payments.length == 0)
@r.destroy
redirect_to campaign_home_url(@campaign), :flash => { :notice => "Reward Deleted!" }
else
redirect_to campaign_home_url(@campaign), :flash => { :error => "Reward can't be Deleted it has Payments !" }
end
end
end

private

Expand Down
29 changes: 29 additions & 0 deletions app/views/theme/assets/stylesheets/campaign.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@
margin: 0px;
li {
border-bottom: 1px solid gray;
&:hover{
.rewards_toolbox{display:block;}
}
.rewards_toolbox{width:80px;height:26px;float:right;margin-top: 10px;display:none;
.toolbox_container{
top:0.5em;right:1em;
list-style-type:none;
float:right;
padding:2px;
a{
display: inline;
padding: 0px 0px;
&:hover {
text-decoration: none;
background: none;
}
}
&:hover {
border :1px solid #eee;
}
.toolbox_item{
float:left;
background-color:#fff;box-shadow:0 0 2px #000;
margin-right:4px;
height:26px;
width:27px;
}
}
}
&:last-child {
border-bottom: none;
a {
Expand Down
3 changes: 3 additions & 0 deletions app/views/theme/views/campaign.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<% @campaign.rewards.order("price ASC").each do |reward| %>
<% if reward.visible? %>
<li id="rewards_click">
<% if [email protected]? && !current_user.nil? && current_user.admin? %>
<div class="rewards_toolbox"><div class="toolbox_container"><div class="toolbox_item"><%= link_to (image_tag '/assets/trash.png'), reward_controller_delete_path(:reward => reward.id), data: { confirm: 'Are you sure?' } %></div></div></div>
<% end %>
<a href="<%= url_for(checkout_amount_path(@campaign, reward: reward.id)) %>" onclick="<%= 'return false' if reward.sold_out? || @campaign.expired? %>" class="<%= 'disabled' if reward.sold_out? || @campaign.expired? %>">
<p class="price">$<%= number_with_precision(reward.price, precision: (reward.price*100%100==0.0 ? 0 : 2)) %></p>
<p class="title"><%= reward.title %></p>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
match '/ajax/verify', to: 'admin#ajax_verify', as: :ajax_verify

# CAMPAIGNS
match '/:id/reward/delete', to: 'campaigns#delete_reward', as: :reward_controller_delete
match '/:id/checkout/amount', to: 'campaigns#checkout_amount', as: :checkout_amount
match '/:id/checkout/payment', to: 'campaigns#checkout_payment', as: :checkout_payment
match '/:id/checkout/process', to: 'campaigns#checkout_process', as: :checkout_process
Expand Down