diff --git a/.gitignore b/.gitignore index 28e4cac..f77f9ce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ config/database.yml db/test.sqlite schema/*.sql -public/advertisements \ No newline at end of file +public/advertisements +coverage \ No newline at end of file diff --git a/TODO.markdown b/TODO.markdown index 626b5c5..c0d5283 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -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 @@ -13,4 +12,5 @@ ## Version 1.1 +* Estimate impression per campaign / spot / site based on historical data * Add in calendar-based saturation views \ No newline at end of file diff --git a/app/controllers/campaigns.rb b/app/controllers/campaigns.rb index 3d09602..9a76aa2 100644 --- a/app/controllers/campaigns.rb +++ b/app/controllers/campaigns.rb @@ -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 diff --git a/app/controllers/sites.rb b/app/controllers/sites.rb index 477ddf1..ae6333f 100644 --- a/app/controllers/sites.rb +++ b/app/controllers/sites.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/global_helpers.rb b/app/helpers/global_helpers.rb index 4d01b31..cc8bb21 100644 --- a/app/helpers/global_helpers.rb +++ b/app/helpers/global_helpers.rb @@ -24,5 +24,9 @@ def format_for_javascript(body) body.gsub(/\'/, "'").gsub(/\n/, "") end + def destroy_button(url, text) + "
" + end + end end diff --git a/app/models/campaign.rb b/app/models/campaign.rb index 318a54a..68324d6 100644 --- a/app/models/campaign.rb +++ b/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 diff --git a/app/models/site.rb b/app/models/site.rb index e7f71a9..ad0a0a3 100644 --- a/app/models/site.rb +++ b/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 diff --git a/app/models/spot.rb b/app/models/spot.rb index ff9547d..621a667 100644 --- a/app/models/spot.rb +++ b/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 diff --git a/app/views/campaigns/edit.html.erb b/app/views/campaigns/edit.html.erb index 8d4b9b5..c1fb45f 100644 --- a/app/views/campaigns/edit.html.erb +++ b/app/views/campaigns/edit.html.erb @@ -5,6 +5,9 @@

Edit details

<%= error_messages_for @campaign %> <%= partial :form %> -
<%= submit_button "Save" %>
+
+ <%= submit_button "Save" %> +
-<% end %> \ No newline at end of file +<% end %> +<%= destroy_button url(:action => "destroy", :id => @campaign.id), "Remove this campaign" %> \ No newline at end of file diff --git a/app/views/sites/edit.html.erb b/app/views/sites/edit.html.erb index e19fac3..99eed4e 100644 --- a/app/views/sites/edit.html.erb +++ b/app/views/sites/edit.html.erb @@ -15,6 +15,7 @@
<%= submit_button "Edit site details" %>
<% end %> +<%= destroy_button url(:action => "destroy", :id => @site.id), "Remove this site" %>

Site Spots

<% if @site.spots.empty? %> @@ -27,6 +28,7 @@

<%= spot.campaigns.count %> / <%= spot.campaign_limit %> campaigns filled

Show Code

+ <%= destroy_button url(:action => "destroy_spot", :id => spot.id), "Remove" %> <% end %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a1d674d..ac41f4c 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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?") + } } } diff --git a/public/stylesheets/master.css b/public/stylesheets/master.css index 10b395f..b78c425 100644 --- a/public/stylesheets/master.css +++ b/public/stylesheets/master.css @@ -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; @@ -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; @@ -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; } \ No newline at end of file