diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 29c001d..81c1b60 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -149,7 +149,6 @@ class CmsController < MyProfileController @uploaded_files = [] @article = @parent = check_parent(params[:parent_id]) @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier - @folders = Folder.find(:all, :conditions => { :profile_id => profile }) if @article record_coming end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e5324e0..5108850 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -664,19 +664,6 @@ module ApplicationHelper content_tag('div', result) end - def select_folder(label, object, method, collection, html_options = {}, js_options = {}) - root = profile ? profile.identifier : _("root") - labelled_form_field(label, select(object, method, - collection.map {|f| [ root + '/' + f.full_name, f.id ]}, - {:include_blank => root}, html_options.merge(js_options))) - end - - def select_profile_folder(label, object, method, profile, html_options = {}, js_options = {}) - labelled_form_field(label, select(object, method, - profile.folders.map {|f| [ profile.identifier + '/' + f.full_name, f.id ]}, - {:include_blank => profile.identifier}, html_options.merge(js_options))) - end - def theme_option(opt = nil) conf = RAILS_ROOT.to_s() + '/public' + theme_path + diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index 3f7724c..2c53a03 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -123,6 +123,38 @@ module FormsHelper options_for_select.join("\n") end + def select_folder(label_text, field_id, collection, default_value=nil, html_options = {}, js_options = {}) + root = profile ? profile.identifier : _("root") + labelled_form_field( + label_text, + select_tag( + field_id, + options_for_select( + [[root, '']] + + collection.collect {|f| [ root + '/' + f.full_name, f.id ] }, + default_value + ), + html_options.merge(js_options) + ) + ) + end + + def select_profile_folder(label_text, field_id, profile, default_value='', html_options = {}, js_options = {}) + result = labelled_form_field( + label_text, + select_tag( + field_id, + options_for_select( + [[profile.identifier, '']] + + profile.folders.collect {|f| [ profile.identifier + '/' + f.full_name, f.id ] }, + default_value + ), + html_options.merge(js_options) + ) + ) + return result + end + protected def self.next_id_number if defined? @@id_num diff --git a/app/views/cms/_general_fields.html.erb b/app/views/cms/_general_fields.html.erb index 3644994..95212d4 100644 --- a/app/views/cms/_general_fields.html.erb +++ b/app/views/cms/_general_fields.html.erb @@ -1 +1,2 @@ +<%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id) %> <%= 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))) %> diff --git a/app/views/cms/_text_editor_sidebar.rhtml b/app/views/cms/_text_editor_sidebar.rhtml index f04d727..e67dc5a 100644 --- a/app/views/cms/_text_editor_sidebar.rhtml +++ b/app/views/cms/_text_editor_sidebar.rhtml @@ -9,8 +9,7 @@
<% form_tag({ :action => 'media_upload' }, :multipart => true) do %>
- <%# TODO duplicated from partial upload_file_form %> - <%= 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 ] }))) %> + <%= select_profile_folder(_('Choose folder to upload files:'), :parent_id, profile) %>

<%= file_field_tag('file1') %>

<%= file_field_tag('file2') %>

diff --git a/app/views/cms/_upload_file_form.rhtml b/app/views/cms/_upload_file_form.rhtml index c5033c1..0786dc4 100644 --- a/app/views/cms/_upload_file_form.rhtml +++ b/app/views/cms/_upload_file_form.rhtml @@ -1,7 +1,7 @@ <% if @parent %> <%= hidden_field_tag('parent_id', @parent.id) %> <% else %> - <%= 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 ] }))) %> + <%= select_profile_folder(_('Choose folder to upload files:'), :parent_id, profile) %> <% end %>
diff --git a/app/views/cms/_uploaded_file.rhtml b/app/views/cms/_uploaded_file.rhtml index 2ceafd2..b9ae689 100644 --- a/app/views/cms/_uploaded_file.rhtml +++ b/app/views/cms/_uploaded_file.rhtml @@ -1,4 +1,7 @@ <%= labelled_form_field(_('Title'), text_field(:article, :title, :maxlength => 60)) %> + +<%= render :partial => 'general_fields' %> + <%= labelled_form_field(_('Description'), text_area(:article, :abstract, :rows => 3, :cols => 64)) %> <% if @article.image? %> <%= f.text_field(:external_link, :size => 64) %> diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 6b5aec2..c0b3c5a 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1556,6 +1556,32 @@ class CmsControllerTest < ActionController::TestCase assert_equal license, article.license end + should 'list folders options to move content' do + article = fast_create(Article, :profile_id => profile.id) + f1 = fast_create(Folder, :profile_id => profile.id) + f2 = fast_create(Folder, :profile_id => profile.id) + f3 = fast_create(Folder, :profile_id => profile, :parent_id => f2.id) + login_as(profile.identifier) + + get :edit, :profile => profile.identifier, :id => article.id + + assert_tag :tag => 'option', :attributes => {:value => f1.id}, :content => "#{profile.identifier}/#{f1.name}" + assert_tag :tag => 'option', :attributes => {:value => f2.id}, :content => "#{profile.identifier}/#{f2.name}" + assert_tag :tag => 'option', :attributes => {:value => f3.id}, :content => "#{profile.identifier}/#{f2.name}/#{f3.name}" + end + + should 'be able to move content' do + f1 = fast_create(Folder, :profile_id => profile.id) + f2 = fast_create(Folder, :profile_id => profile.id) + article = fast_create(Article, :profile_id => profile.id, :parent_id => f1) + login_as(profile.identifier) + + post :edit, :profile => profile.identifier, :id => article.id, :article => {:parent_id => f2.id} + article.reload + + assert_equal f2, article.parent + end + protected # FIXME this is to avoid adding an extra dependency for a proper JSON parser. -- libgit2 0.21.2