From bd706c91a7825a25437707e2a4a09a6586a629cf Mon Sep 17 00:00:00 2001
From: Per Cederqvist <ceder@lysator.liu.se>
Date: Fri, 18 Aug 2006 17:24:49 +0000
Subject: [PATCH] Make a list partial for listing RecurringItemRanges, and fix
 it.

---
 app/views/recurring_item_ranges/_list.rhtml | 63 +++++++++++++++++++++
 app/views/recurring_item_ranges/list.rhtml  | 19 +------
 2 files changed, 64 insertions(+), 18 deletions(-)
 create mode 100644 app/views/recurring_item_ranges/_list.rhtml

diff --git a/app/views/recurring_item_ranges/_list.rhtml b/app/views/recurring_item_ranges/_list.rhtml
new file mode 100644
index 0000000..7aafc35
--- /dev/null
+++ b/app/views/recurring_item_ranges/_list.rhtml
@@ -0,0 +1,63 @@
+<% ignored_columns = [] %>
+<% sorted_columns = ["recurring_item_id", "startdate", "enddate",
+   		     "amount", "schedule_id"] %>
+
+<% for column in RecurringItemRange.content_columns %>
+  <% if not (ignored_columns + sorted_columns).include?(column.name) %>
+    <% sorted_columns << column.name %>
+  <% end %>
+<% end %>
+
+<table border="1">
+  <tr>
+    <th colspan="2">&nbsp;</th>
+    <% for column_name in sorted_columns %>
+      <% puts column_name %>
+      <th><%= RecurringItemRange.columns_hash[column_name].human_name %></th>
+    <%end%>
+    <th>&nbsp;</th>
+  </tr>
+  
+<% for recurring_item_range in @recurring_item_ranges %>
+  <tr>
+    <td><%= link_to 'Edit', :action => 'edit', :id => recurring_item_range %></td>
+    <td><%= link_to 'Show', :action => 'show', :id => recurring_item_range %></td>
+
+    <% for column_name in sorted_columns %>
+      <td class="<%= column_name %>">
+        <% case column_name
+	   when "startdate": %>
+	  <%= recurring_item_range["startdate"].strftime("%Y-%m-%d") %>
+	<% when "enddate": %>
+	  <% if recurring_item_range["enddate"].nil? %>
+	    ---
+	  <% else %>
+	    <%= recurring_item_range["startdate"].strftime("%Y-%m-%d") %>
+	  <% end %>
+	<% when "schedule_id": %>
+	  <% if recurring_item_range.schedule.nil? %>
+	    &nbsp;
+          <% else %>
+	    <%=h recurring_item_range.schedule.name %>
+	  <% end %>
+	<% when "recurring_item_id": %>
+	  <% if recurring_item_range.recurring_item.nil? %>
+	    ---
+          <% else %>
+	    <%=h recurring_item_range.recurring_item.description %>
+	  <% end %>
+	<% else %>
+	  <% if recurring_item_range[column_name].to_s != "" %>
+            <%=h recurring_item_range.send(column_name) %>
+	  <% else %>
+	    &nbsp;
+          <% end %>
+	<% end %>
+      </td>
+    <% end %>
+
+    <td><%= link_to 'Destroy', { :action => 'destroy', :id => recurring_item_range }, :confirm => 'Are you sure?', :post => true %></td>
+
+  </tr>
+<% end %>
+</table>
diff --git a/app/views/recurring_item_ranges/list.rhtml b/app/views/recurring_item_ranges/list.rhtml
index 601a314..35ea6ea 100644
--- a/app/views/recurring_item_ranges/list.rhtml
+++ b/app/views/recurring_item_ranges/list.rhtml
@@ -1,23 +1,6 @@
 <% @heading = "Listing recurring_item_ranges" %>
 
-<table>
-  <tr>
-  <% for column in RecurringItemRange.content_columns %>
-    <th><%= column.human_name %></th>
-  <% end %>
-  </tr>
-  
-<% for recurring_item_range in @recurring_item_ranges %>
-  <tr>
-  <% for column in RecurringItemRange.content_columns %>
-    <td><%=h recurring_item_range.send(column.name) %></td>
-  <% end %>
-    <td><%= link_to 'Show', :action => 'show', :id => recurring_item_range %></td>
-    <td><%= link_to 'Edit', :action => 'edit', :id => recurring_item_range %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => recurring_item_range }, :confirm => 'Are you sure?', :post => true %></td>
-  </tr>
-<% end %>
-</table>
+<%= render :partial => 'list' %>
 
 <%= link_to 'Previous page', { :page => @recurring_item_range_pages.current.previous } if @recurring_item_range_pages.current.previous %>
 <%= link_to 'Next page', { :page => @recurring_item_range_pages.current.next } if @recurring_item_range_pages.current.next %> 
-- 
GitLab