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 class Tasks < Netzke::Basepack::Grid
def configure(c) def configure(c)
super 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.model = "Task"
c.scope = lambda{ |rel| c.scope = lambda{ |rel|
if session[:selected_bike_id] if session[:selected_bike_id]
@ -10,6 +17,24 @@ class Tasks < Netzke::Basepack::Grid
rel.where(:task_list_id => 0) rel.where(:task_list_id => 0)
end 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 end
#override with nil to remove actions #override with nil to remove actions

6
app/models/bike.rb

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

12
app/models/task_list.rb

@ -1,10 +1,22 @@
require 'yaml'
class TaskList < ActiveRecord::Base class TaskList < ActiveRecord::Base
attr_accessible :item_id, :item_type, :name attr_accessible :item_id, :item_type, :name
belongs_to :item, :polymorphic => true belongs_to :item, :polymorphic => true
has_many :tasks 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 def to_s
self.name self.name
end end
def create_default_bike_tasks
@@default_bike_tasks.each do |task|
self.tasks.create( task: task, done: false)
end
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