diff --git a/app/controllers/contents_controller.rb b/app/controllers/contents_controller.rb index a31e50d64..f8b5442cb 100644 --- a/app/controllers/contents_controller.rb +++ b/app/controllers/contents_controller.rb @@ -25,6 +25,8 @@ def show # GET /contents/new.xml def new @content = Content.new + @feeds = Feed.all + @content.submissions.build respond_to do |format| format.html # new.html.erb @@ -41,6 +43,13 @@ def edit # POST /contents.xml def create @content = Content.new(params[:content]) + + # Copy over the duration to each submission instance + # This would be a good place to add code to auto-moderate content + # for feed owners or something like that + @content.submissions.each do |submission| + submission.duration = @content.duration + end respond_to do |format| if @content.save diff --git a/app/models/content.rb b/app/models/content.rb index 6aa4e5594..7caa59a19 100644 --- a/app/models/content.rb +++ b/app/models/content.rb @@ -1,8 +1,10 @@ class Content < ActiveRecord::Base belongs_to :user belongs_to :type - has_many :submissions + has_many :submissions, :dependent => :destroy has_many :feeds, :through => :submissions + + accepts_nested_attributes_for :submissions #Validations validates :name, :presence => true @@ -16,6 +18,11 @@ class Content < ActiveRecord::Base scope :expired, where("end_time < :now", {:now => Time.now}) scope :future, where("start_time > :now", {:now => Time.now}) scope :active, where("(start_time IS NULL OR start_time < :now) AND (end_time IS NULL OR end_time > :now)", {:now => Time.now}) + + #Scoped relations for feed approval states + has_many :approved_feeds, :through => :submissions, :source => :feed, :conditions => {"submissions.moderation_flag" => true} + has_many :pending_feeds, :through => :submissions, :source => :feed, :conditions => "submissions.moderation_flag IS NULL" + has_many :denied_feeds, :through => :submissions, :source => :feed, :conditions => {"submissions.moderation_flag" => false} #Determine if content is active based on its start and end times. def is_active? diff --git a/app/models/submission.rb b/app/models/submission.rb index 2881b1688..fb4698b69 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -2,4 +2,7 @@ class Submission < ActiveRecord::Base belongs_to :content belongs_to :feed belongs_to :user + + #Validations + validates_associated :feed, :content end diff --git a/app/views/contents/_form.html.erb b/app/views/contents/_form.html.erb index ddd20397b..77cae51a2 100644 --- a/app/views/contents/_form.html.erb +++ b/app/views/contents/_form.html.erb @@ -33,6 +33,16 @@ <%= f.label :type %>
<%#= f.text_field :type %> + <% if @content.new_record? %> +
+ <% @feeds.each do |feed| %> + <% f.fields_for :submissions do |submissions| %> + <%= submissions.check_box :feed_id, {}, feed.id %> + <%= feed.name %>
+ <% end %> + <% end %> +
+ <% end %>
<%= f.submit %>
diff --git a/app/views/contents/show.html.erb b/app/views/contents/show.html.erb index 0a799b18e..350ceb295 100644 --- a/app/views/contents/show.html.erb +++ b/app/views/contents/show.html.erb @@ -38,6 +38,33 @@ <%= @content.type unless @content.user.nil? %>

+

+ Approved Feeds: +

+

+ +

+ Pending Feeds: +

+

+ +

+ Denied Feeds: +

+

+ <%= link_to 'Edit', edit_content_path(@content) %> | <%= link_to 'Back', contents_path %> diff --git a/app/views/feeds/show.html.erb b/app/views/feeds/show.html.erb index ffaafd123..1e79cfef0 100644 --- a/app/views/feeds/show.html.erb +++ b/app/views/feeds/show.html.erb @@ -18,6 +18,30 @@ <%= @feed.group %>

+

+ Approved Content: +

+

+

+ Denied Content: +

+

+

+ Pending Content: +

+

<%= link_to 'Edit', edit_feed_path(@feed) %> | <%= link_to 'Back', feeds_path %>