Commit 580afdd731e1b392e145e7878fec549406c4cde4

Authored by Rodrigo Souto
1 parent 3db199c7

[media-panel-improvements] View all

app/controllers/my_profile/cms_controller.rb
@@ -334,6 +334,12 @@ class CmsController < MyProfileController @@ -334,6 +334,12 @@ class CmsController < MyProfileController
334 render :partial => 'published_media_items' 334 render :partial => 'published_media_items'
335 end 335 end
336 336
  337 + def view_all_media
  338 + paginate_options = {:page => 1}
  339 + @key = params[:key].to_sym
  340 + load_recent_files(params[:parent_id], params[:q], paginate_options)
  341 + end
  342 +
337 protected 343 protected
338 344
339 include CmsHelper 345 include CmsHelper
@@ -430,7 +436,7 @@ class CmsController < MyProfileController @@ -430,7 +436,7 @@ class CmsController < MyProfileController
430 {:images => _('Images'), :generics => _('Files')} 436 {:images => _('Images'), :generics => _('Files')}
431 end 437 end
432 438
433 - def load_recent_files(parent_id = nil, q = nil) 439 + def load_recent_files(parent_id = nil, q = nil, paginate_options = {:page => 1, :per_page => 6})
434 #TODO Since we only have special support for images, I'm limiting myself to 440 #TODO Since we only have special support for images, I'm limiting myself to
435 # consider generic files as non-images. In the future, with more supported 441 # consider generic files as non-images. In the future, with more supported
436 # file types we'll need to have a smart way to fetch from the database 442 # file types we'll need to have a smart way to fetch from the database
@@ -446,15 +452,15 @@ class CmsController < MyProfileController @@ -446,15 +452,15 @@ class CmsController < MyProfileController
446 end 452 end
447 453
448 files = files.more_recent 454 files = files.more_recent
449 - images = files.images.limit(6)  
450 - generics = files.no_images.limit(6) 455 + images = files.images
  456 + generics = files.no_images
451 457
452 if q.present? 458 if q.present?
453 - @recent_files[:images] = find_by_contents(:images, images, q)[:results]  
454 - @recent_files[:generics] = find_by_contents(:generics, generics, q)[:results] 459 + @recent_files[:images] = find_by_contents(:images, images, q, paginate_options)[:results]
  460 + @recent_files[:generics] = find_by_contents(:generics, generics, q, paginate_options)[:results]
455 else 461 else
456 - @recent_files[:images] = images  
457 - @recent_files[:generics] = generics 462 + @recent_files[:images] = images.paginate(paginate_options)
  463 + @recent_files[:generics] = generics.paginate(paginate_options)
458 end 464 end
459 end 465 end
460 466
app/views/cms/_published_media_items.html.erb
1 -<div 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%>;'> 1 +<% file_types.each do |key, header| %>
  2 + <% display = @recent_files[key].present? ? '' : 'none' %>
  3 + <div class='<%= key.to_s %>' style='display: <%= display%>;'>
  4 + <div class='section-title'>
5 <h3><%= header %></h3> 5 <h3><%= header %></h3>
6 - <% @recent_files[key].each do |file| %>  
7 - <% @file = file %>  
8 - <%= render :partial => "cms/media_panel/#{key.to_s.singularize}" %> 6 + <% if @recent_files[key].total_pages > 1 %>
  7 + <%= link_to(_('View all'), {:controller => 'cms', :action => 'view_all_media', :profile => profile.identifier, :key => key}, :class => 'view-all colorbox', 'data-key' => key) %>
9 <% end %> 8 <% end %>
10 </div> 9 </div>
11 - <% end %>  
12 -</div> 10 + <% @recent_files[key].each do |file| %>
  11 + <% @file = file %>
  12 + <%= render :partial => "cms/media_panel/#{key.to_s.singularize}" %>
  13 + <% end %>
  14 + </div>
  15 +<% end %>
