diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 8f3cb60..403dc52 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -330,9 +330,7 @@ class CmsController < MyProfileController end def published_media_items - parent = profile.articles.find(params[:parent_id]) - load_recent_files(parent) - @published_media_items_id = params[:parent_id] + load_recent_files(params[:parent_id], params[:q]) render :partial => 'published_media_items' end @@ -432,23 +430,32 @@ class CmsController < MyProfileController {:images => _('Images'), :generics => _('Files')} end - def load_recent_files(parent = nil) + def load_recent_files(parent_id = nil, q = 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 = {} + + parent = parent_id.present? ? profile.articles.find(parent_id) : nil 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) + images = files.images.limit(6) + generics = files.no_images.limit(6) + + if q.present? + @recent_files[:images] = find_by_contents(:images, images, q)[:results] + @recent_files[:generics] = find_by_contents(:generics, generics, q)[:results] + else + @recent_files[:images] = images + @recent_files[:generics] = generics + end end end diff --git a/app/views/cms/_published_media_items.html.erb b/app/views/cms/_published_media_items.html.erb index abddc44..7a32ac3 100644 --- a/app/views/cms/_published_media_items.html.erb +++ b/app/views/cms/_published_media_items.html.erb @@ -1,4 +1,4 @@ -
+
<% file_types.each do |key, header| %> <% display = @recent_files[key].present? ? '' : 'none' %>
diff --git a/app/views/cms/_text_editor_sidebar.html.erb b/app/views/cms/_text_editor_sidebar.html.erb index ff65ab9..02f1864 100644 --- a/app/views/cms/_text_editor_sidebar.html.erb +++ b/app/views/cms/_text_editor_sidebar.html.erb @@ -1,8 +1,4 @@
- '> - '> - '> - <%= render(:partial => 'textile_quick_reference') if @article.is_a?(TextileArticle) %>
<%= _('Insert media') %>
@@ -21,30 +17,14 @@
-
+
'published_media_items', :profile => profile.identifier}) %>'>
<%= _('Published media') %>
- <%= select_profile_folder(nil, :parent_id, profile, 'recent-media', {'data-url' => url_for({:controller => 'cms', :action => 'published_media_items', :profile => profile.identifier})}, {}, + <%= select_profile_folder(nil, :parent_id, profile, 'recent-media', {}, {}, "type='Folder' or type='Gallery'", {:root_label => _('Recent media')}) %> + <%= labelled_form_field _('Search'), text_field_tag('q') %> <%= render :partial => 'drag_and_drop_note' %> <%= render :partial => 'published_media_items' %>
- -