Permalink
Browse files

Added functionality to add multiple replacements whil creating a cont…

…ract:

A person can easily replace two people with one contract. This contract therefore has then two titulars.

Added some navigation
  • Loading branch information...
andycapiaugb committed Mar 31, 2011
1 parent 2efcaee commit c933a723c00472780005a43d865374124afb1657
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -9,12 +9,12 @@ def show
def new
@contract = Contract.new
+ 2.times {@contract.replacements.build}
end
def create
@contract = Contract.new(params[:contract])
if @contract.save
- @contract.replaces!(Contract.find(params[:replaced_contract][:id]))
flash[:notice] = "Contract saved :)"
redirect_to employees_url
end
View
@@ -18,4 +18,10 @@ def end_replacement!(replaced_contract)
def description
"#{self.function.name unless self.function.nil?} - #{self.employee.name_with_employee_number unless self.employee.nil?}"
end
+
+ def replaced_contracts=(replaced_contracts)
+ replaced_contracts.each do |replaced_contract|
+ self.replacements.build({:replacer_id => self.id, :replaced_id => replaced_contract[:id]})
+ end
+ end
end
@@ -1,9 +1,11 @@
-<div class="field">
- <%= fields_for :replaced_contract do |contract_replacement_form| %>
+<% contract.replacements.each do |replacement| %>
+ <%= fields_for "contract[replaced_contracts][]", replacement do |contract_replacement_form| %>
+ <div class="field">
<%= contract_replacement_form.label :replaces %>
<%= contract_replacement_form.select(:id, Contract.all.collect {|p| [ p.description, p.id ] }, {:include_blank => true}) %>
+ </div>
<% end %>
-</div>
+<% end %>
<div class="field">
<%= f.label :number %>
@@ -1,6 +1,6 @@
<h1>New Contract</h1>
<%= form_for @contract do |f| %>
- <%= render 'fields', :f => f %>
+ <%= render 'fields', {:f => f, :contract => @contract} %>
<div class="actions">
<%= f.submit "Save" %>
</div>
@@ -43,21 +43,20 @@
<td><%= c.end %></td>
</tr>
<tr>
- <% if not c.replacing.empty? %>
- <th>Replaces</th>
- <td>
- <% c.replacing.each do |r| %>
- <%= link_to "#{r.employee.name}", employee_url(r.employee.id) %>
- <% end %>
- </td>
- <% elsif not c.replacers.empty? %>
- <th>Replaced by</th>
- <td>
- <% c.replacers.each do |r| %>
- <%= link_to "#{r.employee.name}", employee_url(r.employee.id) %>
- <% end %>
- </td>
- <% end %>
+ <th>Replaces</th>
+ <td>
+ <% c.replacing.each do |r| %>
+ <%= link_to "#{r.employee.name}", employee_url(r.employee.id) %>
+ <% end %>
+ </td>
+ </tr>
+ <tr>
+ <th>Replaced by</th>
+ <td>
+ <% c.replacers.each do |r| %>
+ <%= link_to "#{r.employee.name}", employee_url(r.employee.id) %>
+ <% end %>
+ </td>
</tr>
<tr>
@@ -15,10 +15,11 @@
<div class="round"><%= image_tag "logo.gif", :class => "round" %> Personeelsbeheer</div>
<nav class="round">
<ul>
- <li></li>
- <li></li>
- <li></li>
- <li></li>
+ <li><%= link_to "Nieuwe Persoon", new_person_url %></li>
+ <li><%= link_to "Werknemers", employees_url %></li>
+ <li><%= link_to "Nieuwe Werknemer", new_employee_url %></li>
+ <li><%= link_to "Nieuwe Functie", new_function_url %></li>
+ <li><%= link_to "Nieuw Contract", new_contract_url %></li>
</ul>
</nav>
</header>

0 comments on commit c933a72

Please sign in to comment.