Refactor: move helper methods to a formatter module
This commit is contained in:
@@ -7,6 +7,8 @@ class ContractsController < InheritedResources::Base
|
||||
before_filter :authorize
|
||||
before_filter :require_admin, :only => :destroy
|
||||
|
||||
helper :contract_formatter
|
||||
|
||||
def create
|
||||
create! do |success, failure|
|
||||
success.html { redirect_to contract_url(@project, resource) }
|
||||
|
||||
@@ -7,6 +7,7 @@ class DeliverablesController < InheritedResources::Base
|
||||
before_filter :authorize
|
||||
|
||||
helper :contracts
|
||||
helper :contract_formatter
|
||||
|
||||
def index
|
||||
redirect_to contract_url(@project, @contract)
|
||||
|
||||
54
app/helpers/contract_formatter_helper.rb
Normal file
54
app/helpers/contract_formatter_helper.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
# Formatting helpers
|
||||
module ContractFormatterHelper
|
||||
def format_as_yes_or_no(value)
|
||||
if value
|
||||
l(:general_text_Yes)
|
||||
else
|
||||
l(:general_text_No)
|
||||
end
|
||||
end
|
||||
|
||||
def format_budget_for_deliverable(deliverable, spent, total, options={})
|
||||
extra_css_class = options[:class] || ''
|
||||
|
||||
if total > 0 || spent > 0
|
||||
spent_css_classes = 'spent-amount'
|
||||
spent_css_classes << " #{overage_class(spent, total)}"
|
||||
spent_css_classes << ' ' << extra_css_class
|
||||
total_css_classes = 'total-amount white'
|
||||
total_css_classes << ' ' << extra_css_class
|
||||
|
||||
content_tag(:td, h(format_value_field_for_contracts(spent)), :class => spent_css_classes) +
|
||||
content_tag(:td, h(format_value_field_for_contracts(total)), :class => total_css_classes)
|
||||
else
|
||||
content_tag(:td, '----', :colspan => '2', :class => 'no-value ' + extra_css_class)
|
||||
end
|
||||
end
|
||||
|
||||
def format_deliverable_value_fields(value)
|
||||
number_with_precision(value, :precision => Deliverable::ViewPrecision, :delimiter => '')
|
||||
end
|
||||
|
||||
def format_deliverable_value_fields_as_dollar_or_percent(value)
|
||||
if value.to_s.match('%')
|
||||
h(value)
|
||||
else # currency or straight amount
|
||||
number_to_currency(value.to_s.gsub('$',''), :precision => Deliverable::ViewPrecision, :delimiter => '', :unit => '$')
|
||||
end
|
||||
end
|
||||
|
||||
def format_hourly_rate(decimal)
|
||||
number_to_currency(decimal, :precision => 0) + "/hr" if decimal
|
||||
end
|
||||
|
||||
def format_payment_terms(value)
|
||||
return '' if value.blank?
|
||||
return h(value.name)
|
||||
end
|
||||
|
||||
def format_value_field_for_contracts(value, options={})
|
||||
opt = {:unit => '', :precision => Contract::ViewPrecision, :delimiter => ','}.merge(options)
|
||||
number_to_currency(value, opt)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -7,23 +7,6 @@ module ContractsHelper
|
||||
end
|
||||
end
|
||||
|
||||
def format_budget_for_deliverable(deliverable, spent, total, options={})
|
||||
extra_css_class = options[:class] || ''
|
||||
|
||||
if total > 0 || spent > 0
|
||||
spent_css_classes = 'spent-amount'
|
||||
spent_css_classes << " #{overage_class(spent, total)}"
|
||||
spent_css_classes << ' ' << extra_css_class
|
||||
total_css_classes = 'total-amount white'
|
||||
total_css_classes << ' ' << extra_css_class
|
||||
|
||||
content_tag(:td, h(format_value_field_for_contracts(spent)), :class => spent_css_classes) +
|
||||
content_tag(:td, h(format_value_field_for_contracts(total)), :class => total_css_classes)
|
||||
else
|
||||
content_tag(:td, '----', :colspan => '2', :class => 'no-value ' + extra_css_class)
|
||||
end
|
||||
end
|
||||
|
||||
# Simple helper to show the values of a field on an object in a standard format
|
||||
#
|
||||
# <p>
|
||||
@@ -81,40 +64,6 @@ module ContractsHelper
|
||||
end
|
||||
end
|
||||
|
||||
def format_hourly_rate(decimal)
|
||||
number_to_currency(decimal, :precision => 0) + "/hr" if decimal
|
||||
end
|
||||
|
||||
def format_payment_terms(value)
|
||||
return '' if value.blank?
|
||||
return h(value.name)
|
||||
end
|
||||
|
||||
def format_deliverable_value_fields(value)
|
||||
number_with_precision(value, :precision => Deliverable::ViewPrecision, :delimiter => '')
|
||||
end
|
||||
|
||||
def format_deliverable_value_fields_as_dollar_or_percent(value)
|
||||
if value.to_s.match('%')
|
||||
h(value)
|
||||
else # currency or straight amount
|
||||
number_to_currency(value.to_s.gsub('$',''), :precision => Deliverable::ViewPrecision, :delimiter => '', :unit => '$')
|
||||
end
|
||||
end
|
||||
|
||||
def format_value_field_for_contracts(value, options={})
|
||||
opt = {:unit => '', :precision => Contract::ViewPrecision, :delimiter => ','}.merge(options)
|
||||
number_to_currency(value, opt)
|
||||
end
|
||||
|
||||
def format_as_yes_or_no(value)
|
||||
if value
|
||||
l(:general_text_Yes)
|
||||
else
|
||||
l(:general_text_No)
|
||||
end
|
||||
end
|
||||
|
||||
def retainer_period_options(deliverable, method_options={})
|
||||
selected = method_options[:selected]
|
||||
if selected && selected.is_a?(Date)
|
||||
|
||||
Reference in New Issue
Block a user