Commit 2a7c4de5277aa7643795c14e23b7d18c0d0488d1

Authored by Rodrigo Souto
Committed by Daniela Feitosa
1 parent 2da66927

Adding option to move content parent on edition page

app/controllers/my_profile/cms_controller.rb
@@ -149,7 +149,6 @@ class CmsController < MyProfileController @@ -149,7 +149,6 @@ class CmsController < MyProfileController
149 @uploaded_files = [] 149 @uploaded_files = []
150 @article = @parent = check_parent(params[:parent_id]) 150 @article = @parent = check_parent(params[:parent_id])
151 @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier 151 @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier
152 - @folders = Folder.find(:all, :conditions => { :profile_id => profile })  
153 if @article 152 if @article
154 record_coming 153 record_coming
155 end 154 end
app/helpers/application_helper.rb
@@ -653,19 +653,6 @@ module ApplicationHelper @@ -653,19 +653,6 @@ module ApplicationHelper
653 content_tag('div', result) 653 content_tag('div', result)
654 end 654 end
655 655
656 - def select_folder(label, object, method, collection, html_options = {}, js_options = {})  
657 - root = profile ? profile.identifier : _("root")  
658 - labelled_form_field(label, select(object, method,  
659 - collection.map {|f| [ root + '/' + f.full_name, f.id ]},  
660 - {:include_blank => root}, html_options.merge(js_options)))  
661 - end  
662 -  
663 - def select_profile_folder(label, object, method, profile, html_options = {}, js_options = {})  
664 - labelled_form_field(label, select(object, method,  
665 - profile.folders.map {|f| [ profile.identifier + '/' + f.full_name, f.id ]},  
666 - {:include_blank => profile.identifier}, html_options.merge(js_options)))  
667 - end  
668 -  
669 def theme_option(opt = nil) 656 def theme_option(opt = nil)
670 conf = RAILS_ROOT.to_s() + 657 conf = RAILS_ROOT.to_s() +
671 '/public' + theme_path + 658 '/public' + theme_path +
app/helpers/forms_helper.rb
@@ -236,6 +236,38 @@ module FormsHelper @@ -236,6 +236,38 @@ module FormsHelper
236 ' ' + _('until') +' '+ date_field(to_name, to_value, format, datepicker_options, html_options.merge({:id => to_id})) 236 ' ' + _('until') +' '+ date_field(to_name, to_value, format, datepicker_options, html_options.merge({:id => to_id}))
237 end 237 end
238 238
  239 + def select_folder(label_text, field_id, collection, default_value=nil, html_options = {}, js_options = {})
  240 + root = profile ? profile.identifier : _("root")
  241 + labelled_form_field(
  242 + label_text,
  243 + select_tag(
  244 + field_id,
  245 + options_for_select(
  246 + [[root, '']] +
  247 + collection.collect {|f| [ root + '/' + f.full_name, f.id ] },
  248 + default_value
  249 + ),
  250 + html_options.merge(js_options)
  251 + )
  252 + )
  253 + end
  254 +
  255 + def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {})
  256 + result = labelled_form_field(
  257 + label_text,
  258 + select_tag(
  259 + field_id,
  260 + options_for_select(
  261 + [[profile.identifier, '']] +
  262 + profile.folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id ] },
  263 + default_value
  264 + ),
  265 + html_options.merge(js_options)
  266 + )
  267 + )
  268 + return result
  269 + end
  270 +
239 protected 271 protected
240 def self.next_id_number 272 def self.next_id_number
241 if defined? @@id_num 273 if defined? @@id_num
app/views/cms/_general_fields.html.erb
  1 +<%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id) %>
