Browse Source

Finished adding default Bike task list

denney-disable-on-select
Jason Denney 12 years ago
parent
commit
ad26dab160
  1. 25
      app/components/tasks.rb
  2. 6
      app/models/bike.rb
  3. 12
      app/models/task_list.rb
  4. 8
      db/defaults/bike_tasks.yml

25
app/components/tasks.rb

@ -1,6 +1,13 @@
class Tasks < Netzke::Basepack::Grid
def configure(c)
super
task_list_id = nil
if session[:selected_bike_id]
task_list_id = Bike.find_by_id(session[:selected_bike_id]).task_list.id
end
c.header = false
c.model = "Task"
c.scope = lambda{ |rel|
if session[:selected_bike_id]
@ -10,6 +17,24 @@ class Tasks < Netzke::Basepack::Grid
rel.where(:task_list_id => 0)
end
}
c.strong_default_attrs = {
:task_list_id => task_list_id
}
c.columns = [
:task,
:notes,
:done
]
end
def default_fields_for_forms
fields = []
fields << { :no_binding => true, :xtype => 'displayfield', :fieldLabel => "No Bike Selected", :value => "Select a Bike First!"}
fields.concat( [
:task,
:notes,
:done
])
end
#override with nil to remove actions

6
app/models/bike.rb

@ -27,6 +27,8 @@ class Bike < ActiveRecord::Base
self.per_page = 15
after_save :create_task_list
def brand
self.bike_brand
end
@ -50,4 +52,8 @@ class Bike < ActiveRecord::Base
def to_s
"#{brand} - #{model} - #{style}"
end
def create_task_list
TaskList.create( item_id: self.id, item_type: self.class.to_s, name: "Safety Checklist")
end
end

12
app/models/task_list.rb

@ -1,10 +1,22 @@
require 'yaml'
class TaskList < ActiveRecord::Base
attr_accessible :item_id, :item_type, :name
belongs_to :item, :polymorphic => true
has_many :tasks
after_save :create_default_bike_tasks
@@default_bike_tasks = YAML::load(File.open(File.join( Rails.root, "db", "defaults", "bike_tasks.yml")))["tasks"]
def to_s
self.name
end
def create_default_bike_tasks
@@default_bike_tasks.each do |task|
self.tasks.create( task: task, done: false)
end
end
end

8
db/defaults/bike_tasks.yml

@ -0,0 +1,8 @@
tasks:
- Regrease Back Wheel
- Regrease Front Wheel
- Tru wheel
- Repack bottom bracket
- Repack steering post
- Redo brake lines
- Tighten brakes
Loading…
Cancel
Save