[#4177] Refactored new Contract form to be used with editing a contract.

This commit is contained in:
Eric Davis
2010-06-21 14:25:48 -07:00
parent 5bdbf4e75f
commit c6783f98fd
8 changed files with 82 additions and 29 deletions
+5 -1
View File
@@ -9,7 +9,11 @@ class ContractsController < InheritedResources::Base
def create
create! { contract_url(@project, resource) }
end
def update
update! { contract_url(@project, resource) }
end
protected
def begin_of_association_chain
+1 -1
View File
@@ -38,7 +38,7 @@ class Contract < ActiveRecord::Base
def payment_terms_for_select
PaymentTerms.collect {|value, label|
[l(label), value]
[l(label), value.to_s]
}
end
+26
View File
@@ -0,0 +1,26 @@
<% form.inputs do %>
<%= form.input :name, :required => true %>
<%= form.input :account_executive, :required => true %>
<li class="boolean optional">
<%= label('contract', 'executed') %>
<%= check_box 'contract', 'executed' %>
</li>
<%= form.input :start_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_start_date') %>
<%= form.input :end_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_end_date') %>
<%= form.input :billable_rate, :input_html => {:size => 20}, :hint => l(:field_billable_rate_hint) %>
<%= form.input :discount, :input_html => {:size => 20}, :hint => l(:field_discount_hint) %>
<%= form.input :discount_note, :input_html => {:class => 'wiki-edit', :rows => '5'} %>
<%= form.input :payment_terms, :as => :select, :collection => resource.payment_terms_for_select %>
<%= form.input :client_ap_contact_information, :input_html => {:class => 'wiki-edit', :rows => '5'} %>
<%= form.input :po_number %>
<%= form.input :details, :input_html => {:class => 'wiki-edit'} %>
<% end %>
<% form.buttons do %>
<%= form.commit_button %>
<%= link_to(l(:button_cancel), contracts_path) %>
<% end %>
<%= wikitoolbar_for 'contract_discount_note' %>
<%= wikitoolbar_for 'contract_client_ap_contact_information' %>
<%= wikitoolbar_for 'contract_details' %>
+9
View File
@@ -0,0 +1,9 @@
<%= content_tag(:h2, h(resource.name)) %>
<% semantic_form_for resource, :url => contract_path(@project, resource), :html => {:class => 'tabular'} do |form| %>
<%= render :partial => 'form', :object => form %>
<% end %>
<% content_for(:header_tags) do %>
<%= stylesheet_link_tag "redmine_contracts", :plugin => "redmine_contracts", :media => "screen" %>
<% end %>
+1 -26
View File
@@ -1,33 +1,8 @@
<%= content_tag(:h2, l(:text_new_contract)) %>
<% semantic_form_for resource, :html => {:class => 'tabular'} do |form| %>
<% form.inputs do %>
<%= form.input :name, :required => true %>
<%= form.input :account_executive, :required => true %>
<li class="boolean optional">
<%= label('contract', 'executed') %>
<%= check_box 'contract', 'executed' %>
</li>
<%= form.input :start_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_start_date') %>
<%= form.input :end_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_end_date') %>
<%= form.input :billable_rate, :input_html => {:size => 20}, :hint => l(:field_billable_rate_hint) %>
<%= form.input :discount, :input_html => {:size => 20}, :hint => l(:field_discount_hint) %>
<%= form.input :discount_note, :input_html => {:class => 'wiki-edit', :rows => '5'} %>
<%= form.input :payment_terms, :as => :select, :collection => resource.payment_terms_for_select %>
<%= form.input :client_ap_contact_information, :input_html => {:class => 'wiki-edit', :rows => '5'} %>
<%= form.input :po_number %>
<%= form.input :details, :input_html => {:class => 'wiki-edit'} %>
<%= render :partial => 'form', :object => form %>
<% end %>
<% form.buttons do %>
<%= form.commit_button %>
<%= link_to(l(:button_cancel), contracts_path) %>
<% end %>
<% end %>
<%= wikitoolbar_for 'contract_discount_note' %>
<%= wikitoolbar_for 'contract_client_ap_contact_information' %>
<%= wikitoolbar_for 'contract_details' %>
<% content_for(:header_tags) do %>
<%= stylesheet_link_tag "redmine_contracts", :plugin => "redmine_contracts", :media => "screen" %>
+2
View File
@@ -13,3 +13,5 @@
<%= content_tag(:p, h(resource.po_number)) %>
<%= content_tag(:p, h(resource.details)) %>
<% end %>
<%= link_to(l(:button_update), edit_contract_path(@project, resource)) %>
+1 -1
View File
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_contracts do
requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0'
project_module :contracts do
permission :manage_budget, {:contracts => [:index, :new, :create, :show] }, :public => true
permission :manage_budget, {:contracts => [:index, :new, :create, :show, :edit, :update] }, :public => true
end
menu(:project_menu,
+37
View File
@@ -0,0 +1,37 @@
require 'test_helper'
class ContractsEditTest < ActionController::IntegrationTest
include Redmine::I18n
def setup
@project = Project.generate!(:identifier => 'main')
@contract = Contract.generate!(:project => @project, :name => 'A Contract', :payment_terms => 'net_15')
end
should "allow any user to edit the contract" do
visit_contracts_for_project(@project)
click_link @contract.id
assert_response :success
click_link 'Update'
assert_response :success
assert_template 'contracts/edit'
assert_select "h2", :text => @contract.name
assert_select "form#edit_contract_#{@contract.id}.contract" do
assert_select "input[value=?]", /#{@contract.name}/
assert_select "select#contract_payment_terms" do
assert_select "option[selected=selected][value=net_15]"
end
end
fill_in "Name", :with => 'An updated name'
click_button "Update Contract"
assert_response :success
assert_template 'contracts/show'
assert_equal "An updated name", @contract.reload.name
end
end