Commit 89a324883b058f0ac21b2f00769f6e834d4269d6
Committed by
Antonio Terceiro
1 parent
dcebd712
Exists in
master
and in
28 other branches
ActionItem928: adding list of media when editing with tinymce
* added an iframe to list media * display images and documents to insert in editor * added a partial to upload files * added pagination for images and documents * adding scroll on the left and javascript to scroll down * listing folders with full_name
Showing
16 changed files
with
519 additions
and
37 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -59,7 +59,9 @@ class CmsController < MyProfileController | @@ -59,7 +59,9 @@ class CmsController < MyProfileController | ||
59 | def edit | 59 | def edit |
60 | @article = profile.articles.find(params[:id]) | 60 | @article = profile.articles.find(params[:id]) |
61 | @parent_id = params[:parent_id] | 61 | @parent_id = params[:parent_id] |
62 | - @type = params[:type] | 62 | + @type = params[:type] || @article.class.to_s |
63 | + | ||
64 | + refuse_blocks | ||
63 | if !@article.nil? && @article.blog? || !@type.nil? && @type == 'Blog' | 65 | if !@article.nil? && @article.blog? || !@type.nil? && @type == 'Blog' |
64 | @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier) | 66 | @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier) |
65 | end | 67 | end |
@@ -77,8 +79,8 @@ class CmsController < MyProfileController | @@ -77,8 +79,8 @@ class CmsController < MyProfileController | ||
77 | # FIXME this method should share some logic wirh edit !!! | 79 | # FIXME this method should share some logic wirh edit !!! |
78 | 80 | ||
79 | # user must choose an article type first | 81 | # user must choose an article type first |
82 | + | ||
80 | @type = params[:type] | 83 | @type = params[:type] |
81 | - | ||
82 | if @type.blank? | 84 | if @type.blank? |
83 | @article_types = [] | 85 | @article_types = [] |
84 | available_article_types.each do |type| | 86 | available_article_types.each do |type| |
@@ -95,6 +97,7 @@ class CmsController < MyProfileController | @@ -95,6 +97,7 @@ class CmsController < MyProfileController | ||
95 | if @type == 'Blog' | 97 | if @type == 'Blog' |
96 | @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier) | 98 | @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier) |
97 | end | 99 | end |
100 | + refuse_blocks | ||
98 | end | 101 | end |
99 | 102 | ||
100 | raise "Invalid article type #{@type}" unless valid_article_type?(@type) | 103 | raise "Invalid article type #{@type}" unless valid_article_type?(@type) |
@@ -134,14 +137,21 @@ class CmsController < MyProfileController | @@ -134,14 +137,21 @@ class CmsController < MyProfileController | ||
134 | @uploaded_files = [] | 137 | @uploaded_files = [] |
135 | @article = @parent = check_parent(params[:parent_id]) | 138 | @article = @parent = check_parent(params[:parent_id]) |
136 | @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier | 139 | @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier |
140 | + @folders = Folder.find(:all, :conditions => { :profile_id => profile }) | ||
137 | record_coming_from_public_view if @article | 141 | record_coming_from_public_view if @article |
138 | if request.post? && params[:uploaded_files] | 142 | if request.post? && params[:uploaded_files] |
139 | params[:uploaded_files].each do |file| | 143 | params[:uploaded_files].each do |file| |
140 | @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent) unless file == '' | 144 | @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent) unless file == '' |
141 | end | 145 | end |
142 | @errors = @uploaded_files.select { |f| f.errors.any? } | 146 | @errors = @uploaded_files.select { |f| f.errors.any? } |
147 | + @back_to = params[:back_to] | ||
143 | if @errors.any? | 148 | if @errors.any? |
144 | - render :action => 'upload_files', :parent_id => @parent_id | 149 | + if @back_to && @back_to == 'media_listing' |
150 | + flash[:notice] = _('Could not upload all files') | ||
151 | + redirect_back | ||
152 | + else | ||
153 | + render :action => 'upload_files', :parent_id => @parent_id | ||
154 | + end | ||
145 | else | 155 | else |
146 | if params[:back_to] | 156 | if params[:back_to] |
147 | redirect_back | 157 | redirect_back |
@@ -199,6 +209,39 @@ class CmsController < MyProfileController | @@ -199,6 +209,39 @@ class CmsController < MyProfileController | ||
199 | end | 209 | end |
200 | end | 210 | end |
201 | 211 | ||
212 | + def media_listing | ||
213 | + if params[:image_folder_id] | ||
214 | + folder = profile.articles.find(params[:image_folder_id]) if !params[:image_folder_id].blank? | ||
215 | + @images = (folder ? folder.children : UploadedFile.find(:all, :conditions => ["profile_id = ? AND parent_id is NULL", profile ])).select { |c| c.image? } | ||
216 | + elsif params[:document_folder_id] | ||
217 | + folder = profile.articles.find(params[:document_folder_id]) if !params[:document_folder_id].blank? | ||
218 | + @documents = (folder ? folder.children : UploadedFile.find(:all, :conditions => ["profile_id = ? AND parent_id is NULL", profile ])).select { |c| c.kind_of?(UploadedFile) && !c.image? } | ||
219 | + else | ||
220 | + @documents = UploadedFile.find(:all, :conditions => ["profile_id = ? AND parent_id is NULL", profile ]) | ||
221 | + @images = @documents.select(&:image?) | ||
222 | + @documents -= @images | ||
223 | + end | ||
224 | + | ||
225 | + @images = @images.paginate(:per_page => per_page, :page => params[:ipage]) if @images | ||
226 | + @documents = @documents.paginate(:per_page => per_page, :page => params[:dpage]) if @documents | ||
227 | + | ||
228 | + @folders = Folder.find(:all, :conditions => { :profile_id => profile }) | ||
229 | + @image_folders = @folders.select {|f| f.children.any? {|c| c.image?} } | ||
230 | + @document_folders = @folders.select {|f| f.children.any? {|c| !c.image? && c.kind_of?(UploadedFile) } } | ||
231 | + | ||
232 | + @back_to = 'media_listing' | ||
233 | + | ||
234 | + respond_to do |format| | ||
235 | + format.html { render :layout => false} | ||
236 | + format.js { | ||
237 | + render :update do |page| | ||
238 | + page.replace_html 'media-listing-folder-images', :partial => 'image_thumb', :locals => {:images => @images } if !@images.blank? | ||
239 | + page.replace_html 'media-listing-folder-documents', :partial => 'document_link', :locals => {:documents => @documents } if !@documents.blank? | ||
240 | + end | ||
241 | + } | ||
242 | + end | ||
243 | + end | ||
244 | + | ||
202 | protected | 245 | protected |
203 | 246 | ||
204 | def redirect_back | 247 | def redirect_back |
@@ -206,6 +249,8 @@ class CmsController < MyProfileController | @@ -206,6 +249,8 @@ class CmsController < MyProfileController | ||
206 | redirect_to :controller => 'profile_editor', :profile => @profile.identifier | 249 | redirect_to :controller => 'profile_editor', :profile => @profile.identifier |
207 | elsif params[:back_to] == 'public_view' | 250 | elsif params[:back_to] == 'public_view' |
208 | redirect_to @article.view_url | 251 | redirect_to @article.view_url |
252 | + elsif params[:back_to] == 'media_listing' | ||
253 | + redirect_to :action => 'media_listing' | ||
209 | elsif @article.parent | 254 | elsif @article.parent |
210 | redirect_to :action => 'view', :id => @article.parent | 255 | redirect_to :action => 'view', :id => @article.parent |
211 | else | 256 | else |
@@ -239,7 +284,7 @@ class CmsController < MyProfileController | @@ -239,7 +284,7 @@ class CmsController < MyProfileController | ||
239 | end | 284 | end |
240 | 285 | ||
241 | def check_parent(id) | 286 | def check_parent(id) |
242 | - if id | 287 | + if !id.blank? |
243 | parent = profile.articles.find(id) | 288 | parent = profile.articles.find(id) |
244 | if ! parent.allow_children? | 289 | if ! parent.allow_children? |
245 | raise ArgumentError.new("cannot create child of article which does not accept children") | 290 | raise ArgumentError.new("cannot create child of article which does not accept children") |
@@ -249,5 +294,15 @@ class CmsController < MyProfileController | @@ -249,5 +294,15 @@ class CmsController < MyProfileController | ||
249 | nil | 294 | nil |
250 | end | 295 | end |
251 | end | 296 | end |
297 | + | ||
298 | + def refuse_blocks | ||
299 | + if ['TinyMceArticle', 'Event', 'EnterpriseHomepage'].include?(@type) | ||
300 | + @no_design_blocks = true | ||
301 | + end | ||
302 | + end | ||
303 | + | ||
304 | + def per_page | ||
305 | + 10 | ||
306 | + end | ||
252 | end | 307 | end |
253 | 308 |
app/helpers/cms_helper.rb
@@ -9,12 +9,21 @@ module CmsHelper | @@ -9,12 +9,21 @@ module CmsHelper | ||
9 | mime_type.gsub('/', '_').gsub('-', '') | 9 | mime_type.gsub('/', '_').gsub('-', '') |
10 | end | 10 | end |
11 | 11 | ||
12 | - def add_upload_file_field(name) | 12 | + def add_upload_file_field(name, locals) |
13 | button_to_function :add, name, nil do |page| | 13 | button_to_function :add, name, nil do |page| |
14 | - page.insert_html :bottom, :uploaded_files, :partial => 'upload_file', :object => UploadedFile.new | 14 | + page.insert_html :bottom, :uploaded_files, :partial => 'upload_file', :locals => locals, :object => UploadedFile.new |
15 | end | 15 | end |
16 | end | 16 | end |
17 | 17 | ||
18 | + def select_folder(object, method, collection, html_options, js_options) | ||
19 | + labelled_form_field(_('Folder'), select(object, method, collection.map {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, html_options.merge({:include_blank => "#{profile.identifier}"}), js_options)) | ||
20 | + end | ||
21 | + | ||
22 | + def pagination_links(collection, options={}) | ||
23 | + options = {:prev_label => '« ', :next_label => ' »', :page_links => false}.merge(options) | ||
24 | + will_paginate(collection, options) | ||
25 | + end | ||
26 | + | ||
18 | attr_reader :environment | 27 | attr_reader :environment |
19 | 28 | ||
20 | def options_for_article(article) | 29 | def options_for_article(article) |
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<div id='media-listing-folder-documents' > | ||
2 | + <ul> | ||
3 | + <% documents.each do |document| %> | ||
4 | + <li><%= link_to(image_tag(icon_for_article(document)) + document.name, document.view_url) %></li> | ||
5 | + <% end %> | ||
6 | + </ul> | ||
7 | + <div id='pagination-documents'> | ||
8 | + <%= pagination_links documents, :param_name => 'dpage', :params => {:document_folder_id => params[:document_folder_id]} %> | ||
9 | + </div> | ||
10 | +</div> |
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<div id='media-listing-folder-images' > | ||
2 | + <ul> | ||
3 | + <% images.each do |image| %> | ||
4 | + <li><%= image_tag url_for(image.url) %></li> | ||
5 | + <% end %> | ||
6 | + </ul> | ||
7 | + <div id='pagination-images'> | ||
8 | + <%= pagination_links images, :param_name => 'ipage', :params => {:image_folder_id => params[:image_folder_id]} %> | ||
9 | + </div> | ||
10 | +</div> |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +<%= select('folder', 'folder_id', @image_folders.collect {|f| [ f.name, f.id ] }, {:include_blank => "#{profile.identifier}"}, :onchange => remote_function(:update => 'media-listing-folder-images', :with => "'folder_id=' + value", :url => { :action => :get_images }) ) %> |
app/views/cms/_tiny_mce_article.rhtml
@@ -2,13 +2,15 @@ | @@ -2,13 +2,15 @@ | ||
2 | 2 | ||
3 | <%= render :file => 'shared/tiny_mce' %> | 3 | <%= render :file => 'shared/tiny_mce' %> |
4 | 4 | ||
5 | -<% if profile.enterprise? && environment.enabled?('disable_cms') && !@article.name.blank? %> | ||
6 | - <div> | ||
7 | - <%= _('Title') %>: <%= @article.name %> | ||
8 | - </div> | ||
9 | -<% else %> | ||
10 | - <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> | ||
11 | -<% end %> | 5 | +<div style='margin-left: 20px;'> |
6 | + <% if profile.enterprise? && environment.enabled?('disable_cms') && !@article.name.blank? %> | ||
7 | + <div> | ||
8 | + <%= _('Title') %>: <%= @article.name %> | ||
9 | + </div> | ||
10 | + <% else %> | ||
11 | + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> | ||
12 | + <% end %> | ||
12 | 13 | ||
13 | -<%= labelled_form_field(_('Text'), text_area(:article, 'body', :cols => 40, :style => 'width:99%')) %> | 14 | + <%= labelled_form_field(_('Text'), text_area(:article, 'body', :cols => 40, :style => 'width:100%')) %> |
14 | 15 | ||
16 | +</div> |
app/views/cms/_upload_file.rhtml
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +<% if @parent %> | ||
2 | + <%= hidden_field_tag('parent_id', @parent.id) %> | ||
3 | +<% else %> | ||
4 | + <h4><%= _('Choose folder to upload files:') %></h4> | ||
5 | + <%= select_tag('parent_id', options_for_select([[profile.identifier, '']] + @folders.collect {|f| [ f.name, f.id ] })) %> | ||
6 | +<% end %> | ||
7 | + | ||
8 | +<div id='uploaded_files'> | ||
9 | + <% 3.times do %> | ||
10 | + <%= render :partial => 'upload_file', :locals => {:size => size} %> | ||
11 | + <% end %> | ||
12 | +</div> | ||
13 | + | ||
14 | +<%= hidden_field_tag('back_to', @back_to) if @back_to %> | ||
15 | + | ||
16 | +<% button_bar do %> | ||
17 | + <%= add_upload_file_field(_('More files'), {:size => size}) %> | ||
18 | + <% if @back_to == 'media_listing' %> | ||
19 | + <%= submit_button :save, _('Upload') %> | ||
20 | + <% elsif @back_url %> | ||
21 | + <%= submit_button :save, _('Upload'), :cancel => @back_url %> | ||
22 | + <% else %> | ||
23 | + <%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %> | ||
24 | + <% end %> | ||
25 | +<% end %> |
app/views/cms/edit.rhtml
1 | <%= error_messages_for 'article' %> | 1 | <%= error_messages_for 'article' %> |
2 | 2 | ||
3 | -<% labelled_form_for 'article', @article, :html => { :multipart => true } do |f| %> | 3 | +<% labelled_form_for 'article', @article, :html => { :multipart => true, :style => 'width:57%;float:left;' } do |f| %> |
4 | 4 | ||
5 | <%= hidden_field_tag("type", @type) if @type %> | 5 | <%= hidden_field_tag("type", @type) if @type %> |
6 | 6 | ||
@@ -38,3 +38,7 @@ | @@ -38,3 +38,7 @@ | ||
38 | <% end %> | 38 | <% end %> |
39 | <% end %> | 39 | <% end %> |
40 | <% end %> | 40 | <% end %> |
41 | + | ||
42 | +<% if [TinyMceArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %> | ||
43 | + <%= render :partial => 'media_listing' %> | ||
44 | +<% end %> |
@@ -0,0 +1,62 @@ | @@ -0,0 +1,62 @@ | ||
1 | +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= html_language %>" lang="<%= html_language %>"> | ||
2 | +<head> | ||
3 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
4 | + <%= | ||
5 | + stylesheet_import( %w( media_listing button ) ) + "\n" + | ||
6 | + stylesheet_import( %w( media_listing button ), :themed_source => true ) | ||
7 | + %> | ||
8 | + <%= javascript_include_tag :defaults %> | ||
9 | + <%= javascript_include_tag 'lowpro' %> | ||
10 | + <%= stylesheet_link_tag '/designs/icons/default/style.css' %> | ||
11 | +</head> | ||
12 | +<body class='noosfero'> | ||
13 | + <script type="text/javascript"> | ||
14 | + /* Adds a class to "msie" to the body element if a Microsoft browser is | ||
15 | + * detected. This is needed to workaround several of their limitations. | ||
16 | + */ | ||
17 | + if ( navigator.appVersion.indexOf("MSIE") > -1 ) { | ||
18 | + document.body.className += " msie msie" + | ||
19 | + navigator.appVersion.replace(/^.*MSIE\s+([0-9]+).*$/, "$1"); | ||
20 | + } | ||
21 | + function registerDocumentSize() { | ||
22 | + document.body.className = document.body.className.replace(/(^| )docSize.+( |$)/g, " "); | ||
23 | + for ( var x=100; x<=1500; x+=100 ) { | ||
24 | + if ( document.body.clientWidth > x ) { | ||
25 | + document.body.className += " docSize-GT-" + x; | ||
26 | + } else { | ||
27 | + document.body.className += " docSize-LT-" + x; | ||
28 | + } | ||
29 | + } | ||
30 | + } | ||
31 | + registerDocumentSize(); | ||
32 | + </script> | ||
33 | + <div id='media-listing'> | ||
34 | + <div id='media-listing-images'> | ||
35 | + <h3><%= _('Images') %></h3> | ||
36 | + <%= select_folder('folder', 'image_folder_id', @image_folders, {}, :onchange => remote_function(:with => "'image_folder_id=' + value + '&ipage=1'", :url => { :action => :media_listing, :format => 'js' }) ) %> | ||
37 | + <%= render :partial => 'image_thumb', :locals => { :images => @images } %> | ||
38 | + </div><!-- id='media-listing-images' --> | ||
39 | + <div id='media-listing-documents'> | ||
40 | + <h3><%= _('Documents') %></h3> | ||
41 | + <%= select_folder('folder', 'document_folder_id', @document_folders, {}, :onchange => remote_function(:with => "'document_folder_id=' + value + '&dpage=1'", :url => { :action => :media_listing }) ) %> | ||
42 | + <%= render :partial => 'document_link', :locals => { :documents => @documents } %> | ||
43 | + </div><!-- id='media-listing-documents' --> | ||
44 | + <br style="clear:both" /> | ||
45 | + <p><%= _('If you want to add images or links to files in your article, click on the file you want, drag it to the text area and drop the file.') %></p> | ||
46 | + <br style="clear:both" /> | ||
47 | + </div><!-- id='media-listing' --> | ||
48 | + <div id='media-listing-upload'> | ||
49 | + <div id="notice" onclick="Element.hide('notice');" style="display:none"> | ||
50 | + <% unless flash[:notice].nil? %> | ||
51 | + <%= flash[:notice] unless flash[:notice].nil? %> | ||
52 | + <%= javascript_tag(visual_effect( :appear, 'notice')) %> | ||
53 | + <% end %> | ||
54 | + </div> | ||
55 | + | ||
56 | + <% form_for('uploaded_file', :url => {:action => 'upload_files'}, :html => {:multipart => true}) do |f| %> | ||
57 | + <%= hidden_field_tag('back_to', @back_to) %> | ||
58 | + <%= render :partial => 'upload_file_form', :locals => { :size => '30' } %> | ||
59 | + <% end %> | ||
60 | + </div><!-- id='media-listing-upload' --> | ||
61 | +</body> | ||
62 | +</html> |
app/views/cms/upload_files.rhtml
@@ -20,24 +20,5 @@ | @@ -20,24 +20,5 @@ | ||
20 | <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5> | 20 | <h5><%= _('Uploading files to %s') % content_tag('code', @target) %></h5> |
21 | 21 | ||
22 | <% form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> | 22 | <% form_for('uploaded_file', :url => { :action => 'upload_files' }, :html => {:multipart => true}) do |f| %> |
23 | - | ||
24 | - <div id='uploaded_files'> | ||
25 | - <% 3.times do %> | ||
26 | - <%= render :partial => 'upload_file' %> | ||
27 | - <% end %> | ||
28 | - </div> | ||
29 | - | ||
30 | - <%= hidden_field_tag('parent_id', @parent.id) if @parent %> | ||
31 | - | ||
32 | - <%= hidden_field_tag('back_to', @back_to) if @back_to %> | ||
33 | - | ||
34 | - <% button_bar do %> | ||
35 | - <%= add_upload_file_field _('More files') %> | ||
36 | - <% if @back_url %> | ||
37 | - <%= submit_button :save, _('Upload'), :cancel => @back_url %> | ||
38 | - <% else %> | ||
39 | - <%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %> | ||
40 | - <% end %> | ||
41 | - <% end %> | ||
42 | - | 23 | + <%= render :partial => 'upload_file_form', :locals => { :size => '50'} %> |
43 | <% end %> | 24 | <% end %> |
public/javascripts/application.js
@@ -41,3 +41,11 @@ function convToValidLogin( str ) { | @@ -41,3 +41,11 @@ function convToValidLogin( str ) { | ||
41 | .replace( /[^-_a-z0-9]+/g, "" ) | 41 | .replace( /[^-_a-z0-9]+/g, "" ) |
42 | } | 42 | } |
43 | 43 | ||
44 | +document.observe("dom:loaded", function() { | ||
45 | + Event.addBehavior.reassignAfterAjax = true; | ||
46 | + Event.addBehavior({ | ||
47 | + 'div#pagination-images .pagination a' : Remote.Link, | ||
48 | + 'div#pagination-documents .pagination a' : Remote.Link | ||
49 | + }) | ||
50 | +}); | ||
51 | + |
public/stylesheets/controller_cms.css
@@ -145,3 +145,19 @@ div.file-manager-button a:hover { | @@ -145,3 +145,19 @@ div.file-manager-button a:hover { | ||
145 | #fetch-external-feed #external-feed-options .formfield { | 145 | #fetch-external-feed #external-feed-options .formfield { |
146 | display: block; | 146 | display: block; |
147 | } | 147 | } |
148 | + | ||
149 | +/* Media listing */ | ||
150 | + | ||
151 | +#media-listing-iframe { | ||
152 | + float: right; | ||
153 | + width: 40%; | ||
154 | + height: 630px; | ||
155 | + border: none; | ||
156 | + margin: 115px 20px 0px 0px; | ||
157 | + padding: 0px; | ||
158 | + overflow: hidden; | ||
159 | +} | ||
160 | + | ||
161 | +.msie #media-listing-iframe { | ||
162 | + height: 610px; | ||
163 | +} |
@@ -0,0 +1,146 @@ | @@ -0,0 +1,146 @@ | ||
1 | +body { | ||
2 | + padding: 0px; | ||
3 | + margin: 0px; | ||
4 | + font-family: Verdana, sans-serif; | ||
5 | + font-size: 14px; | ||
6 | + color: #444; | ||
7 | + background-color: #F0F0EE; | ||
8 | + border: 1px solid #CCC; | ||
9 | + overflow: hidden; | ||
10 | +} | ||
11 | + | ||
12 | +h3, h4, h5 { | ||
13 | + margin: 10px 0px; | ||
14 | +} | ||
15 | + | ||
16 | +h3 { | ||
17 | + font-size: 18px; | ||
18 | +} | ||
19 | + | ||
20 | +h4 { | ||
21 | + font-size: 16px; | ||
22 | +} | ||
23 | + | ||
24 | +#media-listing { | ||
25 | + width: 100%; | ||
26 | + height: 65%; | ||
27 | + margin: 0px; | ||
28 | + padding: 0px; | ||
29 | + border-bottom: 2px solid #444; | ||
30 | +} | ||
31 | + | ||
32 | +#media-listing p { | ||
33 | + font-size: 14px; | ||
34 | + margin: 5px 5px; | ||
35 | +} | ||
36 | + | ||
37 | +#media-listing li { | ||
38 | + list-style: none; | ||
39 | + margin: 0px; | ||
40 | +} | ||
41 | + | ||
42 | +#media-listing a { | ||
43 | + text-decoration: none; | ||
44 | +} | ||
45 | + | ||
46 | +#media-listing select { | ||
47 | + width: 80%; | ||
48 | +} | ||
49 | + | ||
50 | +#media-listing-images { | ||
51 | + margin-top: 2px; | ||
52 | + width: 46%; | ||
53 | + height: 80%; | ||
54 | + float: left; | ||
55 | + text-align: center; | ||
56 | +} | ||
57 | + | ||
58 | +#media-listing-images img { | ||
59 | + max-width: 80px; | ||
60 | + max-height: 60px; | ||
61 | +} | ||
62 | + | ||
63 | +.msie6 #media-listing-images img, | ||
64 | +.msie7 #media-listing-images img { | ||
65 | + width: 80px; | ||
66 | + height: 60px; | ||
67 | +} | ||
68 | + | ||
69 | +#media-listing-folder-images { | ||
70 | + height: 75%; | ||
71 | +} | ||
72 | + | ||
73 | +#media-listing ul { | ||
74 | + padding: 0px; | ||
75 | + margin: 5px; | ||
76 | + height: 65%; | ||
77 | + overflow: auto; | ||
78 | + width: 98%; | ||
79 | +} | ||
80 | + | ||
81 | +#media-listing-documents ul { | ||
82 | + text-align: left; | ||
83 | +} | ||
84 | + | ||
85 | +#media-listing-documents { | ||
86 | + margin: 2px 0px 0px 2px; | ||
87 | + width: 52%; | ||
88 | + height: 80%; | ||
89 | + float: left; | ||
90 | + text-align: center; | ||
91 | +} | ||
92 | + | ||
93 | +#media-listing-folder-documents { | ||
94 | + height: 75%; | ||
95 | +} | ||
96 | + | ||
97 | +#media-listing-folder-documents img { | ||
98 | + border: none; | ||
99 | +} | ||
100 | + | ||
101 | +#media-listing-upload { | ||
102 | + height: 38%; | ||
103 | + width: 98%; | ||
104 | + padding: 3px; | ||
105 | +} | ||
106 | + | ||
107 | +#media-listing-upload p { | ||
108 | + margin: 5px 0px; | ||
109 | +} | ||
110 | + | ||
111 | +#media-listing-upload select { | ||
112 | + width: 90%; | ||
113 | +} | ||
114 | + | ||
115 | +#uploaded_files { | ||
116 | + overflow-x: hidden; | ||
117 | + overflow-y: scroll; | ||
118 | + height: 100px; | ||
119 | +} | ||
120 | + | ||
121 | +.msie #uploaded_files { | ||
122 | + height: 100px; | ||
123 | + padding: 0px; | ||
124 | +} | ||
125 | + | ||
126 | +.formlabel { | ||
127 | + font-size: 11px; | ||
128 | + display: block; | ||
129 | +} | ||
130 | + | ||
131 | +/* Notice */ | ||
132 | + | ||
133 | +div#notice { | ||
134 | + background: #fee; | ||
135 | + border: 1px solid #933; | ||
136 | + bottom: 150px; | ||
137 | + color: black; | ||
138 | + cursor: pointer; | ||
139 | + font-weight: bold; | ||
140 | + left: 50%; | ||
141 | + margin-left: -150px; | ||
142 | + padding: 5px; | ||
143 | + position: absolute; | ||
144 | + text-align: center; | ||
145 | + width: 300px; | ||
146 | +} |
test/functional/cms_controller_test.rb
@@ -278,7 +278,6 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -278,7 +278,6 @@ class CmsControllerTest < Test::Unit::TestCase | ||
278 | assert_template 'upload_files' | 278 | assert_template 'upload_files' |
279 | end | 279 | end |
280 | 280 | ||
281 | - | ||
282 | should 'offer to create children' do | 281 | should 'offer to create children' do |
283 | Article.any_instance.stubs(:allow_children?).returns(true) | 282 | Article.any_instance.stubs(:allow_children?).returns(true) |
284 | 283 | ||
@@ -942,4 +941,154 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -942,4 +941,154 @@ class CmsControllerTest < Test::Unit::TestCase | ||
942 | assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' } | 941 | assert_tag :tag => 'input', :attributes => { :name => 'article[external_feed_builder][only_once]', :checked => 'checked', :value => 'true' } |
943 | end | 942 | end |
944 | 943 | ||
944 | + should 'display iframe for media listing when it is TinyMceArticle' do | ||
945 | + image_folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
946 | + non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') | ||
947 | + | ||
948 | + image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
949 | + file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
950 | + | ||
951 | + get :new, :profile => profile.identifier, :type => 'TinyMceArticle' | ||
952 | + assert_tag :tag => 'iframe', :attributes => { :src => "/myprofile/#{profile.identifier}/cms/media_listing?type=TinyMceArticle" } | ||
953 | + end | ||
954 | + | ||
955 | + should 'not display iframe for media listing when it is Folder' do | ||
956 | + image_folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
957 | + non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') | ||
958 | + | ||
959 | + image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
960 | + file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
961 | + | ||
962 | + get :new, :profile => profile.identifier, :type => 'Folder' | ||
963 | + assert_no_tag :tag => 'iframe', :attributes => { :src => "/myprofile/#{profile.identifier}/cms/media_listing" } | ||
964 | + end | ||
965 | + | ||
966 | + should 'display list of images' do | ||
967 | + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
968 | + get :media_listing, :profile => profile.identifier | ||
969 | + assert_tag :tag => 'div', :attributes => { :id => 'media-listing-images' }, :descendant => { :tag => 'img', :attributes => {:src => /#{file.name}/}} | ||
970 | + end | ||
971 | + | ||
972 | + should 'display list of documents' do | ||
973 | + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
974 | + get :media_listing, :profile => profile.identifier | ||
975 | + assert_tag :tag => 'div', :attributes => { :id => 'media-listing-documents' }, :descendant => { :tag => 'a', :attributes => {:href => /#{file.name}/}} | ||
976 | + end | ||
977 | + | ||
978 | + should 'list image folders to select' do | ||
979 | + image_folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
980 | + non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') | ||
981 | + | ||
982 | + image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
983 | + file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
984 | + | ||
985 | + get :media_listing, :profile => profile.identifier | ||
986 | + assert_tag :tag => 'div', :attributes => { :id => 'media-listing-images' }, :descendant => { :tag => 'option', :content => /#{image_folder.name}/, :attributes => { :value => image_folder.id}} | ||
987 | + assert_no_tag :tag => 'div', :attributes => { :id => 'media-listing-images' }, :descendant => { :tag => 'option', :content => /#{non_image_folder.name}/, :attributes => { :value => non_image_folder.id}} | ||
988 | + end | ||
989 | + | ||
990 | + should 'list documents folders to select' do | ||
991 | + image_folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
992 | + non_image_folder = Folder.create(:profile => profile, :name => 'Non image folder') | ||
993 | + | ||
994 | + image = UploadedFile.create!(:profile => profile, :parent => image_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
995 | + file = UploadedFile.create!(:profile => profile, :parent => non_image_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
996 | + | ||
997 | + get :media_listing, :profile => profile.identifier | ||
998 | + assert_no_tag :tag => 'div', :attributes => { :id => 'media-listing-documents' }, :descendant => { :tag => 'option', :content => /#{image_folder.name}/, :attributes => { :value => image_folder.id}} | ||
999 | + assert_tag :tag => 'div', :attributes => { :id => 'media-listing-documents' }, :descendant => { :tag => 'option', :content => /#{non_image_folder.name}/, :attributes => { :value => non_image_folder.id}} | ||
1000 | + end | ||
1001 | + | ||
1002 | + should 'get a list of images from a image folder' do | ||
1003 | + folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
1004 | + other_folder = Folder.create(:profile => profile, :name => 'Non image folder') | ||
1005 | + image = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
1006 | + file_in_folder = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
1007 | + image_in_other_folder = UploadedFile.create!(:profile => profile, :parent => other_folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
1008 | + | ||
1009 | + get :media_listing, :profile => profile.identifier, :image_folder_id => folder.id, :format => 'js' | ||
1010 | + | ||
1011 | + assert_includes assigns(:images), image | ||
1012 | + assert_not_includes assigns(:images), file_in_folder | ||
1013 | + assert_not_includes assigns(:images), image_in_other_folder | ||
1014 | + end | ||
1015 | + | ||
1016 | + should 'get a list of images from profile' do | ||
1017 | + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
1018 | + folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
1019 | + image_in_folder = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
1020 | + get :media_listing, :profile => profile.identifier, :image_folder_id => '', :format => 'js' | ||
1021 | + | ||
1022 | + assert_includes assigns(:images), image | ||
1023 | + assert_not_includes assigns(:images), image_in_folder | ||
1024 | + end | ||
1025 | + | ||
1026 | + should 'get a list of documents from a document folder' do | ||
1027 | + folder = Folder.create(:profile => profile, :name => 'Non images folder') | ||
1028 | + other_folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
1029 | + file = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
1030 | + image = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
1031 | + file_in_other_folder = UploadedFile.create!(:profile => profile, :parent => other_folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
1032 | + | ||
1033 | + get :media_listing, :profile => profile.identifier, :document_folder_id => folder.id, :format => 'js' | ||
1034 | + | ||
1035 | + assert_includes assigns(:documents), file | ||
1036 | + assert_not_includes assigns(:documents), image | ||
1037 | + assert_not_includes assigns(:documents), file_in_other_folder | ||
1038 | + end | ||
1039 | + | ||
1040 | + should 'get a list of documents from profile' do | ||
1041 | + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
1042 | + folder = Folder.create(:profile => profile, :name => 'Image folder') | ||
1043 | + file_in_folder = UploadedFile.create!(:profile => profile, :parent => folder, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
1044 | + | ||
1045 | + get :media_listing, :profile => profile.identifier, :document_folder_id => '', :format => 'js' | ||
1046 | + | ||
1047 | + assert_includes assigns(:documents), file | ||
1048 | + assert_not_includes assigns(:documents), file_in_folder | ||
1049 | + end | ||
1050 | + | ||
1051 | + should 'display pagination links of images' do | ||
1052 | + @controller.stubs(:per_page).returns(1) | ||
1053 | + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
1054 | + | ||
1055 | + fixture_filename = '/files/other-pic.jpg' | ||
1056 | + filename = RAILS_ROOT + '/test/fixtures' + fixture_filename | ||
1057 | + system('echo "image for test" | convert -background yellow -page 32x32 text:- %s' % filename) | ||
1058 | + | ||
1059 | + image2 = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload(fixture_filename, 'image/jpg')) | ||
1060 | + | ||
1061 | + get :media_listing, :profile => profile.identifier | ||
1062 | + | ||
1063 | + assert_includes assigns(:images), image | ||
1064 | + assert_not_includes assigns(:images), image2 | ||
1065 | + | ||
1066 | + File.rm_f(filename) | ||
1067 | + end | ||
1068 | + | ||
1069 | + should 'display pagination links of documents' do | ||
1070 | + @controller.stubs(:per_page).returns(1) | ||
1071 | + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) | ||
1072 | + file2 = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/feed.xml', 'text/xml')) | ||
1073 | + | ||
1074 | + get :media_listing, :profile => profile.identifier | ||
1075 | + | ||
1076 | + assert_includes assigns(:documents), file | ||
1077 | + assert_not_includes assigns(:documents), file2 | ||
1078 | + end | ||
1079 | + | ||
1080 | + | ||
1081 | + should 'redirect to media listing when upload files from there' do | ||
1082 | + post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')] | ||
1083 | + assert_template nil | ||
1084 | + assert_redirected_to :action => 'media_listing' | ||
1085 | + end | ||
1086 | + | ||
1087 | + should 'redirect to media listing when occur errors when upload files from there' do | ||
1088 | + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('files/rails.png', 'image/png')) | ||
1089 | + | ||
1090 | + post :upload_files, :profile => profile.identifier, :back_to => 'media_listing', :uploaded_files => [fixture_file_upload('files/rails.png', 'image/png')] | ||
1091 | + assert_template nil | ||
1092 | + assert_redirected_to :action => 'media_listing' | ||
1093 | + end | ||
945 | end | 1094 | end |