Commit 14a7188797f324099e3837b200388eded62bf983

Authored by Rodrigo Souto
1 parent 79629a6a

Adding option to move content parent on edition page

app/controllers/my_profile/cms_controller.rb
... ... @@ -149,7 +149,6 @@ class CmsController < MyProfileController
149 149 @uploaded_files = []
150 150 @article = @parent = check_parent(params[:parent_id])
151 151 @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier
152   - @folders = Folder.find(:all, :conditions => { :profile_id => profile })
153 152 if @article
154 153 record_coming
155 154 end
... ...
app/helpers/application_helper.rb
... ... @@ -664,19 +664,6 @@ module ApplicationHelper
664 664 content_tag('div', result)
665 665 end
666 666  
667   - def select_folder(label, object, method, collection, html_options = {}, js_options = {})
668   - root = profile ? profile.identifier : _("root")
669   - labelled_form_field(label, select(object, method,
670   - collection.map {|f| [ root + '/' + f.full_name, f.id ]},
671   - {:include_blank => root}, html_options.merge(js_options)))
672   - end
673   -
674   - def select_profile_folder(label, object, method, profile, html_options = {}, js_options = {})
675   - labelled_form_field(label, select(object, method,
676   - profile.folders.map {|f| [ profile.identifier + '/' + f.full_name, f.id ]},
677   - {:include_blank => profile.identifier}, html_options.merge(js_options)))
678   - end
679   -
680 667 def theme_option(opt = nil)
681 668 conf = RAILS_ROOT.to_s() +
682 669 '/public' + theme_path +
... ...
app/helpers/forms_helper.rb
... ... @@ -123,6 +123,38 @@ module FormsHelper
123 123 options_for_select.join("\n")
124 124 end
125 125  
  126 + def select_folder(label_text, field_id, collection, default_value=nil, html_options = {}, js_options = {})
  127 + root = profile ? profile.identifier : _("root")
  128 + labelled_form_field(
  129 + label_text,
  130 + select_tag(
  131 + field_id,
  132 + options_for_select(
  133 + [[root, '']] +
  134 + collection.collect {|f| [ root + '/' + f.full_name, f.id ] },
  135 + default_value
  136 + ),
  137 + html_options.merge(js_options)
  138 + )
  139 + )
  140 + end
  141 +
  142 + def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {})
  143 + result = labelled_form_field(
  144 + label_text,
  145 + select_tag(
  146 + field_id,
  147 + options_for_select(
  148 + [[profile.identifier, '']] +
  149 + profile.folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id ] },
  150 + default_value
  151 + ),
  152 + html_options.merge(js_options)
  153 + )
  154 + )
  155 + return result
  156 + end
  157 +
126 158 protected
127 159 def self.next_id_number
128 160 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 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 9 <div id='media-upload-form'>
10 10 <% form_tag({ :action => 'media_upload' }, :multipart => true) do %>
11 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 13 </div>
15 14 <p><%= file_field_tag('file1') %></p>
16 15 <p><%= file_field_tag('file2') %></p>
... ...
app/views/cms/_upload_file_form.rhtml
1 1 <% if @parent %>
2 2 <%= hidden_field_tag('parent_id', @parent.id) %>
3 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 5 <% end %>
6 6  
7 7 <div id='uploaded_files'>
... ...
app/views/cms/_uploaded_file.rhtml
1 1 <%= labelled_form_field(_('Title'), text_field(:article, :title, :maxlength => 60)) %>
  2 +
  3 +<%= render :partial => 'general_fields' %>
  4 +
2 5 <%= labelled_form_field(_('Description'), text_area(:article, :abstract, :rows => 3, :cols => 64)) %>
3 6 <% if @article.image? %>
4 7 <%= f.text_field(:external_link, :size => 64) %>
... ...
test/functional/cms_controller_test.rb
... ... @@ -1556,6 +1556,32 @@ class CmsControllerTest &lt; ActionController::TestCase
1556 1556 assert_equal license, article.license
1557 1557 end
1558 1558  
  1559 + should 'list folders options to move content' do
  1560 + article = fast_create(Article, :profile_id => profile.id)
  1561 + f1 = fast_create(Folder, :profile_id => profile.id)
  1562 + f2 = fast_create(Folder, :profile_id => profile.id)
  1563 + f3 = fast_create(Folder, :profile_id => profile, :parent_id => f2.id)
  1564 + login_as(profile.identifier)
  1565 +
  1566 + get :edit, :profile => profile.identifier, :id => article.id
  1567 +
  1568 + assert_tag :tag => 'option', :attributes => {:value => f1.id}, :content => "#{profile.identifier}/#{f1.name}"
  1569 + assert_tag :tag => 'option', :attributes => {:value => f2.id}, :content => "#{profile.identifier}/#{f2.name}"
  1570 + assert_tag :tag => 'option', :attributes => {:value => f3.id}, :content => "#{profile.identifier}/#{f2.name}/#{f3.name}"
  1571 + end
  1572 +
  1573 + should 'be able to move content' do
  1574 + f1 = fast_create(Folder, :profile_id => profile.id)
  1575 + f2 = fast_create(Folder, :profile_id => profile.id)
  1576 + article = fast_create(Article, :profile_id => profile.id, :parent_id => f1)
  1577 + login_as(profile.identifier)
  1578 +
  1579 + post :edit, :profile => profile.identifier, :id => article.id, :article => {:parent_id => f2.id}
  1580 + article.reload
  1581 +
  1582 + assert_equal f2, article.parent
  1583 + end
  1584 +
1559 1585 protected
1560 1586  
1561 1587 # FIXME this is to avoid adding an extra dependency for a proper JSON parser.
... ...