]> source.dussan.org Git - redmine.git/commitdiff
Refactoring of tabs rendering.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Sep 2009 09:13:13 +0000 (09:13 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 12 Sep 2009 09:13:13 +0000 (09:13 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2871 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/helpers/custom_fields_helper.rb
app/views/common/_tabs.rhtml [new file with mode: 0644]
app/views/custom_fields/_index.rhtml [new file with mode: 0644]
app/views/custom_fields/index.rhtml
app/views/groups/edit.html.erb
app/views/projects/settings.rhtml
app/views/settings/edit.rhtml
app/views/users/edit.rhtml

index 581ea2fe81d206107d58aac7076726fa1687272b..3f96c7deaa5e42b23a0ae7ad43b0337a09f977b7 100644 (file)
@@ -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
index eb39b4c0a4d376ac1d198110559c055fc825504f..f97b9238b58a4a2294a6f05c8b3a7a9b5b442370 100644 (file)
 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 (file)
index 0000000..f9ef5dd
--- /dev/null
@@ -0,0 +1,19 @@
+<% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %>
+
+<div class="tabs">
+  <ul>
+  <% tabs.each do |tab| -%>
+    <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
+                                    :id => "tab-#{tab[:name]}",
+                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
+                                    :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
+  <% end -%>
+  </ul>
+</div>
+
+<% 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 (file)
index 0000000..1417dd4
--- /dev/null
@@ -0,0 +1,32 @@
+<table class="list">
+  <thead><tr>
+       <th width="30%"><%=l(:field_name)%></th>
+       <th><%=l(:field_field_format)%></th>
+       <th><%=l(:field_is_required)%></th>
+       <% if tab[:name] == 'IssueCustomField' %>
+       <th><%=l(:field_is_for_all)%></th>
+       <th><%=l(:label_used_by)%></th>
+       <% end %>
+       <th><%=l(:button_sort)%></th>
+       <th width="10%"></th>
+  </tr></thead>
+  <tbody>
+       <% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%>
+               <tr class="<%= cycle("odd", "even") %>">
+                       <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
+                       <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
+                       <td align="center"><%= image_tag 'true.png' if custom_field.is_required? %></td>
+                       <% if tab[:name] == 'IssueCustomField' %>
+                       <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
+                       <td align="center"><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
+                       <% end %>
+                 <td align="center" style="width:15%;"><%= reorder_links('custom_field', {:action => 'edit', :id => custom_field}) %></td>
+                       <td align="center">
+                               <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
+                 </td>
+               </tr>
+       <% end; reset_cycle %>
+  </tbody>
+</table>
+
+<p><%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %></p>
index 999648f0e09c46aabeab6b3bc7f4e916e2a22e74..7b29e25e797a49467652a8849edca4fffe896464 100644 (file)
@@ -1,53 +1,5 @@
 <h2><%=l(:label_custom_field_plural)%></h2>
 
-<% selected_tab = params[:tab] ? params[:tab].to_s : custom_fields_tabs.first[:name] %>
-
-<div class="tabs">
-<ul>
-<% custom_fields_tabs.each do |tab| -%>
-    <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
-                                    :id => "tab-#{tab[:name]}",
-                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
-                                    :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
-<% end -%>
-</ul>
-</div>
-
-<% custom_fields_tabs.each do |tab| %>
-<div id="tab-content-<%= tab[:name] %>" class="tab-content" style="<%= tab[:name] != selected_tab ? 'display:none' : nil %>">
-<table class="list">           
-  <thead><tr>  
-       <th width="30%"><%=l(:field_name)%></th>
-       <th><%=l(:field_field_format)%></th>
-       <th><%=l(:field_is_required)%></th>
-       <% if tab[:name] == 'IssueCustomField' %>
-       <th><%=l(:field_is_for_all)%></th>
-       <th><%=l(:label_used_by)%></th>
-       <% end %>
-       <th><%=l(:button_sort)%></th>
-       <th width="10%"></th>
-  </tr></thead>
-  <tbody>
-<% (@custom_fields_by_type[tab[:name]] || []).sort.each do |custom_field| -%>
-  <tr class="<%= cycle("odd", "even") %>">
-       <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
-       <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
-       <td align="center"><%= image_tag 'true.png' if custom_field.is_required? %></td>
-       <% if tab[:name] == 'IssueCustomField' %>
-       <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
-       <td align="center"><%= l(:label_x_projects, :count => custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
-       <% end %>
-    <td align="center" style="width:15%;"><%= reorder_links('custom_field', {:action => 'edit', :id => custom_field}) %></td>
-       <td align="center">
-          <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
-    </td>
-  </tr>
-<% end; reset_cycle %>
-  </tbody>
-</table>
-
-<p><%= link_to l(:label_custom_field_new), {:action => 'new', :type => tab[:name]}, :class => 'icon icon-add' %></p>
-</div>
-<% end %>
+<%= render_tabs custom_fields_tabs %>
 
 <% html_title(l(:label_custom_field_plural)) -%>
index 93e890887056ebf9642d8fa220dfe39998d3b52a..e6daa5a099a64aabbff0902f5ce48e0d5a5afcfe 100644 (file)
@@ -1,23 +1,5 @@
 <h2><%= link_to l(:label_group_plural), groups_path %> &#187; <%= h(@group) %></h2>
 
-<% selected_tab = params[:tab] ? params[:tab].to_s : group_settings_tabs.first[:name] %>
-
-<div class="tabs">
-<ul>
-<% group_settings_tabs.each do |tab| -%>
-    <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
-                                    :id => "tab-#{tab[:name]}",
-                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
-                                    :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
-<% end -%>
-</ul>
-</div>
-
-<% 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)) -%>
index e8be1a091122f77019491c78de9e6fc704a57b8a..eefcb7b0693bf6c6debd3b2069428a3106b4cc9e 100644 (file)
@@ -1,29 +1,5 @@
 <h2><%=l(:label_settings)%></h2>
 
-<% tabs = project_settings_tabs %>
-
-<% if tabs.any? %>
-<% selected_tab = params[:tab] ? params[:tab].to_s : tabs.first[:name] %>
-
-<div class="tabs">
-<ul>
-<% tabs.each do |tab| -%>
-    <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
-                                    :id => "tab-#{tab[:name]}",
-                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
-                                    :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
-<% end -%>
-</ul>
-</div>
-
-<% 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 %>
-<p class="nodata"><%= l(:label_no_data) %></p>
-<% end %>
+<%= render_tabs project_settings_tabs %>
 
 <% html_title(l(:label_settings)) -%>
index c99a139604c6e62b4e59a5e6f10be5d437edf9f8..de64e3bb2c431c040ce0908b72729a2b6e5b65d3 100644 (file)
@@ -1,23 +1,5 @@
 <h2><%= l(:label_settings) %></h2>
 
-<% selected_tab = params[:tab] ? params[:tab].to_s : administration_settings_tabs.first[:name] %>
-
-<div class="tabs">
-<ul>
-<% administration_settings_tabs.each do |tab| -%>
-    <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
-                                    :id => "tab-#{tab[:name]}",
-                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
-                                    :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
-<% end -%>
-</ul>
-</div>
-
-<% 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)) -%>
index 96e089c15407f1aa6873a4886fae0eac5d2fb671..b67ccc2be2756b219af20272845c81570a05fdd8 100644 (file)
@@ -4,24 +4,6 @@
 
 <h2><%= link_to l(:label_user_plural), :controller => 'users', :action => 'index' %> &#187; <%=h @user.login %></h2>
 
-<% selected_tab = params[:tab] ? params[:tab].to_s : user_settings_tabs.first[:name] %>
-
-<div class="tabs">
-<ul>
-<% user_settings_tabs.each do |tab| -%>
-    <li><%= link_to l(tab[:label]), { :tab => tab[:name] },
-                                    :id => "tab-#{tab[:name]}",
-                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
-                                    :onclick => "showTab('#{tab[:name]}'); this.blur(); return false;" %></li>
-<% end -%>
-</ul>
-</div>
-
-<% 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)) -%>