1 <%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %> 2 <%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %>
app/views/cms/_text_editor_sidebar.rhtml
@@ -9,8 +9,7 @@ @@ -9,8 +9,7 @@
9 <div id='media-upload-form'> 9 <div id='media-upload-form'>
10 <% form_tag({ :action => 'media_upload' }, :multipart => true) do %> 10 <% form_tag({ :action => 'media_upload' }, :multipart => true) do %>
11 <div class='formfield'> 11 <div class='formfield'>
12 - <%# TODO duplicated from partial upload_file_form %>  
13 - <%= labelled_form_field(_('Choose folder to upload files:'), select_tag('parent_id', options_for_select([[profile.identifier, '']] + profile.folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id ] }))) %> 12 + <%= select_profile_folder(_('Choose folder to upload files:'), :parent_id, profile) %>
14 </div> 13 </div>
15 <p><%= file_field_tag('file1') %></p> 14 <p><%= file_field_tag('file1') %></p>
16 <p><%= file_field_tag('file2') %></p> 15 <p><%= file_field_tag('file2') %></p>
app/views/cms/_upload_file_form.rhtml
1 <% if @parent %> 1 <% if @parent %>
2 <%= hidden_field_tag('parent_id', @parent.id) %> 2 <%= hidden_field_tag('parent_id', @parent.id) %>
3 <% else %> 3 <% else %>
4 - <%= labelled_form_field(_('Choose folder to upload files:'), select_tag('parent_id', options_for_select([[profile.identifier, '']] + @folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id ] }))) %> 4 + <%= select_profile_folder(_('Choose folder to upload files:'), :parent_id, profile) %>
5 <% end %> 5 <% end %>
6 6
7 <div id='uploaded_files'> 7 <div id='uploaded_files'>
app/views/cms/_uploaded_file.rhtml
1 <%= labelled_form_field(_('Title'), text_field(:article, :title, :maxlength => 60)) %> 1 <%= labelled_form_field(_('Title'), text_field(:article, :title, :maxlength => 60)) %>
  2 +
  3 +<%= render :partial => 'general_fields' %>
  4 +
2 <%= labelled_form_field(_('Description'), text_area(:article, :abstract, :rows => 3, :cols => 64)) %> 5 <%= labelled_form_field(_('Description'), text_area(:article, :abstract, :rows => 3, :cols => 64)) %>
3 <% if @article.image? %> 6 <% if @article.image? %>
4 <%= f.text_field(:external_link, :size => 64) %> 7 <%= f.text_field(:external_link, :size => 64) %>
test/functional/cms_controller_test.rb
@@ -1557,6 +1557,32 @@ class CmsControllerTest &lt; ActionController::TestCase @@ -1557,6 +1557,32 @@ class CmsControllerTest &lt; ActionController::TestCase
1557 assert_equal license, article.license 1557 assert_equal license, article.license
1558 end 1558 end
1559 1559
  1560 + should 'list folders options to move content' do
  1561 + article = fast_create(Article, :profile_id => profile.id)
  1562 + f1 = fast_create(Folder, :profile_id => profile.id)
  1563 + f2 = fast_create(Folder, :profile_id => profile.id)
  1564 + f3 = fast_create(Folder, :profile_id => profile, :parent_id => f2.id)
  1565 + login_as(profile.identifier)
  1566 +
  1567 + get :edit, :profile => profile.identifier, :id => article.id
  1568 +
  1569 + assert_tag :tag => 'option', :attributes => {:value => f1.id}, :content => "#{profile.identifier}/#{f1.name}"
  1570 + assert_tag :tag => 'option', :attributes => {:value => f2.id}, :content => "#{profile.identifier}/#{f2.name}"
  1571 + assert_tag :tag => 'option', :attributes => {:value => f3.id}, :content => "#{profile.identifier}/#{f2.name}/#{f3.name}"
  1572 + end
  1573 +
  1574 + should 'be able to move content' do
  1575 + f1 = fast_create(Folder, :profile_id => profile.id)
  1576 + f2 = fast_create(Folder, :profile_id => profile.id)
  1577 + article = fast_create(Article, :profile_id => profile.id, :parent_id => f1)
  1578 + login_as(profile.identifier)
  1579 +
  1580 + post :edit, :profile => profile.identifier, :id => article.id, :article => {:parent_id => f2.id}
  1581 + article.reload
  1582 +
  1583 + assert_equal f2, article.parent
  1584 + end
  1585 +
1560 protected 1586 protected
1561 1587
1562 # FIXME this is to avoid adding an extra dependency for a proper JSON parser. 1588 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.