From 7b127ee489a134436ab457467c2da42e32aa652d 2014-02-07 07:57:59 From: Jean-Philippe Lang Date: 2014-02-07 07:57:59 Subject: [PATCH] Show tabs for existing custom field types only and adds a view for choosing the type when adding a new custom field. git-svn-id: http://svn.redmine.org/redmine/trunk@12849 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 3f721b1..28178e9 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -77,7 +77,7 @@ class CustomFieldsController < ApplicationController def build_new_custom_field @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field]) if @custom_field.nil? - render_404 + render :action => 'select_type' end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 25096a1..363653c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -309,9 +309,13 @@ module ApplicationHelper end # Renders tabs and their content - def render_tabs(tabs) + def render_tabs(tabs, selected=params[:tab]) if tabs.any? - render :partial => 'common/tabs', :locals => {:tabs => tabs} + unless tabs.detect {|tab| tab[:name] == selected} + selected = nil + end + selected ||= tabs.first[:name] + render :partial => 'common/tabs', :locals => {:tabs => tabs, :selected_tab => selected} else content_tag 'p', l(:label_no_data), :class => "nodata" end diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index 5447130..173e0d5 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -40,8 +40,13 @@ module CustomFieldsHelper :label => DocumentCategory::OptionName} ] - def custom_fields_tabs - CUSTOM_FIELDS_TABS + def render_custom_fields_tabs(types) + tabs = CUSTOM_FIELDS_TABS.select {|h| types.include?(h[:name]) } + render_tabs tabs + end + + def custom_field_type_options + CUSTOM_FIELDS_TABS.map {|h| [l(h[:label]), h[:name]]} end def render_custom_field_format_partial(form, custom_field) diff --git a/app/views/common/_tabs.html.erb b/app/views/common/_tabs.html.erb index 8cbcda5..34fd570 100644 --- a/app/views/common/_tabs.html.erb +++ b/app/views/common/_tabs.html.erb @@ -1,5 +1,3 @@ -<% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %> -