Allow for changing the customer of a task; fixed form preseeding here and there
This commit is contained in:
parent
ed90dad0c2
commit
d8538ec1d2
21
stoptime.rb
21
stoptime.rb
|
@ -611,6 +611,9 @@ module StopTime::Controllers
|
||||||
if @task.invalid?
|
if @task.invalid?
|
||||||
@errors = @task.errors
|
@errors = @task.errors
|
||||||
@customer = Customer.find(customer_id)
|
@customer = Customer.find(customer_id)
|
||||||
|
@customer_list = Customer.all.map do |c|
|
||||||
|
[c.id, c.short_name.present? ? c.short_name : c.name]
|
||||||
|
end
|
||||||
@target = [CustomersNTasks, customer_id]
|
@target = [CustomersNTasks, customer_id]
|
||||||
@method = "create"
|
@method = "create"
|
||||||
return render :task_form
|
return render :task_form
|
||||||
|
@ -635,6 +638,7 @@ module StopTime::Controllers
|
||||||
@task = Task.new(:hourly_rate => @customer.hourly_rate)
|
@task = Task.new(:hourly_rate => @customer.hourly_rate)
|
||||||
@input = @task.attributes
|
@input = @task.attributes
|
||||||
@input["type"] = @task.type # FIXME: find nicer way!
|
@input["type"] = @task.type # FIXME: find nicer way!
|
||||||
|
@input["customer"] = customer_id
|
||||||
|
|
||||||
@target = [CustomersNTasks, customer_id]
|
@target = [CustomersNTasks, customer_id]
|
||||||
@method = "create"
|
@method = "create"
|
||||||
|
@ -655,11 +659,15 @@ module StopTime::Controllers
|
||||||
# Views#task_form.
|
# Views#task_form.
|
||||||
def get(customer_id, task_id)
|
def get(customer_id, task_id)
|
||||||
@customer = Customer.find(customer_id)
|
@customer = Customer.find(customer_id)
|
||||||
|
@customer_list = Customer.all.map do |c|
|
||||||
|
[c.id, c.short_name.present? ? c.short_name : c.name]
|
||||||
|
end
|
||||||
@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.attributes
|
@input = @task.attributes
|
||||||
@input["type"] = @task.type
|
@input["type"] = @task.type
|
||||||
|
@input["customer"] = customer_id
|
||||||
# FIXME: Check that task is of that customer.
|
# FIXME: Check that task is of that customer.
|
||||||
render :task_form
|
render :task_form
|
||||||
end
|
end
|
||||||
|
@ -671,10 +679,9 @@ module StopTime::Controllers
|
||||||
# and shown in the intial form (Views#task_form).
|
# and shown in the intial form (Views#task_form).
|
||||||
def post(customer_id, task_id)
|
def post(customer_id, task_id)
|
||||||
return redirect R(CustomersN, customer_id) if @input.cancel
|
return redirect R(CustomersN, customer_id) if @input.cancel
|
||||||
@customer = Customer.find(customer_id)
|
|
||||||
@task = Task.find(task_id)
|
@task = Task.find(task_id)
|
||||||
if @input.has_key? "update"
|
if @input.has_key? "update"
|
||||||
# FIXME: task should be cloned/dupped as to prevent rewriting history!
|
@task["customer"] = Customer.find(@input["customer"])
|
||||||
@task["name"] = @input["name"] unless @input["name"].blank?
|
@task["name"] = @input["name"] unless @input["name"].blank?
|
||||||
case @input.type
|
case @input.type
|
||||||
when "fixed_cost"
|
when "fixed_cost"
|
||||||
|
@ -687,10 +694,12 @@ module StopTime::Controllers
|
||||||
@task.save
|
@task.save
|
||||||
if @task.invalid?
|
if @task.invalid?
|
||||||
@errors = @task.errors
|
@errors = @task.errors
|
||||||
|
@customer = Customer.find(customer_id)
|
||||||
|
@customer_list = Customer.all.map do |c|
|
||||||
|
[c.id, c.short_name.present? ? c.short_name : c.name]
|
||||||
|
end
|
||||||
@target = [CustomersNTasksN, customer_id, task_id]
|
@target = [CustomersNTasksN, customer_id, task_id]
|
||||||
@method = "update"
|
@method = "update"
|
||||||
@input = @task.attributes
|
|
||||||
@input["type"] = @input.type
|
|
||||||
return render :task_form
|
return render :task_form
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1432,6 +1441,10 @@ module StopTime::Views
|
||||||
h2 "Task Information"
|
h2 "Task Information"
|
||||||
form :action => R(*@target), :method => :post do
|
form :action => R(*@target), :method => :post do
|
||||||
ol do
|
ol do
|
||||||
|
li do
|
||||||
|
label "Customer", :for => "customer"
|
||||||
|
_form_select("customer", @customer_list)
|
||||||
|
end
|
||||||
li { _form_input_with_label("Name", "name", :text) }
|
li { _form_input_with_label("Name", "name", :text) }
|
||||||
li do
|
li do
|
||||||
label "Project/Task type"
|
label "Project/Task type"
|
||||||
|
|
Loading…
Reference in New Issue