diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index a1dbeae..d439479 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -17,6 +17,9 @@ class CmsController < MyProfileController end before_filter :login_required, :except => [:suggest_an_article] + before_filter :load_recent_files, :only => [:new, :edit] + + helper_method :file_types protect_if :only => :upload_files do |c, user, profile| article_id = c.params[:parent_id] @@ -418,4 +421,20 @@ class CmsController < MyProfileController end end + def file_types + {:images => _('Images'), :generics => _('Files')} + end + + def load_recent_files + #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 + @recent_files[:images] = files.images.limit(6) + @recent_files[:generics] = files.no_images.limit(6) + end + end diff --git a/app/models/article.rb b/app/models/article.rb index c44af59..4df59b2 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -461,6 +461,7 @@ class Article < ActiveRecord::Base scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}} scope :galleries, :conditions => { :type => 'Gallery' } scope :images, :conditions => { :is_image => true } + scope :no_images, :conditions => { :is_image => false } scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } diff --git a/app/models/profile.rb b/app/models/profile.rb index 1506d8d..26e7a1e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -200,6 +200,7 @@ 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/_text_editor_sidebar.html.erb b/app/views/cms/_text_editor_sidebar.html.erb index edb3499..8f81070 100644 --- a/app/views/cms/_text_editor_sidebar.html.erb +++ b/app/views/cms/_text_editor_sidebar.html.erb @@ -25,12 +25,17 @@