From ede9960444ed7c93e1561f004ee8682a0458f295 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 12 Sep 2009 09:13:13 +0000 Subject: [PATCH] Refactoring of tabs rendering. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2871 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 9 +++++ app/helpers/custom_fields_helper.rb | 10 +++--- app/views/common/_tabs.rhtml | 19 +++++++++++ app/views/custom_fields/_index.rhtml | 32 ++++++++++++++++++ app/views/custom_fields/index.rhtml | 50 +--------------------------- app/views/groups/edit.html.erb | 20 +---------- app/views/projects/settings.rhtml | 26 +-------------- app/views/settings/edit.rhtml | 20 +---------- app/views/users/edit.rhtml | 20 +---------- 9 files changed, 70 insertions(+), 136 deletions(-) create mode 100644 app/views/common/_tabs.rhtml create mode 100644 app/views/custom_fields/_index.rhtml diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 581ea2fe8..3f96c7dea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -132,6 +132,15 @@ module ApplicationHelper s end + # Renders tabs and their content + def render_tabs(tabs) + if tabs.any? + render :partial => 'common/tabs', :locals => {:tabs => tabs} + else + content_tag 'p', l(:label_no_data), :class => "nodata" + end + end + # Renders the project quick-jump box def render_project_jump_box # Retrieve them now to avoid a COUNT query diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index eb39b4c0a..f97b9238b 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -18,11 +18,11 @@ module CustomFieldsHelper def custom_fields_tabs - tabs = [{:name => 'IssueCustomField', :label => :label_issue_plural}, - {:name => 'TimeEntryCustomField', :label => :label_spent_time}, - {:name => 'ProjectCustomField', :label => :label_project_plural}, - {:name => 'UserCustomField', :label => :label_user_plural}, - {:name => 'GroupCustomField', :label => :label_group_plural} + tabs = [{:name => 'IssueCustomField', :partial => 'custom_fields/index', :label => :label_issue_plural}, + {:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time}, + {:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural}, + {:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural}, + {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural} ] end diff --git a/app/views/common/_tabs.rhtml b/app/views/common/_tabs.rhtml new file mode 100644 index 000000000..f9ef5dd35 --- /dev/null +++ b/app/views/common/_tabs.rhtml @@ -0,0 +1,19 @@ +<% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %> + +
+ +
+ +<% tabs.each do |tab| -%> + <%= content_tag('div', render(:partial => tab[:partial], :locals => {:tab => tab} ), + :id => "tab-content-#{tab[:name]}", + :style => (tab[:name] != selected_tab ? 'display:none' : nil), + :class => 'tab-content') %> +<% end -%> diff --git a/app/views/custom_fields/_index.rhtml b/app/views/custom_fields/_index.rhtml new file mode 100644 index 000000000..1417dd4bb --- /dev/null +++ b/app/views/custom_fields/_index.rhtml @@ -0,0 +1,32 @@ + + + + + + <% if tab[:name] == 'IssueCustomField' %> + + + <% end %> + + + + + <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%> + "> + + + + <% if tab[:name] == 'IssueCustomField' %> + + + <% end %> + + + + <% end; reset_cycle %> + +
<%=l(:field_name)%><%=l(:field_field_format)%><%=l(:field_is_required)%><%=l(:field_is_for_all)%><%=l(:label_used_by)%><%=l(:button_sort)%>
<%= link_to custom_field.name, :action => 'edit', :id => custom_field %><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %><%= image_tag 'true.png' if custom_field.is_required? %><%= image_tag 'true.png' if custom_field.is_for_all? %><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %><%= reorder_links('custom_field', {:action => 'edit', :id => custom_field}) %> + <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %> +
+ +

<%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %>

diff --git a/app/views/custom_fields/index.rhtml b/app/views/custom_fields/index.rhtml index 999648f0e..7b29e25e7 100644 --- a/app/views/custom_fields/index.rhtml +++ b/app/views/custom_fields/index.rhtml @@ -1,53 +1,5 @@

<%=l(:label_custom_field_plural)%>

