diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index d439479..8f3cb60 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -329,6 +329,13 @@ class CmsController < MyProfileController #render :text => article_list_to_json([file]), :content_type => 'text/plain' end + def published_media_items + parent = profile.articles.find(params[:parent_id]) + load_recent_files(parent) + @published_media_items_id = params[:parent_id] + render :partial => 'published_media_items' + end + protected include CmsHelper @@ -425,14 +432,21 @@ class CmsController < MyProfileController {:images => _('Images'), :generics => _('Files')} end - def load_recent_files + def load_recent_files(parent = nil) #TODO Since we only have special support for images, I'm limiting myself to # consider generic files as non-images. In the future, with more supported # file types we'll need to have a smart way to fetch from the database # scopes of each supported type as well as the non-supported types as a # whole. @recent_files = {} - files = profile.files.more_recent + if parent.present? + files = parent.children.files + @published_media_items_id = parent.id + else + files = profile.files + @published_media_items_id = 'recent-media' + end + files = files.more_recent @recent_files[:images] = files.images.limit(6) @recent_files[:generics] = files.no_images.limit(6) end diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index 44f3626..93f358e 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -265,7 +265,7 @@ module FormsHelper ) end - def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {}, find_options = {}) + def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {}, find_options = {}, extra_options = {}) if find_options.empty? folders = profile.folders else @@ -276,7 +276,7 @@ module FormsHelper select_tag( field_id, options_for_select( - [[profile.identifier, '']] + + [[(extra_options[:root_label] || profile.identifier), '']] + folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id.to_s ] }, default_value.to_s ), diff --git a/app/models/article.rb b/app/models/article.rb index 4df59b2..5efb766 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -463,6 +463,7 @@ class Article < ActiveRecord::Base scope :images, :conditions => { :is_image => true } scope :no_images, :conditions => { :is_image => false } scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] + scope :files, :conditions => { :type => 'UploadedFile' } scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } scope :more_popular, :order => 'hits DESC' diff --git a/app/models/profile.rb b/app/models/profile.rb index 26e7a1e..1506d8d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -200,7 +200,6 @@ class Profile < ActiveRecord::Base has_many :tasks, :dependent => :destroy, :as => 'target' has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date' - has_many :files, :source => 'articles', :class_name => 'UploadedFile', :order => 'start_date' def find_in_all_tasks(task_id) begin diff --git a/app/views/cms/_published_media_items.html.erb b/app/views/cms/_published_media_items.html.erb new file mode 100644 index 0000000..abddc44 --- /dev/null +++ b/app/views/cms/_published_media_items.html.erb @@ -0,0 +1,12 @@ +