Skip to content

Commit

Permalink
Removing of sites, spots and campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
kneath committed Apr 28, 2008
1 parent c73f6be commit 4495de0
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,5 @@
config/database.yml
db/test.sqlite
schema/*.sql
public/advertisements
public/advertisements
coverage
2 changes: 1 addition & 1 deletion TODO.markdown
Expand Up @@ -3,7 +3,6 @@
* Track clicks to ads
* Build out dashboard page
* Support default campaigns
* Remove campaigns / spots / sites
* List out inactive / default campaigns

## Version 1.0
Expand All @@ -13,4 +12,5 @@

## Version 1.1

* Estimate impression per campaign / spot / site based on historical data
* Add in calendar-based saturation views
8 changes: 8 additions & 0 deletions app/controllers/campaigns.rb
Expand Up @@ -34,4 +34,12 @@ def edit
render
end

def destroy
if request.method == :post
@campaign = Campaign.find(params[:id])
@campaign.destroy
end
redirect url(:action => "show", :site_id => @campaign.spot.site.id)
end

end
16 changes: 16 additions & 0 deletions app/controllers/sites.rb
Expand Up @@ -22,4 +22,20 @@ def edit
render
end

def destroy
@site = Site.find(params[:id])
if request.method == :post
@site.destroy
end
redirect url(:action => "index")
end

def destroy_spot
@spot = Spot.find(params[:id])
if request.method == :post
@spot.destroy
end
redirect url(:action => "edit", :id => @spot.site.id)
end

end
4 changes: 4 additions & 0 deletions app/helpers/global_helpers.rb
Expand Up @@ -24,5 +24,9 @@ def format_for_javascript(body)
body.gsub(/\'/, "'").gsub(/\n/, "")
end

def destroy_button(url, text)
"<form action=\"#{url}\" method=\"post\" class=\"destroy\"><button type=\"submit\" class=\"destroy\">#{text}</button></form>"
end

end
end
2 changes: 1 addition & 1 deletion app/models/campaign.rb
@@ -1,7 +1,7 @@
class Campaign < ActiveRecord::Base

belongs_to :spot
has_many :impressions
has_many :impressions, :dependent => :destroy

validates_presence_of :name, :starts_on, :ends_on, :spot_id

Expand Down
2 changes: 1 addition & 1 deletion app/models/site.rb
@@ -1,6 +1,6 @@
class Site < ActiveRecord::Base

has_many :spots
has_many :spots, :dependent => :destroy

validates_presence_of :name, :url
validates_uniqueness_of :url
Expand Down
2 changes: 1 addition & 1 deletion app/models/spot.rb
@@ -1,7 +1,7 @@
class Spot < ActiveRecord::Base

belongs_to :site
has_many :campaigns
has_many :campaigns, :dependent => :destroy
has_many :active_campaigns, :class_name => "Campaign", :conditions => ["starts_on < ? AND ends_on > ? AND active = ?", Time.now.to_formatted_s(:db), Time.now.to_formatted_s(:db), true]

validates_presence_of :name
Expand Down
7 changes: 5 additions & 2 deletions app/views/campaigns/edit.html.erb
Expand Up @@ -5,6 +5,9 @@
<h2>Edit details</h2>
<%= error_messages_for @campaign %>
<%= partial :form %>
<div class="actions"><%= submit_button "Save" %></div>
<div class="actions">
<%= submit_button "Save" %>
</div>
</div>
<% end %>
<% end %>
<%= destroy_button url(:action => "destroy", :id => @campaign.id), "Remove this campaign" %>
2 changes: 2 additions & 0 deletions app/views/sites/edit.html.erb
Expand Up @@ -15,6 +15,7 @@
<div class="actions"><%= submit_button "Edit site details" %></div>
<% end %>
</div>
<%= destroy_button url(:action => "destroy", :id => @site.id), "Remove this site" %>

<h2>Site Spots</h2>
<% if @site.spots.empty? %>
Expand All @@ -27,6 +28,7 @@
<p class="meta"><%= spot.campaigns.count %> / <%= spot.campaign_limit %> campaigns filled</p>
<p class="action"><a href="#" class="codetoggler" toggle="code-<%= spot.id %>">Show Code</a></p>
<textarea id="code-<%= spot.id %>" class="code-insertion"><%= partial :insertion_code, :spot => spot %></textarea>
<%= destroy_button url(:action => "destroy_spot", :id => spot.id), "Remove" %>
</li>
<% end %>
</ul>
Expand Down
6 changes: 6 additions & 0 deletions public/javascripts/application.js
Expand Up @@ -53,6 +53,12 @@ var rules = {
}
(new Event(e)).stop();
});
},

'form.destroy': function(element){
element.onsubmit = function(){
return confirm("Are you sure you want to remove this item?")
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions public/stylesheets/master.css
Expand Up @@ -214,6 +214,18 @@ input[type=submit], button[type=submit]{
input[type=submit]:hover, button[type=submit]:hover{
background-color:#333;
}
button.destroy{
position:relative;
top:-48px;
left:10px;
background-color:#cc0000;
}
button.destroy:hover{
background-color:#990000;
}
html>body*#wrap button.destroy{
top:-45px;
}

p.dateresults{
margin-left:-20px;
Expand Down Expand Up @@ -296,6 +308,7 @@ ul.full-width-spots{
margin-left:0;
}
ul.spots li{
position:relative;
list-style-type:none;
float:left;
margin:0 0 10px 10px;
Expand Down Expand Up @@ -329,4 +342,21 @@ ul.full-width-spots li{
.spots p.action{
margin:-22px 0 0 0;
float:right;
}

.spots button.destroy{
position:absolute;
top:10px;
right:10px;
left:auto;
font-size:10px;
padding:2px 5px;
opacity:0.5;
background-color:#333;
}
.spots button.destroy:hover{
opacity:1;
}
html>body*#wrap button.destroy{
top:10px;
}

0 comments on commit 4495de0

Please sign in to comment.