app/views/cms/_text_editor_sidebar.html.erb
@@ -23,7 +23,9 @@ @@ -23,7 +23,9 @@
23 "type='Folder' or type='Gallery'", {:root_label => _('Recent media')}) %> 23 "type='Folder' or type='Gallery'", {:root_label => _('Recent media')}) %>
24 <%= labelled_form_field _('Search'), text_field_tag('q') %> 24 <%= labelled_form_field _('Search'), text_field_tag('q') %>
25 <%= render :partial => 'drag_and_drop_note' %> 25 <%= render :partial => 'drag_and_drop_note' %>
26 - <%= render :partial => 'published_media_items' %> 26 + <div class='items'>
  27 + <%= render :partial => 'published_media_items' %>
  28 + </div>
27 </div> 29 </div>
28 </div> 30 </div>
29 31
app/views/cms/media_panel/_generic.html.erb
1 <div class="item file <%= icon_for_article(@file) %>" data-item="div"> 1 <div class="item file <%= icon_for_article(@file) %>" data-item="div">
2 <div> 2 <div>
3 - <a class="add-to-text" href="<%= url_for(@file.url) %>"><%= @file.title %></a> 3 + <a class="add-to-text" href="<%= url_for(@file.url) %>" title="<%= @file.title %>"><%= @file.title %></a>
4 </div> 4 </div>
5 </div> 5 </div>
app/views/cms/media_panel/_image.html.erb
1 -<div class="item image" data-item="span"> 1 +<div class="item image" data-item="span" title="<%= @file.name %>">
2 <span> 2 <span>
3 <img src="<%= @file.public_filename(:uploaded) %>"/> 3 <img src="<%= @file.public_filename(:uploaded) %>"/>
4 </span> 4 </span>
app/views/cms/media_upload.js.erb
1 <% if @file.valid? %> 1 <% if @file.valid? %>
2 <% klass = @file.class.name.split('::').last.to_css_class %> 2 <% klass = @file.class.name.split('::').last.to_css_class %>
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(); 3 + jQuery("#published-media .items .<%= klass.pluralize %> .section-title").after("<%= j render :partial => "cms/media_panel/#{klass}" %>");
  4 + jQuery("#published-media .items .<%= klass.pluralize %>").show();
5 <% else %> 5 <% else %>
6 alert("Failed to upload file: <%= j @file.errors.full_messages.join(', ').html_safe %>"); 6 alert("Failed to upload file: <%= j @file.errors.full_messages.join(', ').html_safe %>");
7 <% end %> 7 <% end %>
app/views/cms/view_all_media.html.erb 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +<h1><%= file_types[@key] %></h1>
  2 +
  3 +<div class='view-all-media view-all-<%= @key %>'>
  4 + <% @recent_files[@key].each do |file| %>
  5 + <% @file = file %>
  6 + <%= render :partial => "cms/media_panel/#{@key.to_s.singularize}" %>
  7 + <% end %>
  8 +</div>
public/javascripts/article.js
@@ -79,6 +79,11 @@ jQuery(function($) { @@ -79,6 +79,11 @@ jQuery(function($) {
79 return '<div class="item" data-item="div"><div><img src="' + img + '" style="max-width: 640px; max-height: 480px"/></div>' + '<div class="button-bar">' + add_to_text_button('with-text') + '&nbsp;&nbsp;&nbsp;' + close_button('with-text') + '</div></div>' 79 return '<div class="item" data-item="div"><div><img src="' + img + '" style="max-width: 640px; max-height: 480px"/></div>' + '<div class="button-bar">' + add_to_text_button('with-text') + '&nbsp;&nbsp;&nbsp;' + close_button('with-text') + '</div></div>'
80 } 80 }
81 81
  82 + $('.view-all-images .item').live('click', function(){
  83 + insert_item_in_text(jQuery(this).find('span'));
  84 + $.colorbox.close();
  85 + });
  86 +
82 $('a.add-to-text').live('click', function() { 87 $('a.add-to-text').live('click', function() {
83 var $item = $(this).closest('.item'); 88 var $item = $(this).closest('.item');
84 var html_selector = $item.attr('data-item'); 89 var html_selector = $item.attr('data-item');
public/javascripts/media-panel.js
@@ -26,6 +26,7 @@ function loadPublishedMedia() { @@ -26,6 +26,7 @@ function loadPublishedMedia() {
26 success: function(response) { 26 success: function(response) {
27 jQuery("#published-media .items").html(response); 27 jQuery("#published-media .items").html(response);
28 jQuery('#published-media').removeClass('fetching'); 28 jQuery('#published-media').removeClass('fetching');
  29 + updateViewAllLinks();
29 }, 30 },
30 error: function(response, textStatus, xhr) { 31 error: function(response, textStatus, xhr) {
31 console.log(response); 32 console.log(response);
@@ -34,6 +35,18 @@ function loadPublishedMedia() { @@ -34,6 +35,18 @@ function loadPublishedMedia() {
34 }); 35 });
35 } 36 }
36 37
  38 +function updateViewAllLinks() {
  39 + var parent_id = jQuery('#published-media #parent_id').val();
  40 + var q = jQuery('#published-media #q').val();
  41 + jQuery('#published-media .view-all').each(function(){
  42 + var key = jQuery(this).data('key');
  43 + var params = {parent_id: parent_id, q: q, key: key}
  44 + var href = jQuery(this).attr('href');
  45 + href = href.replace(/\?.*/, '?'+jQuery.param(params));
  46 + jQuery(this).attr('href', href);
  47 + });
  48 +}
  49 +
37 jQuery('#published-media #parent_id').change(function(){ loadPublishedMedia() }); 50 jQuery('#published-media #parent_id').change(function(){ loadPublishedMedia() });
38 51
39 jQuery("#published-media #q").typeWatch({ 52 jQuery("#published-media #q").typeWatch({
public/stylesheets/application.css
@@ -3415,7 +3415,7 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] { @@ -3415,7 +3415,7 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] {
3415 .text-editor-sidebar-box { 3415 .text-editor-sidebar-box {
3416 background: #fcfcf9; 3416 background: #fcfcf9;
3417 border: 1px solid #d3d7cf; 3417 border: 1px solid #d3d7cf;
3418 - padding: 10px 10px 0px 10px; 3418 + padding: 10px;
3419 margin-bottom: 10px; 3419 margin-bottom: 10px;
3420 } 3420 }
3421 3421
@@ -3441,11 +3441,53 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] { @@ -3441,11 +3441,53 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] {
3441 margin-bottom: 10px; 3441 margin-bottom: 10px;
3442 } 3442 }
3443 3443
3444 -.text-editor-sidebar .items .file { 3444 +.text-editor-sidebar .image,
  3445 +.view-all-media .image {
  3446 + display: inline-block;
  3447 + vertical-align: top;
  3448 + text-align: center;
  3449 + position: relative;
  3450 +}
  3451 +
  3452 +.text-editor-sidebar .image {
  3453 + width: 80px;
  3454 + margin: 2px;
  3455 + height: 80px;
  3456 + line-height: 80px;
  3457 +}
  3458 +
  3459 +.view-all-media .image {
  3460 + width: 150px;
  3461 + margin: 3px;
  3462 + height: 125px;
  3463 + line-height: 125px;
  3464 +}
  3465 +
  3466 +.view-all-images .image:hover {
  3467 + cursor: pointer;
  3468 + background-color: #EEE;
  3469 +}
  3470 +
  3471 +.text-editor-sidebar img,
  3472 +.view-all-media img {
  3473 + vertical-align: middle;
  3474 + max-height: 100%;
  3475 + max-width: 100%;
  3476 +}
  3477 +
  3478 +.view-all-images {
  3479 + text-align: center;
  3480 +}
  3481 +
  3482 +.text-editor-sidebar .file,
  3483 +.view-all-media .file {
3445 background-repeat: no-repeat; 3484 background-repeat: no-repeat;
3446 background-position: 0px 0px; 3485 background-position: 0px 0px;
3447 border: none; 3486 border: none;
3448 margin-bottom: 12px; 3487 margin-bottom: 12px;
  3488 + padding-left: 20px;
  3489 + overflow: hidden;
  3490 + text-align: left;
3449 } 3491 }
3450 3492
3451 .text-editor-sidebar select, 3493 .text-editor-sidebar select,
@@ -3453,37 +3495,36 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] { @@ -3453,37 +3495,36 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] {
3453 width: 100%; 3495 width: 100%;
3454 } 3496 }
3455 3497
3456 -.text-editor-sidebar .items .image {  
3457 - display: inline-block;  
3458 - vertical-align: middle;  
3459 - margin: 5px;  
3460 - position: relative;  
3461 -}  
3462 -  
3463 -.text-editor-sidebar .items .file {  
3464 - padding-left: 20px;  
3465 -}  
3466 -  
3467 -.text-editor-sidebar .items :hover { 3498 +.text-editor-sidebar .items :hover,
  3499 +.view-all-media :hover {
3468 background-color: transparent; 3500 background-color: transparent;
3469 } 3501 }
3470 3502
3471 -.text-editor-sidebar .items .image-controls { 3503 +.text-editor-sidebar .items .image-controls,
  3504 +.view-all-media .image-controls {
3472 display: none; 3505 display: none;
3473 position: absolute; 3506 position: absolute;
3474 top: 5px; 3507 top: 5px;
3475 left: 5px; 3508 left: 5px;
  3509 + line-height: 16px;
3476 } 3510 }
3477 3511
3478 -.text-editor-sidebar .items .item:hover .image-controls { 3512 +.text-editor-sidebar .items .item:hover .image-controls,
  3513 +.view-all-media .item:hover .image-controls {
3479 display: block; 3514 display: block;
3480 } 3515 }
3481 3516
3482 -.text-editor-sidebar .items .file-controls { 3517 +.view-all-images .item:hover .image-controls {
  3518 + display: none;
  3519 +}
  3520 +
  3521 +.text-editor-sidebar .items .file-controls,
  3522 +.view-all-media .file-controls {
3483 margin-top: 5px; 3523 margin-top: 5px;
3484 } 3524 }
3485 3525
3486 -.text-editor-sidebar .items .image-controls .icon-zoom { 3526 +.text-editor-sidebar .items .image-controls .icon-zoom,
  3527 +.view-all-media .image-controls .icon-zoom {
3487 background-image: url(../images/zoom-dark.png); 3528 background-image: url(../images/zoom-dark.png);
3488 display: block; 3529 display: block;
3489 width: 0px; 3530 width: 0px;
@@ -3494,10 +3535,6 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] { @@ -3494,10 +3535,6 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] {
3494 background-repeat: no-repeat; 3535 background-repeat: no-repeat;
3495 background-position: 98% 10px; 3536 background-position: 98% 10px;
3496 } 3537 }
3497 -.text-editor-sidebar img {  
3498 - max-height: 70px;  
3499 - max-width: 74px;  
3500 -}  
3501 .text-editor-sidebar .media-upload-error { 3538 .text-editor-sidebar .media-upload-error {
3502 color: red; 3539 color: red;
3503 } 3540 }
@@ -3505,6 +3542,29 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] { @@ -3505,6 +3542,29 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] {
3505 max-width: 355px; 3542 max-width: 355px;
3506 } 3543 }
3507 3544
  3545 +.view-all-media {
  3546 + max-width: 830px;
  3547 + max-height: 600px;
  3548 +}
  3549 +
  3550 +.view-all-media a.button {
  3551 + background-color: #EEE;
  3552 +}
  3553 +
  3554 +#published-media .section-title {
  3555 + width: 100%;
  3556 + height: 40px;
  3557 +}
  3558 +
  3559 +#published-media .section-title h3 {
  3560 + float: left;
  3561 +}
  3562 +
  3563 +#published-media .section-title a.view-all {
  3564 + float: right;
  3565 + line-height: 40px
  3566 +}
  3567 +
3508 /* ==> public/stylesheets/controller_contact.css <== */ 3568 /* ==> public/stylesheets/controller_contact.css <== */
3509 /*** SELECT CITY ***/ 3569 /*** SELECT CITY ***/
3510 3570