Commit ee45f9287fd8acfe03d36f3218151d733778caa7
1 parent
efd10d8d
Exists in
master
and in
21 other branches
[media-panel-improvements] Published media folder selection filter
Showing
9 changed files
with
80 additions
and
35 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -329,6 +329,13 @@ class CmsController < MyProfileController |
| 329 | 329 | #render :text => article_list_to_json([file]), :content_type => 'text/plain' |
| 330 | 330 | end |
| 331 | 331 | |
| 332 | + def published_media_items | |
| 333 | + parent = profile.articles.find(params[:parent_id]) | |
| 334 | + load_recent_files(parent) | |
| 335 | + @published_media_items_id = params[:parent_id] | |
| 336 | + render :partial => 'published_media_items' | |
| 337 | + end | |
| 338 | + | |
| 332 | 339 | protected |
| 333 | 340 | |
| 334 | 341 | include CmsHelper |
| ... | ... | @@ -425,14 +432,21 @@ class CmsController < MyProfileController |
| 425 | 432 | {:images => _('Images'), :generics => _('Files')} |
| 426 | 433 | end |
| 427 | 434 | |
| 428 | - def load_recent_files | |
| 435 | + def load_recent_files(parent = nil) | |
| 429 | 436 | #TODO Since we only have special support for images, I'm limiting myself to |
| 430 | 437 | # consider generic files as non-images. In the future, with more supported |
| 431 | 438 | # file types we'll need to have a smart way to fetch from the database |
| 432 | 439 | # scopes of each supported type as well as the non-supported types as a |
| 433 | 440 | # whole. |
| 434 | 441 | @recent_files = {} |
| 435 | - files = profile.files.more_recent | |
| 442 | + if parent.present? | |
| 443 | + files = parent.children.files | |
| 444 | + @published_media_items_id = parent.id | |
| 445 | + else | |
| 446 | + files = profile.files | |
| 447 | + @published_media_items_id = 'recent-media' | |
| 448 | + end | |
| 449 | + files = files.more_recent | |
| 436 | 450 | @recent_files[:images] = files.images.limit(6) |
| 437 | 451 | @recent_files[:generics] = files.no_images.limit(6) |
| 438 | 452 | end | ... | ... |
app/helpers/forms_helper.rb
| ... | ... | @@ -265,7 +265,7 @@ module FormsHelper |
| 265 | 265 | ) |
| 266 | 266 | end |
| 267 | 267 | |
| 268 | - def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {}, find_options = {}) | |
| 268 | + def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {}, find_options = {}, extra_options = {}) | |
| 269 | 269 | if find_options.empty? |
| 270 | 270 | folders = profile.folders |
| 271 | 271 | else |
| ... | ... | @@ -276,7 +276,7 @@ module FormsHelper |
| 276 | 276 | select_tag( |
| 277 | 277 | field_id, |
| 278 | 278 | options_for_select( |
| 279 | - [[profile.identifier, '']] + | |
| 279 | + [[(extra_options[:root_label] || profile.identifier), '']] + | |
| 280 | 280 | folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id.to_s ] }, |
| 281 | 281 | default_value.to_s |
| 282 | 282 | ), | ... | ... |
app/models/article.rb
| ... | ... | @@ -463,6 +463,7 @@ class Article < ActiveRecord::Base |
| 463 | 463 | scope :images, :conditions => { :is_image => true } |
| 464 | 464 | scope :no_images, :conditions => { :is_image => false } |
| 465 | 465 | scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] |
| 466 | + scope :files, :conditions => { :type => 'UploadedFile' } | |
| 466 | 467 | scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } |
| 467 | 468 | |
| 468 | 469 | scope :more_popular, :order => 'hits DESC' | ... | ... |
app/models/profile.rb
| ... | ... | @@ -200,7 +200,6 @@ class Profile < ActiveRecord::Base |
| 200 | 200 | has_many :tasks, :dependent => :destroy, :as => 'target' |
| 201 | 201 | |
| 202 | 202 | has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date' |
| 203 | - has_many :files, :source => 'articles', :class_name => 'UploadedFile', :order => 'start_date' | |
| 204 | 203 | |
| 205 | 204 | def find_in_all_tasks(task_id) |
| 206 | 205 | begin | ... | ... |
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +<div id='<%= @published_media_items_id %>' class='items'> | |
| 2 | + <% file_types.each do |key, header| %> | |
| 3 | + <% display = @recent_files[key].present? ? '' : 'none' %> | |
| 4 | + <div class='<%= key.to_s %>' style='display: <%= display%>;'> | |
| 5 | + <h3><%= header %></h3> | |
| 6 | + <% @recent_files[key].each do |file| %> | |
| 7 | + <% @file = file %> | |
| 8 | + <%= render :partial => "cms/media_panel/#{key.to_s.singularize}" %> | |
| 9 | + <% end %> | |
| 10 | + </div> | |
| 11 | + <% end %> | |
| 12 | +</div> | ... | ... |
app/views/cms/_text_editor_sidebar.html.erb
| ... | ... | @@ -23,20 +23,10 @@ |
| 23 | 23 | |
| 24 | 24 | <div id='published-media' class='text-editor-sidebar-box'> |
| 25 | 25 | <div class='header'><strong><%= _('Published media') %></strong></div> |
| 26 | + <%= select_profile_folder(nil, :parent_id, profile, 'recent-media', {'data-url' => url_for({:controller => 'cms', :action => 'published_media_items', :profile => profile.identifier})}, {}, | |
| 27 | + "type='Folder' or type='Gallery'", {:root_label => _('Recent media')}) %> | |
| 26 | 28 | <%= render :partial => 'drag_and_drop_note' %> |
| 27 | - <div class='items'> | |
| 28 | - <% file_types.each do |key, label| %> | |
| 29 | - <% if @recent_files[key].present? %> | |
| 30 | - <div class='<%= key.to_s%>'> | |
| 31 | - <h3><%= label %></h3> | |
| 32 | - <% @recent_files[key].each do |file| %> | |
| 33 | - <% @file = file %> | |
| 34 | - <%= render :partial => "cms/media_panel/#{key.to_s.singularize}" %> | |
| 35 | - <% end %> | |
| 36 | - </div> | |
| 37 | - <% end %> | |
| 38 | - <% end %> | |
| 39 | - </div> | |
| 29 | + <%= render :partial => 'published_media_items' %> | |
| 40 | 30 | </div> |
| 41 | 31 | |
| 42 | 32 | <div id='media-search-box' class='text-editor-sidebar-box'> |
| ... | ... | @@ -64,4 +54,4 @@ |
| 64 | 54 | </div> |
| 65 | 55 | </script> |
| 66 | 56 | |
| 67 | -<%= javascript_include_tag 'jquery.fileupload.js', 'tmpl.js', 'media-upload.js' %> | |
| 57 | +<%= javascript_include_tag 'jquery.fileupload.js', 'tmpl.js', 'media-panel.js' %> | ... | ... |
app/views/cms/media_upload.js.erb
| 1 | 1 | <% if @file.valid? %> |
| 2 | 2 | <% klass = @file.class.name.split('::').last.to_css_class %> |
| 3 | - jQuery("#published-media .items .<%= klass.pluralize %> h3").after("<%= j render :partial => "cms/media_panel/#{klass}" %>"); | |
| 4 | - jQuery("#published-media .items .<%= klass.pluralize %>").show(); | |
| 3 | + jQuery("#published-media #recent-media .<%= klass.pluralize %> h3").after("<%= j render :partial => "cms/media_panel/#{klass}" %>"); | |
| 4 | + jQuery("#published-media #recent-media .<%= klass.pluralize %>").show(); | |
| 5 | 5 | <% else %> |
| 6 | 6 | alert("Failed to upload file: <%= j @file.errors.full_messages.join(', ').html_safe %>"); |
| 7 | 7 | <% end %> | ... | ... |
| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | +jQuery('#file').fileupload({ | |
| 2 | + add: function(e, data){ | |
| 3 | + data.context = jQuery(tmpl("template-upload", data.files[0])); | |
| 4 | + jQuery('#media-upload-form').append(data.context); | |
| 5 | + data.submit(); | |
| 6 | + }, | |
| 7 | + progress: function (e, data) { | |
| 8 | + if (data.context) { | |
| 9 | + progress = parseInt(data.loaded / data.total * 100, 10); | |
| 10 | + data.context.find('.bar').css('width', progress + '%'); | |
| 11 | + data.context.find('.percentage').text(progress + '%'); | |
| 12 | + } | |
| 13 | + } | |
| 14 | +}); | |
| 15 | + | |
| 16 | +jQuery('#published-media #parent_id').change(function(){ | |
| 17 | + value = jQuery(this).val(); | |
| 18 | + if(value == '') | |
| 19 | + value = 'recent-media' | |
| 20 | + selector = '#published-media #'+value | |
| 21 | + | |
| 22 | + if (jQuery(selector).length > 0){ | |
| 23 | + jQuery('#published-media .items').hide(); | |
| 24 | + jQuery(selector).show(); | |
| 25 | + } else { | |
| 26 | + jQuery('#published-media').addClass('fetching'); | |
| 27 | + url = jQuery(this).data('url'); | |
| 28 | + jQuery.ajax({ | |
| 29 | + url: url, | |
| 30 | + data: {"parent_id":value}, | |
| 31 | + dataType: 'html', | |
| 32 | + success: function(response) { | |
| 33 | + jQuery('#published-media .items').hide(); | |
| 34 | + jQuery("#published-media").append('<div id="'+ value +'" class="items">' + response + '</div>'); | |
| 35 | + jQuery('#published-media').removeClass('fetching'); | |
| 36 | + }, | |
| 37 | + error: function(response, textStatus, xhr) { | |
| 38 | + console.log(response); | |
| 39 | + console.log(textStatus); | |
| 40 | + } | |
| 41 | + }); | |
| 42 | + } | |
| 43 | +}); | ... | ... |
public/javascripts/media-upload.js
| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | -jQuery('#file').fileupload({ | |
| 2 | - add: function(e, data){ | |
| 3 | - data.context = jQuery(tmpl("template-upload", data.files[0])); | |
| 4 | - jQuery('#media-upload-form').append(data.context); | |
| 5 | - data.submit(); | |
| 6 | - }, | |
| 7 | - progress: function (e, data) { | |
| 8 | - if (data.context) { | |
| 9 | - progress = parseInt(data.loaded / data.total * 100, 10); | |
| 10 | - data.context.find('.bar').css('width', progress + '%'); | |
| 11 | - data.context.find('.percentage').text(progress + '%'); | |
| 12 | - } | |
| 13 | - } | |
| 14 | -}); |