-<% selected_tab = params[:tab] ? params[:tab].to_s : custom_fields_tabs.first[:name] %> - -
- -
- -<% custom_fields_tabs.each do |tab| %> -
- - - - - - <% if tab[:name] == 'IssueCustomField' %> - - - <% end %> - - - - -<% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%> - "> - - - - <% if tab[:name] == 'IssueCustomField' %> - - - <% end %> - - - -<% end; reset_cycle %> - -
<%=l(:field_name)%><%=l(:field_field_format)%><%=l(:field_is_required)%><%=l(:field_is_for_all)%><%=l(:label_used_by)%><%=l(:button_sort)%>
<%= link_to custom_field.name, :action => 'edit', :id => custom_field %><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %><%= image_tag 'true.png' if custom_field.is_required? %><%= image_tag 'true.png' if custom_field.is_for_all? %><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %><%= reorder_links('custom_field', {:action => 'edit', :id => custom_field}) %> - <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %> -
- -

<%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %>

-
-<% end %> +<%= render_tabs custom_fields_tabs %> <% html_title(l(:label_custom_field_plural)) -%> diff --git a/app/views/groups/edit.html.erb b/app/views/groups/edit.html.erb index 93e890887..e6daa5a09 100644 --- a/app/views/groups/edit.html.erb +++ b/app/views/groups/edit.html.erb @@ -1,23 +1,5 @@

<%= link_to l(:label_group_plural), groups_path %> » <%= h(@group) %>

-<% selected_tab = params[:tab] ? params[:tab].to_s : group_settings_tabs.first[:name] %> - -
- -
- -<% group_settings_tabs.each do |tab| -%> -<%= content_tag('div', render(:partial => tab[:partial]), - :id => "tab-content-#{tab[:name]}", - :style => (tab[:name] != selected_tab ? 'display:none' : nil), - :class => 'tab-content') %> -<% end -%> +<%= render_tabs group_settings_tabs %> <% html_title(l(:label_group), @group, l(:label_administration)) -%> diff --git a/app/views/projects/settings.rhtml b/app/views/projects/settings.rhtml index e8be1a091..eefcb7b06 100644 --- a/app/views/projects/settings.rhtml +++ b/app/views/projects/settings.rhtml @@ -1,29 +1,5 @@

<%=l(:label_settings)%>

-<% tabs = project_settings_tabs %> - -<% if tabs.any? %> -<% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %> - -
- -
- -<% tabs.each do |tab| -%> -<%= content_tag('div', render(:partial => tab[:partial]), - :id => "tab-content-#{tab[:name]}", - :style => (tab[:name] != selected_tab ? 'display:none' : nil), - :class => 'tab-content') %> -<% end -%> -<% else %> -

<%= l(:label_no_data) %>

-<% end %> +<%= render_tabs project_settings_tabs %> <% html_title(l(:label_settings)) -%> diff --git a/app/views/settings/edit.rhtml b/app/views/settings/edit.rhtml index c99a13960..de64e3bb2 100644 --- a/app/views/settings/edit.rhtml +++ b/app/views/settings/edit.rhtml @@ -1,23 +1,5 @@

<%= l(:label_settings) %>

-<% selected_tab = params[:tab] ? params[:tab].to_s : administration_settings_tabs.first[:name] %> - -
- -
- -<% administration_settings_tabs.each do |tab| -%> -<%= content_tag('div', render(:partial => tab[:partial]), - :id => "tab-content-#{tab[:name]}", - :style => (tab[:name] != selected_tab ? 'display:none' : nil), - :class => 'tab-content') %> -<% end -%> +<%= render_tabs administration_settings_tabs %> <% html_title(l(:label_settings), l(:label_administration)) -%> diff --git a/app/views/users/edit.rhtml b/app/views/users/edit.rhtml index 96e089c15..b67ccc2be 100644 --- a/app/views/users/edit.rhtml +++ b/app/views/users/edit.rhtml @@ -4,24 +4,6 @@

<%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> » <%=h @user.login %>

-<% selected_tab = params[:tab] ? params[:tab].to_s : user_settings_tabs.first[:name] %> - -
- -
- -<% user_settings_tabs.each do |tab| -%> -<%= content_tag('div', render(:partial => tab[:partial]), - :id => "tab-content-#{tab[:name]}", - :style => (tab[:name] != selected_tab ? 'display:none' : nil), - :class => 'tab-content') %> -<% end -%> +<%= render_tabs user_settings_tabs %> <% html_title(l(:label_user), @user.login, l(:label_administration)) -%>