Use a hash with attributes to mimick not-yet-existing objects.
This commit is contained in:
parent
6fa7334919
commit
a75aa40389
46
stoptime.rb
46
stoptime.rb
|
@ -265,7 +265,7 @@ module StopTime::Controllers
|
||||||
@customer = Customer.find(customer_id)
|
@customer = Customer.find(customer_id)
|
||||||
@edit_task = true
|
@edit_task = true
|
||||||
@target = [CustomersN, @customer.id]
|
@target = [CustomersN, @customer.id]
|
||||||
@input = @customer
|
@input = @customer.attributes
|
||||||
render :customer_form
|
render :customer_form
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -330,7 +330,8 @@ module StopTime::Controllers
|
||||||
@task = Task.new(:hourly_rate => @customer.hourly_rate)
|
@task = Task.new(:hourly_rate => @customer.hourly_rate)
|
||||||
@target = [CustomersNTasks, customer_id]
|
@target = [CustomersNTasks, customer_id]
|
||||||
@method = "create"
|
@method = "create"
|
||||||
@input = @task
|
@input = @task.attributes
|
||||||
|
@input["task_type"] = @task.task_type # FIXME: find nicer way!
|
||||||
render :task_form
|
render :task_form
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -341,7 +342,8 @@ module StopTime::Controllers
|
||||||
@task = Task.find(task_id)
|
@task = Task.find(task_id)
|
||||||
@target = [CustomersNTasksN, customer_id, task_id]
|
@target = [CustomersNTasksN, customer_id, task_id]
|
||||||
@method = "update"
|
@method = "update"
|
||||||
@input = @task
|
@input = @task.attributes
|
||||||
|
@input["task_type"] = @task.task_type
|
||||||
# FIXME: Check that task is of that customer.
|
# FIXME: Check that task is of that customer.
|
||||||
render :task_form
|
render :task_form
|
||||||
end
|
end
|
||||||
|
@ -367,7 +369,8 @@ module StopTime::Controllers
|
||||||
@errors = @task.errors
|
@errors = @task.errors
|
||||||
@target = [CustomersNTasksN, customer_id, task_id]
|
@target = [CustomersNTasksN, customer_id, task_id]
|
||||||
@method = "update"
|
@method = "update"
|
||||||
@input = @task
|
@input = @task.attributes
|
||||||
|
@input["task_type"] = @input.task_type
|
||||||
return render :task_form
|
return render :task_form
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -471,7 +474,7 @@ module StopTime::Controllers
|
||||||
class Company
|
class Company
|
||||||
def get
|
def get
|
||||||
@company = CompanyInfo.first
|
@company = CompanyInfo.first
|
||||||
@input = @company
|
@input = @company.attributes
|
||||||
render :company_form
|
render :company_form
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -559,23 +562,24 @@ module StopTime::Views
|
||||||
:value => DateTime.now.to_date.to_formatted_s + " " }
|
:value => DateTime.now.to_date.to_formatted_s + " " }
|
||||||
td { input :type => :text, :name => "comment" }
|
td { input :type => :text, :name => "comment" }
|
||||||
td { "N/A" }
|
td { "N/A" }
|
||||||
td { _form_input_checkbox("bill", "bill") }
|
td { _form_input_checkbox("bill") }
|
||||||
td do
|
td do
|
||||||
input :type => :submit, :name => "enter", :value => "Enter"
|
input :type => :submit, :name => "enter", :value => "Enter"
|
||||||
input :type => :reset, :name => "clear", :value => "Clear"
|
input :type => :reset, :name => "clear", :value => "Clear"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@time_entries.each do |entry|
|
@entries.each do |entry|
|
||||||
tr do
|
tr do
|
||||||
td { a entry.customer.short_name,
|
td { a entry.customer.short_name,
|
||||||
:href => R(CustomersN, entry.customer.id) }
|
:href => R(CustomersN, entry.customer.id) }
|
||||||
td { a entry.task.name,
|
td { a entry.task.name,
|
||||||
:href => R(CustomersNTasksN, entry.customer.id, entry.task.id) }
|
:href => R(CustomersNTasksN, entry.customer.id, entry.task.id) }
|
||||||
td { entry.start }
|
td { a entry.start,
|
||||||
|
:href => R(TimeregN, entry.id) }
|
||||||
td { entry.end }
|
td { entry.end }
|
||||||
td { entry.comment }
|
td { entry.comment }
|
||||||
td { "%.2fh" % ((entry.end - entry.start)/3600.0) }
|
td { "%.2fh" % entry.total }
|
||||||
td do
|
td do
|
||||||
if entry.bill
|
if entry.bill
|
||||||
input :type => "checkbox", :name => "bill_#{entry.id}",
|
input :type => "checkbox", :name => "bill_#{entry.id}",
|
||||||
|
@ -677,13 +681,9 @@ module StopTime::Views
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
li do
|
li do
|
||||||
if @input.billed?
|
_form_input_checkbox("billed")
|
||||||
input :type => :checkbox, :name => "billed", :checked => true
|
label "Billed!", :for => "billed"
|
||||||
else
|
|
||||||
input :type => :checkbox, :name => "billed"
|
|
||||||
end
|
|
||||||
span "Billed"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
input :type => "submit", :name => @method, :value => @method.capitalize
|
input :type => "submit", :name => @method, :value => @method.capitalize
|
||||||
|
@ -795,11 +795,11 @@ module StopTime::Views
|
||||||
def _form_input_with_label(label_name, input_name, type)
|
def _form_input_with_label(label_name, input_name, type)
|
||||||
label label_name, :for => input_name
|
label label_name, :for => input_name
|
||||||
input :type => type, :name => input_name, :id => input_name,
|
input :type => type, :name => input_name, :id => input_name,
|
||||||
:value => @input.send(input_name)
|
:value => @input[input_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
def _form_input_radio(name, value, default=false)
|
def _form_input_radio(name, value, default=false)
|
||||||
input_val = @input.send(name)
|
input_val = @input[name]
|
||||||
if input_val == value or (input_val.blank? and default)
|
if input_val == value or (input_val.blank? and default)
|
||||||
input :type => "radio", :id => "#{name}_#{value}",
|
input :type => "radio", :id => "#{name}_#{value}",
|
||||||
:name => name, :value => value, :checked => true
|
:name => name, :value => value, :checked => true
|
||||||
|
@ -809,12 +809,12 @@ module StopTime::Views
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _form_input_checkbox(name, value="true")
|
def _form_input_checkbox(name, value=true)
|
||||||
if @input.send(name) == value
|
if @input[name] == value
|
||||||
input :type => "checkbox", :id => name, :name => name,
|
input :type => "checkbox", :id => "#{name}_#{value}", :name => name,
|
||||||
:value => value, :checked => true
|
:value => value, :checked => true
|
||||||
else
|
else
|
||||||
input :type => "checkbox", :id => name, :name => name,
|
input :type => "checkbox", :id => "#{name}_#{value}", :name => name,
|
||||||
:value => value
|
:value => value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -822,7 +822,7 @@ module StopTime::Views
|
||||||
def _form_select(name, opts_list)
|
def _form_select(name, opts_list)
|
||||||
select :name => name, :id => name do
|
select :name => name, :id => name do
|
||||||
opts_list.each do |opt_val, opt_str|
|
opts_list.each do |opt_val, opt_str|
|
||||||
if @input.send(name) == opt_val
|
if @input[name] == opt_val
|
||||||
option opt_str, :value => opt_val, :selected => true
|
option opt_str, :value => opt_val, :selected => true
|
||||||
else
|
else
|
||||||
option opt_str, :value => opt_val
|
option opt_str, :value => opt_val
|
||||||
|
|
Loading…
Reference in New Issue