Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first deploy

  • Loading branch information...
commit 8f8e1e1a2072c5730e57def768afb81a9d010619 1 parent 10b8721
Cody Swann authored September 10, 2012

Showing 190 changed files with 4,323 additions and 35 deletions. Show diff stats Hide diff stats

  1. 84  README
  2. 3  app/assets/javascripts/addresses.js.coffee
  3. 3  app/assets/javascripts/agencies.js.coffee
  4. 3  app/assets/javascripts/agents.js.coffee
  5. 3  app/assets/javascripts/assigned_agents.js.coffee
  6. 3  app/assets/javascripts/assigned_client_types.js.coffee
  7. 3  app/assets/javascripts/assigned_clients.js.coffee
  8. 3  app/assets/javascripts/client_types.js.coffee
  9. 3  app/assets/javascripts/clients.js.coffee
  10. 3  app/assets/javascripts/contact_types.js.coffee
  11. 3  app/assets/javascripts/contacts.js.coffee
  12. 3  app/assets/javascripts/contracts.js.coffee
  13. 3  app/assets/javascripts/sports.js.coffee
  14. 3  app/assets/stylesheets/addresses.css.scss
  15. 3  app/assets/stylesheets/agencies.css.scss
  16. 3  app/assets/stylesheets/agents.css.scss
  17. 3  app/assets/stylesheets/assigned_agents.css.scss
  18. 3  app/assets/stylesheets/assigned_client_types.css.scss
  19. 3  app/assets/stylesheets/assigned_clients.css.scss
  20. 3  app/assets/stylesheets/client_types.css.scss
  21. 3  app/assets/stylesheets/clients.css.scss
  22. 3  app/assets/stylesheets/contact_types.css.scss
  23. 3  app/assets/stylesheets/contacts.css.scss
  24. 3  app/assets/stylesheets/contracts.css.scss
  25. 3  app/assets/stylesheets/sports.css.scss
  26. 2  app/controllers/addresses_controller.rb
  27. 9  app/controllers/agencies_controller.rb
  28. 3  app/controllers/agents_controller.rb
  29. 3  app/controllers/application_controller.rb
  30. 11  app/controllers/assigned_agents_controller.rb
  31. 2  app/controllers/assigned_client_types_controller.rb
  32. 11  app/controllers/assigned_clients_controller.rb
  33. 2  app/controllers/client_types_controller.rb
  34. 11  app/controllers/clients_controller.rb
  35. 9  app/controllers/contact_types_controller.rb
  36. 12  app/controllers/contacts_controller.rb
  37. 3  app/controllers/contracts_controller.rb
  38. 3  app/controllers/home_controller.rb
  39. 2  app/controllers/sports_controller.rb
  40. 2  app/controllers/users_controller.rb
  41. 2  app/helpers/addresses_helper.rb
  42. 2  app/helpers/agencies_helper.rb
  43. 2  app/helpers/agents_helper.rb
  44. 2  app/helpers/assigned_agents_helper.rb
  45. 2  app/helpers/assigned_client_types_helper.rb
  46. 2  app/helpers/assigned_clients_helper.rb
  47. 2  app/helpers/client_types_helper.rb
  48. 2  app/helpers/clients_helper.rb
  49. 2  app/helpers/contact_types_helper.rb
  50. 2  app/helpers/contacts_helper.rb
  51. 2  app/helpers/contracts_helper.rb
  52. 2  app/helpers/sports_helper.rb
  53. 16  app/models/ability.rb
  54. 4  app/models/address.rb
  55. 26  app/models/agency.rb
  56. 29  app/models/agent.rb
  57. 5  app/models/assigned_agent.rb
  58. 5  app/models/assigned_client.rb
  59. 5  app/models/assigned_client_type.rb
  60. 44  app/models/client.rb
  61. 3  app/models/client_type.rb
  62. 5  app/models/contact.rb
  63. 7  app/models/contact_type.rb
  64. 6  app/models/contract.rb
  65. 3  app/models/sport.rb
  66. 38  app/models/user.rb
  67. 16  app/views/addresses/_form.html.erb
  68. 6  app/views/addresses/edit.html.erb
  69. 52  app/views/addresses/index.html.erb
  70. 6  app/views/addresses/new.html.erb
  71. 37  app/views/addresses/show.html.erb
  72. 11  app/views/agencies/_form.html.erb
  73. 6  app/views/agencies/edit.html.erb
  74. 36  app/views/agencies/index.html.erb
  75. 6  app/views/agencies/new.html.erb
  76. 67  app/views/agencies/show.html.erb
  77. 10  app/views/agents/_form.html.erb
  78. 6  app/views/agents/edit.html.erb
  79. 38  app/views/agents/index.html.erb
  80. 6  app/views/agents/new.html.erb
  81. 84  app/views/agents/show.html.erb
  82. 10  app/views/assigned_agents/_form.html.erb
  83. 6  app/views/assigned_agents/edit.html.erb
  84. 44  app/views/assigned_agents/index.html.erb
  85. 7  app/views/assigned_agents/new.html.erb
  86. 29  app/views/assigned_agents/show.html.erb
  87. 10  app/views/assigned_client_types/_form.html.erb
  88. 6  app/views/assigned_client_types/edit.html.erb
  89. 40  app/views/assigned_client_types/index.html.erb
  90. 6  app/views/assigned_client_types/new.html.erb
  91. 25  app/views/assigned_client_types/show.html.erb
  92. 11  app/views/assigned_clients/_form.html.erb
  93. 6  app/views/assigned_clients/edit.html.erb
  94. 44  app/views/assigned_clients/index.html.erb
  95. 6  app/views/assigned_clients/new.html.erb
  96. 29  app/views/assigned_clients/show.html.erb
  97. 8  app/views/client_types/_form.html.erb
  98. 6  app/views/client_types/edit.html.erb
  99. 36  app/views/client_types/index.html.erb
  100. 6  app/views/client_types/new.html.erb
  101. 21  app/views/client_types/show.html.erb
  102. 12  app/views/clients/_form.html.erb
  103. 6  app/views/clients/edit.html.erb
  104. 38  app/views/clients/index.html.erb
  105. 6  app/views/clients/new.html.erb
  106. 74  app/views/clients/show.html.erb
  107. 11  app/views/contact_types/_form.html.erb
  108. 6  app/views/contact_types/edit.html.erb
  109. 36  app/views/contact_types/index.html.erb
  110. 6  app/views/contact_types/new.html.erb
  111. 21  app/views/contact_types/show.html.erb
  112. 9  app/views/contacts/_form.html.erb
  113. 6  app/views/contacts/edit.html.erb
  114. 42  app/views/contacts/index.html.erb
  115. 6  app/views/contacts/new.html.erb
  116. 27  app/views/contacts/show.html.erb
  117. 14  app/views/contracts/_form.html.erb
  118. 6  app/views/contracts/edit.html.erb
  119. 52  app/views/contracts/index.html.erb
  120. 6  app/views/contracts/new.html.erb
  121. 37  app/views/contracts/show.html.erb
  122. 16  app/views/layouts/_navigation.html.erb
  123. 2  app/views/layouts/application.html.erb
  124. 8  app/views/sports/_form.html.erb
  125. 6  app/views/sports/edit.html.erb
  126. 36  app/views/sports/index.html.erb
  127. 6  app/views/sports/new.html.erb
  128. 21  app/views/sports/show.html.erb
  129. 9  app/views/users/_form.html.erb
  130. 6  app/views/users/edit.html.erb
  131. 36  app/views/users/index.html.erb
  132. 6  app/views/users/new.html.erb
  133. 21  app/views/users/show.html.erb
  134. 22  config/initializers/devise.rb
  135. 16  config/locales/devise_invitable.en.yml
  136. 3  config/locales/en.yml
  137. 32  config/routes.rb
  138. 13  db/migrate/20120823172214_devise_create_users.rb
  139. 8  db/migrate/20120823172229_add_confirmable_to_users.rb
  140. 9  db/migrate/20120823184100_create_agencies.rb
  141. 18  db/migrate/20120823184105_create_addresses.rb
  142. 11  db/migrate/20120823184111_create_clients.rb
  143. 9  db/migrate/20120823184117_create_client_types.rb
  144. 13  db/migrate/20120823184123_create_assigned_client_types.rb
  145. 15  db/migrate/20120823184129_create_assigned_clients.rb
  146. 14  db/migrate/20120823184134_create_contacts.rb
  147. 9  db/migrate/20120823184140_create_contact_types.rb
  148. 11  db/migrate/20120823184146_create_agents.rb
  149. 15  db/migrate/20120823184152_create_assigned_agents.rb
  150. 15  db/migrate/20120908212254_change_assigned_client_to_polymorphic_relationship.rb
  151. 19  db/migrate/20120910183752_create_contracts.rb
  152. 9  db/migrate/20120910183759_create_sports.rb
  153. 145  db/schema.rb
  154. 9  db/seeds.rb
  155. 164  spec/controllers/addresses_controller_spec.rb
  156. 164  spec/controllers/agencies_controller_spec.rb
  157. 164  spec/controllers/agents_controller_spec.rb
  158. 164  spec/controllers/assigned_agents_controller_spec.rb
  159. 164  spec/controllers/assigned_client_types_controller_spec.rb
  160. 164  spec/controllers/assigned_clients_controller_spec.rb
  161. 164  spec/controllers/client_types_controller_spec.rb
  162. 164  spec/controllers/clients_controller_spec.rb
  163. 164  spec/controllers/contact_types_controller_spec.rb
  164. 164  spec/controllers/contacts_controller_spec.rb
  165. 164  spec/controllers/contracts_controller_spec.rb
  166. 164  spec/controllers/sports_controller_spec.rb
  167. 15  spec/factories/addresses.rb
  168. 7  spec/factories/agencies.rb
  169. 9  spec/factories/agents.rb
  170. 11  spec/factories/assigned_agents.rb
  171. 9  spec/factories/assigned_client_types.rb
  172. 11  spec/factories/assigned_clients.rb
  173. 7  spec/factories/client_types.rb
  174. 9  spec/factories/clients.rb
  175. 7  spec/factories/contact_types.rb
  176. 10  spec/factories/contacts.rb
  177. 15  spec/factories/contracts.rb
  178. 7  spec/factories/sports.rb
  179. 5  spec/models/address_spec.rb
  180. 5  spec/models/agency_spec.rb
  181. 5  spec/models/agent_spec.rb
  182. 5  spec/models/assigned_agent_spec.rb
  183. 5  spec/models/assigned_client_spec.rb
  184. 5  spec/models/assigned_client_type_spec.rb
  185. 5  spec/models/client_spec.rb
  186. 5  spec/models/client_type_spec.rb
  187. 5  spec/models/contact_spec.rb
  188. 5  spec/models/contact_type_spec.rb
  189. 5  spec/models/contract_spec.rb
  190. 5  spec/models/sport_spec.rb
84  README
... ...
@@ -1,6 +1,88 @@
1  
-Sportsagentdatabase
  1
+Sports Agent Database
2 2
 ========================
3 3
 
  4
+rm -rf ~/workspace/ruby/rails/sportsagentdatabase
  5
+cd ~/workspace/ruby/rails
  6
+rvm use 1.9.3
  7
+rvm gemset create sportsagentdatabase
  8
+rvm use 1.9.3@sportsagentdatabase
  9
+gem install rails --no-ri --no-rdoc
  10
+gem install rails_apps_composer --no-ri --no-rdoc
  11
+rails_apps_composer new sportsagentdatabase -r home_page devise add_user rspec action_mailer html5 cleanup extras git seed_database capybara guard inherited_resources simple_form
  12
+
  13
+echo 'rvm use 1.9.3@sportsagentdatabase' >> sportsagentdatabase/.rvmrc
  14
+
  15
+cd sportsagentdatabase
  16
+
  17
+mate Gemfile
  18
+# ADD GEMS (HEROKU, ETC)
  19
+
  20
+bundle
  21
+
  22
+# Add the following to application.rb:
  23
+# config.assets.initialize_on_precompile = false
  24
+
  25
+
  26
+
  27
+rails g controller users index show create update destroy new edit
  28
+rails g bootstrap:themed Users -f 
  29
+
  30
+# Tweak seeds file
  31
+
  32
+# Add the following to application.css.scss
  33
+*= require bootstrap_and_overrides
  34
+
  35
+bundle exec rake db:seed
  36
+
  37
+rails g heroku:config
  38
+
  39
+# Tweak heroku.yml
  40
+
  41
+bundle open heroku-rails
  42
+
  43
+# def authorize
  44
+#   return if @heroku
  45
+#   @heroku = Heroku::Auth.client
  46
+# end
  47
+
  48
+git remote add origin https://github.com/gunnertech/sportsagentdatabase.git
  49
+git remote set-url origin git@github.com:gunnertech/sportsagentdatabase.git
  50
+git add .
  51
+git commit -am "first commit"
  52
+git push -u origin master
  53
+
  54
+bundle exec rake all heroku:setup
  55
+bundle exec rake all heroku:deploy
  56
+heroku run rake db:migrate --app sportsagentdatabase-staging
  57
+heroku run rake db:seed --app sportsagentdatabase-staging
  58
+heroku run rake db:migrate --app sportsagentdatabase
  59
+
  60
+
  61
+
  62
+rails g scaffold agency name:string
  63
+rails g scaffold address address_1:string address_2:string city:string state:string zip:string lat:float lng:float addressable:belongs_to addressable_type:string
  64
+rails g scaffold client first_name:string last_name:string name:string
  65
+rails g scaffold client_type name:string
  66
+rails g scaffold assigned_client_type client:belongs_to client_type:belongs_to active:boolean
  67
+rails g scaffold assigned_client client:belongs_to agent:belongs_to active:boolean start_date:date end_date:date
  68
+rails g scaffold contact contact_type:belongs_to value:string contactable:belongs_to contactable_type:string
  69
+rails g scaffold contact_type name:string
  70
+rails g scaffold agent first_name:string last_name:string name:string
  71
+rails g scaffold assigned_agent agency:belongs_to agent:belongs_to active:boolean start_date:date end_date:date
  72
+
  73
+
  74
+rake db:migrate
  75
+
  76
+rails g bootstrap:themed agencies -f
  77
+rails g bootstrap:themed addresses -f
  78
+rails g bootstrap:themed clients -f
  79
+rails g bootstrap:themed client_types -f
  80
+rails g bootstrap:themed assigned_client_types -f
  81
+rails g bootstrap:themed assigned_clients -f
  82
+rails g bootstrap:themed contacts -f
  83
+rails g bootstrap:themed contact_types -f
  84
+rails g bootstrap:themed agents -f
  85
+rails g bootstrap:themed assigned_agents -f
4 86
 
5 87
 ________________________
6 88
 
3  app/assets/javascripts/addresses.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/agencies.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/agents.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/assigned_agents.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/assigned_client_types.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/assigned_clients.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/client_types.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/clients.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/contact_types.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/contacts.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/contracts.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/javascripts/sports.js.coffee
... ...
@@ -0,0 +1,3 @@
  1
+# Place all the behaviors and hooks related to the matching controller here.
  2
+# All this logic will automatically be available in application.js.
  3
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/stylesheets/addresses.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the addresses controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/agencies.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the agencies controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/agents.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the agents controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/assigned_agents.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the assigned_agents controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/assigned_client_types.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the assigned_client_types controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/assigned_clients.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the assigned_clients controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/client_types.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the client_types controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/clients.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the clients controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/contact_types.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the contact_types controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/contacts.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the contacts controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/contracts.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the Contracts controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
3  app/assets/stylesheets/sports.css.scss
... ...
@@ -0,0 +1,3 @@
  1
+// Place all the styles related to the sports controller here.
  2
+// They will automatically be included in application.css.
  3
+// You can use Sass (SCSS) here: http://sass-lang.com/
2  app/controllers/addresses_controller.rb
... ...
@@ -0,0 +1,2 @@
  1
+class AddressesController < InheritedResources::Base
  2
+end
9  app/controllers/agencies_controller.rb
... ...
@@ -0,0 +1,9 @@
  1
+class AgenciesController < InheritedResources::Base
  2
+  def create
  3
+    if params[:agency][:agent_id].blank?
  4
+      create!
  5
+    else
  6
+      create!{ agent_url(params[:agency][:agent_id]) }
  7
+    end
  8
+  end
  9
+end
3  app/controllers/agents_controller.rb
... ...
@@ -0,0 +1,3 @@
  1
+class AgentsController < InheritedResources::Base
  2
+  
  3
+end
3  app/controllers/application_controller.rb
... ...
@@ -1,4 +1,7 @@
1 1
 class ApplicationController < ActionController::Base
  2
+  load_and_authorize_resource unless: :devise_controller?
  3
+  check_authorization unless: :devise_controller?
  4
+  
2 5
   protect_from_forgery
3 6
   rescue_from CanCan::AccessDenied do |exception|
4 7
     redirect_to root_path, :alert => exception.message
11  app/controllers/assigned_agents_controller.rb
... ...
@@ -0,0 +1,11 @@
  1
+class AssignedAgentsController < InheritedResources::Base
  2
+  belongs_to :agent
  3
+  
  4
+  def create
  5
+    create!{ agent_url(parent) }
  6
+  end
  7
+  
  8
+  def update
  9
+    update!{ agent_url(parent) }
  10
+  end
  11
+end
2  app/controllers/assigned_client_types_controller.rb
... ...
@@ -0,0 +1,2 @@
  1
+class AssignedClientTypesController < InheritedResources::Base
  2
+end
11  app/controllers/assigned_clients_controller.rb
... ...
@@ -0,0 +1,11 @@
  1
+class AssignedClientsController < InheritedResources::Base
  2
+  belongs_to :agency, :agent, polymorphic: true
  3
+  
  4
+  def create
  5
+    create!{ parent }
  6
+  end
  7
+  
  8
+  def update
  9
+    update!{ parent }
  10
+  end
  11
+end
2  app/controllers/client_types_controller.rb
... ...
@@ -0,0 +1,2 @@
  1
+class ClientTypesController < InheritedResources::Base
  2
+end
11  app/controllers/clients_controller.rb
... ...
@@ -0,0 +1,11 @@
  1
+class ClientsController < InheritedResources::Base
  2
+  
  3
+  
  4
+  def create
  5
+    if params[:client][:agent_id].blank?
  6
+      create!
  7
+    else
  8
+      create!{ agent_url(params[:client][:agent_id]) }
  9
+    end
  10
+  end
  11
+end
9  app/controllers/contact_types_controller.rb
... ...
@@ -0,0 +1,9 @@
  1
+class ContactTypesController < InheritedResources::Base
  2
+  def create
  3
+    if params[:redirect_to].blank?
  4
+      create!
  5
+    else
  6
+      create!{ params[:redirect_to] }
  7
+    end
  8
+  end
  9
+end
12  app/controllers/contacts_controller.rb
... ...
@@ -0,0 +1,12 @@
  1
+class ContactsController < InheritedResources::Base
  2
+  
  3
+  belongs_to :client, :agent, :agency, polymorphic: true
  4
+  
  5
+  def create
  6
+    create!{ parent }
  7
+  end
  8
+  
  9
+  def update
  10
+    update!{ parent }
  11
+  end
  12
+end
3  app/controllers/contracts_controller.rb
... ...
@@ -0,0 +1,3 @@
  1
+class ContractsController < InheritedResources::Base
  2
+  belongs_to :agency, :agent, polymorphic: true
  3
+end
3  app/controllers/home_controller.rb
... ...
@@ -1,4 +1,7 @@
1 1
 class HomeController < ApplicationController
  2
+  skip_load_and_authorize_resource
  3
+  skip_authorization_check
  4
+  
2 5
   def index
3 6
   end
4 7
 end
2  app/controllers/sports_controller.rb
... ...
@@ -0,0 +1,2 @@
  1
+class SportsController < InheritedResources::Base
  2
+end
2  app/controllers/users_controller.rb
... ...
@@ -0,0 +1,2 @@
  1
+class UsersController < InheritedResources::Base
  2
+end
2  app/helpers/addresses_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AddressesHelper
  2
+end
2  app/helpers/agencies_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AgenciesHelper
  2
+end
2  app/helpers/agents_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AgentsHelper
  2
+end
2  app/helpers/assigned_agents_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AssignedAgentsHelper
  2
+end
2  app/helpers/assigned_client_types_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AssignedClientTypesHelper
  2
+end
2  app/helpers/assigned_clients_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module AssignedClientsHelper
  2
+end
2  app/helpers/client_types_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ClientTypesHelper
  2
+end
2  app/helpers/clients_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ClientsHelper
  2
+end
2  app/helpers/contact_types_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ContactTypesHelper
  2
+end
2  app/helpers/contacts_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ContactsHelper
  2
+end
2  app/helpers/contracts_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ContractsHelper
  2
+end
2  app/helpers/sports_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module SportsHelper
  2
+end
16  app/models/ability.rb
@@ -2,6 +2,22 @@ class Ability
2 2
   include CanCan::Ability
3 3
 
4 4
   def initialize(user)
  5
+    user ||= User.new # guest user (not logged in)
  6
+    
  7
+    can :manage, Client if user.has_role?('admin')
  8
+    can :manage, AssignedClient if user.has_role?('admin')
  9
+    can :manage, Contact if user.has_role?('admin')
  10
+    can :manage, Agent if user.has_role?('admin')
  11
+    can :manage, AssignedAgent if user.has_role?('admin')
  12
+    can :manage, AssignedClient if user.has_role?('admin')
  13
+    can :manage, Sport if user.has_role?('admin')
  14
+    can :manage, Contract if user.has_role?('admin')
  15
+    can :manage, User if user.has_role?('admin')
  16
+    
  17
+    
  18
+    can :read, :all if user.has_role?('member')
  19
+    cannot :read, User unless user.has_role?('admin')
  20
+    
5 21
     # Define abilities for the passed in user here. For example:
6 22
     #
7 23
     #   user ||= User.new # guest user (not logged in)
4  app/models/address.rb
... ...
@@ -0,0 +1,4 @@
  1
+class Address < ActiveRecord::Base
  2
+  belongs_to :addressable, polymorphic: true
  3
+  attr_accessible :address_1, :address_2, :addressable_type, :city, :lat, :lng, :state, :zip, :addressable_id, :addressable 
  4
+end
26  app/models/agency.rb
... ...
@@ -0,0 +1,26 @@
  1
+class Agency < ActiveRecord::Base
  2
+  attr_accessible :name, :agent_id
  3
+  has_many :addresses, as: :addressable
  4
+  has_many :contacts, as: :contactable 
  5
+  has_many :assigned_agents
  6
+  has_many :agents, through: :assigned_agents
  7
+  has_many :assigned_clients, as: :clientable
  8
+  has_many :clients, through: :assigned_clients, source: :client
  9
+  has_many :contracts, as: :contractable
  10
+  
  11
+  attr_accessor :agent_id
  12
+  
  13
+  after_save :add_agent
  14
+    
  15
+  def to_s
  16
+    name
  17
+  end
  18
+  
  19
+  protected
  20
+  
  21
+  def add_agent
  22
+    if agent_id
  23
+      self.assigned_agents.create(agent_id: agent_id)
  24
+    end
  25
+  end
  26
+end
29  app/models/agent.rb
... ...
@@ -0,0 +1,29 @@
  1
+class Agent < ActiveRecord::Base
  2
+  attr_accessible :first_name, :last_name, :name
  3
+  has_many :addresses, as: :addressable
  4
+  has_many :contacts, as: :contactable
  5
+  has_many :assigned_agents
  6
+  has_many :agencies, through: :assigned_agents
  7
+  has_many :assigned_clients, as: :clientable, source: :agent
  8
+  has_many :clients, through: :assigned_clients
  9
+  has_many :currently_assigned_agencies, class_name: 'AssignedAgent', conditions: ['end_date IS ?', nil]
  10
+  has_many :contracts, as: :contractable
  11
+  
  12
+  before_validation :set_name
  13
+  
  14
+  def to_s
  15
+    name
  16
+  end
  17
+  
  18
+  protected
  19
+  
  20
+  def set_name
  21
+    if name
  22
+      name_pieces = name.split(" ")
  23
+      self.first_name = name_pieces.first
  24
+      self.last_name = (name_pieces - [name_pieces.first]).join(" ").strip
  25
+    end
  26
+    
  27
+    self.name = "#{self.first_name} #{self.last_name}"
  28
+  end
  29
+end
5  app/models/assigned_agent.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AssignedAgent < ActiveRecord::Base
  2
+  belongs_to :agency
  3
+  belongs_to :agent
  4
+  attr_accessible :active, :end_date, :start_date, :agent_id, :agency_id
  5
+end
5  app/models/assigned_client.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AssignedClient < ActiveRecord::Base
  2
+  belongs_to :client
  3
+  belongs_to :clientable, polymorphic: true
  4
+  attr_accessible :active, :end_date, :start_date, :clientable_id, :client_id, :clientable_type
  5
+end
5  app/models/assigned_client_type.rb
... ...
@@ -0,0 +1,5 @@
  1
+class AssignedClientType < ActiveRecord::Base
  2
+  belongs_to :client
  3
+  belongs_to :client_type
  4
+  attr_accessible :active
  5
+end
44  app/models/client.rb
... ...
@@ -0,0 +1,44 @@
  1
+class Client < ActiveRecord::Base
  2
+  attr_accessible :first_name, :last_name, :name, :agent_id
  3
+  has_many :addresses, as: :addressable
  4
+  has_many :contacts, as: :contactable
  5
+  has_many :assigned_clients
  6
+  has_many :agents, through: :assigned_clients
  7
+  has_many :currently_assigned_agents, class_name: 'AssignedClient', conditions: ['end_date IS ?', nil]
  8
+  
  9
+  attr_accessor :agent_id
  10
+  
  11
+  before_validation :set_name
  12
+  after_save :add_agent
  13
+  
  14
+  class << self
  15
+    def active_for(agency)
  16
+      # agents = Agent.where{ id >> my{assigned_agents.where{ active == true }.map(&:agent_id)} }
  17
+      self.joins{ assigned_clients }.where{ assigned_clients.agent_id >> my{agency.assigned_agents.where{ active == true }.map(&:agent_id)} }
  18
+    end
  19
+  end
  20
+  
  21
+  
  22
+
  23
+  def to_s
  24
+    name
  25
+  end
  26
+
  27
+  protected
  28
+  
  29
+  def set_name
  30
+    if name
  31
+      name_pieces = name.split(" ")
  32
+      self.first_name = name_pieces.first
  33
+      self.last_name = (name_pieces - [name_pieces.first]).join(" ").strip
  34
+    end
  35
+    
  36
+    self.name = "#{self.first_name} #{self.last_name}"
  37
+  end
  38
+
  39
+  def add_agent
  40
+    if agent_id
  41
+      self.assigned_clients.create(agent_id: agent_id)
  42
+    end
  43
+  end
  44
+end
3  app/models/client_type.rb
... ...
@@ -0,0 +1,3 @@
  1
+class ClientType < ActiveRecord::Base
  2
+  attr_accessible :name
  3
+end
5  app/models/contact.rb
... ...
@@ -0,0 +1,5 @@
  1
+class Contact < ActiveRecord::Base
  2
+  belongs_to :contact_type
  3
+  belongs_to :contactable, polymorphic: true
  4
+  attr_accessible :contactable, :contactable_id, :contactable_type, :value , :contact_type, :contact_type_id
  5
+end
7  app/models/contact_type.rb
... ...
@@ -0,0 +1,7 @@
  1
+class ContactType < ActiveRecord::Base
  2
+  attr_accessible :name
  3
+  
  4
+  def to_s
  5
+    name
  6
+  end
  7
+end
6  app/models/contract.rb
... ...
@@ -0,0 +1,6 @@
  1
+class Contract < ActiveRecord::Base
  2
+  belongs_to :client
  3
+  belongs_to :sport
  4
+  belongs_to :contractable, polymorphic: true
  5
+  attr_accessible :amount, :contractable_id, :contractable_type, :end_date, :executed_on, :length, :start_date
  6
+end
3  app/models/sport.rb
... ...
@@ -0,0 +1,3 @@
  1
+class Sport < ActiveRecord::Base
  2
+  attr_accessible :name
  3
+end
38  app/models/user.rb
@@ -4,9 +4,43 @@ class User < ActiveRecord::Base
4 4
   # :token_authenticatable, :confirmable,
5 5
   # :lockable, :timeoutable and :omniauthable
6 6
   devise :database_authenticatable, :registerable, :confirmable,
7  
-         :recoverable, :rememberable, :trackable, :validatable
  7
+         :recoverable, :rememberable, :trackable, :validatable, :invitable
8 8
 
9 9
   # Setup accessible (or protected) attributes for your model
10  
-  attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :confirmed_at
  10
+  attr_accessor :admin
  11
+  attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :confirmed_at, :admin
  12
+  
  13
+  # before_validation :set_name
  14
+  after_save :set_member_role, :set_admin_role
  15
+  
  16
+  def admin
  17
+    @admin.nil? ? (has_role? 'admin') : @admin
  18
+  end
  19
+  
  20
+  protected
  21
+  
  22
+  def set_admin_role
  23
+    if admin == '0'
  24
+      self.remove_role('admin') if self.has_role?('admin')
  25
+    elsif admin == '1'
  26
+      self.add_role('admin') if !self.has_role?('admin')
  27
+    end
  28
+    true
  29
+  end
  30
+  
  31
+  def set_member_role
  32
+    self.add_role('member') if !self.has_role?('member') && !self.confirmed_at.nil?
  33
+    true
  34
+  end
  35
+  
  36
+  def set_name
  37
+    if name
  38
+      name_pieces = name.split(" ")
  39
+      self.first_name = name_pieces.first
  40
+      self.last_name = (name_pieces - [name_pieces.first]).join(" ").strip
  41
+    end
  42
+    
  43
+    self.name = "#{self.first_name} #{self.last_name}"
  44
+  end
11 45
   
12 46
 end
16  app/views/addresses/_form.html.erb
... ...
@@ -0,0 +1,16 @@
  1
+<%= simple_form_for @address, :html => { :class => 'form-horizontal' } do |f| %>
  2
+  <%= f.input :address_1 %>
  3
+  <%= f.input :address_2 %>
  4
+  <%= f.input :city %>
  5
+  <%= f.input :state %>
  6
+  <%= f.input :zip %>
  7
+  <%= f.input :lat %>
  8
+  <%= f.input :lng %>
  9
+  <%= f.input :addressable_id %>
  10
+  <%= f.input :addressable_type %>
  11
+  <div class="form-actions">
  12
+    <%= f.button :submit, :class => 'btn-primary' %>
  13
+    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
  14
+                addresses_path, :class => 'btn' %>
  15
+  </div>
  16
+<% end %>
6  app/views/addresses/edit.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<%- model_class = Addres -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human,
  4
+                                   :default => "Edit #{model_class.model_name.human}") %></h1>
  5
+</div>
  6
+<%= render :partial => 'form' %>
52  app/views/addresses/index.html.erb
... ...
@@ -0,0 +1,52 @@
  1
+<%- model_class = Addres -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
  4
+</div>
  5
+<table class="table table-striped">
  6
+  <thead>
  7
+    <tr>
  8
+      <th><%= model_class.human_attribute_name(:id) %></th>
  9
+      <th><%= model_class.human_attribute_name(:address_1) %></th>
  10
+      <th><%= model_class.human_attribute_name(:address_2) %></th>
  11
+      <th><%= model_class.human_attribute_name(:city) %></th>
  12
+      <th><%= model_class.human_attribute_name(:state) %></th>
  13
+      <th><%= model_class.human_attribute_name(:zip) %></th>
  14
+      <th><%= model_class.human_attribute_name(:lat) %></th>
  15
+      <th><%= model_class.human_attribute_name(:lng) %></th>
  16
+      <th><%= model_class.human_attribute_name(:addressable_id) %></th>
  17
+      <th><%= model_class.human_attribute_name(:addressable_type) %></th>
  18
+      <th><%= model_class.human_attribute_name(:created_at) %></th>
  19
+      <th><%=t '.actions', :default => t("helpers.actions") %></th>
  20
+    </tr>
  21
+  </thead>
  22
+  <tbody>
  23
+    <% @addresses.each do |address| %>
  24
+      <tr>
  25
+        <td><%= link_to address.id, address_path(address) %></td>
  26
+        <td><%= address.address_1 %></td>
  27
+        <td><%= address.address_2 %></td>
  28
+        <td><%= address.city %></td>
  29
+        <td><%= address.state %></td>
  30
+        <td><%= address.zip %></td>
  31
+        <td><%= address.lat %></td>
  32
+        <td><%= address.lng %></td>
  33
+        <td><%= address.addressable_id %></td>
  34
+        <td><%= address.addressable_type %></td>
  35
+        <td><%=l address.created_at %></td>
  36
+        <td>
  37
+          <%= link_to t('.edit', :default => t("helpers.links.edit")),
  38
+                      edit_address_path(address), :class => 'btn btn-mini' %>
  39
+          <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
  40
+                      address_path(address),
  41
+                      :method => :delete,
  42
+                      :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  43
+                      :class => 'btn btn-mini btn-danger' %>
  44
+        </td>
  45
+      </tr>
  46
+    <% end %>
  47
+  </tbody>
  48
+</table>
  49
+
  50
+<%= link_to t('.new', :default => t("helpers.links.new")),
  51
+            new_address_path,
  52
+            :class => 'btn btn-primary' %>
6  app/views/addresses/new.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<%- model_class = Addres -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
  4
+                                 :default => "New #{model_class.model_name.human}") %></h1>
  5
+</div>
  6
+<%= render :partial => 'form' %>
37  app/views/addresses/show.html.erb
... ...
@@ -0,0 +1,37 @@
  1
+<%- model_class = Addres -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => model_class.model_name.human %></h1>
  4
+</div>
  5
+
  6
+<dl class="dl-horizontal">
  7
+  <dt><strong><%= model_class.human_attribute_name(:address_1) %>:</strong></dt>
  8
+  <dd><%= @address.address_1 %></dd>
  9
+  <dt><strong><%= model_class.human_attribute_name(:address_2) %>:</strong></dt>
  10
+  <dd><%= @address.address_2 %></dd>
  11
+  <dt><strong><%= model_class.human_attribute_name(:city) %>:</strong></dt>
  12
+  <dd><%= @address.city %></dd>
  13
+  <dt><strong><%= model_class.human_attribute_name(:state) %>:</strong></dt>
  14
+  <dd><%= @address.state %></dd>
  15
+  <dt><strong><%= model_class.human_attribute_name(:zip) %>:</strong></dt>
  16
+  <dd><%= @address.zip %></dd>
  17
+  <dt><strong><%= model_class.human_attribute_name(:lat) %>:</strong></dt>
  18
+  <dd><%= @address.lat %></dd>
  19
+  <dt><strong><%= model_class.human_attribute_name(:lng) %>:</strong></dt>
  20
+  <dd><%= @address.lng %></dd>
  21
+  <dt><strong><%= model_class.human_attribute_name(:addressable_id) %>:</strong></dt>
  22
+  <dd><%= @address.addressable_id %></dd>
  23
+  <dt><strong><%= model_class.human_attribute_name(:addressable_type) %>:</strong></dt>
  24
+  <dd><%= @address.addressable_type %></dd>
  25
+</dl>
  26
+
  27
+<div class="form-actions">
  28
+  <%= link_to t('.back', :default => t("helpers.links.back")),
  29
+              addresses_path, :class => 'btn'  %>
  30
+  <%= link_to t('.edit', :default => t("helpers.links.edit")),
  31
+              edit_address_path(@address), :class => 'btn' %>
  32
+  <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
  33
+              address_path(@address),
  34
+              :method => 'delete',
  35
+              :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  36
+              :class => 'btn btn-danger' %>
  37
+</div>
11  app/views/agencies/_form.html.erb
... ...
@@ -0,0 +1,11 @@
  1
+<%= simple_form_for @agency, :html => { :class => 'form-horizontal' } do |f| %>
  2
+  <%= f.input :name %>
  3
+  
  4
+  <%= f.input :agent_id, input_html: {value: params[:agent_id]}, as: :hidden if params[:agent_id] %>
  5
+  
  6
+  <div class="form-actions">
  7
+    <%= f.button :submit, :class => 'btn-primary' %>
  8
+    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
  9
+                agencies_path, :class => 'btn' %>
  10
+  </div>
  11
+<% end %>
6  app/views/agencies/edit.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<%- model_class = Agency -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human,
  4
+                                   :default => "Edit #{model_class.model_name.human}") %></h1>
  5
+</div>
  6
+<%= render :partial => 'form' %>
36  app/views/agencies/index.html.erb
... ...
@@ -0,0 +1,36 @@
  1
+<%- model_class = Agency -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
  4
+</div>
  5
+<table class="table table-striped">
  6
+  <thead>
  7
+    <tr>
  8
+      <th><%= model_class.human_attribute_name(:id) %></th>
  9
+      <th><%= model_class.human_attribute_name(:name) %></th>
  10
+      <th><%= model_class.human_attribute_name(:created_at) %></th>
  11
+      <th><%=t '.actions', :default => t("helpers.actions") %></th>
  12
+    </tr>
  13
+  </thead>
  14
+  <tbody>
  15
+    <% @agencies.each do |agency| %>
  16
+      <tr>
  17
+        <td><%= link_to agency.id, agency_path(agency) %></td>
  18
+        <td><%= agency.name %></td>
  19
+        <td><%=l agency.created_at %></td>
  20
+        <td>
  21
+          <%= link_to t('.edit', :default => t("helpers.links.edit")),
  22
+                      edit_agency_path(agency), :class => 'btn btn-mini' %>
  23
+          <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
  24
+                      agency_path(agency),
  25
+                      :method => :delete,
  26
+                      :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  27
+                      :class => 'btn btn-mini btn-danger' %>
  28
+        </td>
  29
+      </tr>
  30
+    <% end %>
  31
+  </tbody>
  32
+</table>
  33
+
  34
+<%= link_to t('.new', :default => t("helpers.links.new")),
  35
+            new_agency_path,
  36
+            :class => 'btn btn-primary' %>
6  app/views/agencies/new.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<%- model_class = Agency -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
  4
+                                 :default => "New #{model_class.model_name.human}") %></h1>
  5
+</div>
  6
+<%= render :partial => 'form' %>
67  app/views/agencies/show.html.erb
... ...
@@ -0,0 +1,67 @@
  1
+<%- model_class = Agency -%>
  2
+<div class="page-header">
  3
+  <h1><%= resource %></h1>
  4
+</div>
  5
+
  6
+<h2><%=t ('agents') %></h2>
  7
+
  8
+<table class="table table-striped">
  9
+  <thead>
  10
+    <tr>
  11
+      <th><%=t 'agent' %></th>
  12
+      <th><%=t 'from' %></th>
  13
+      <th><%=t 'to' %></th>
  14
+      <th><%=t 'clients' %></th>
  15
+      <th><%=t 'actions' %></th>
  16
+    </tr>
  17
+  </thead>
  18
+  <tbody>
  19
+    <% resource.assigned_agents.each do |assigned_agent| %>
  20
+      <tr>
  21
+        <td><%= link_to assigned_agent.agent, assigned_agent.agent %></td>
  22
+        <td><%= assigned_agent.start_date %></td>
  23
+        <td><%= assigned_agent.end_date %></td>
  24
+        <td>
  25
+          <%= raw assigned_agent.agent.clients.map{ |client| link_to(client,client) }.join(', ') %>
  26
+        </td>
  27
+        <td>
  28
+          <%= link_to t('.edit', :default => t("helpers.links.edit")), edit_agent_assigned_agent_path(resource,assigned_agent), :class => 'btn btn-mini' %>
  29
+          <%= link_to t('.destroy', :default => t("helpers.links.destroy")), agent_assigned_agent_path(resource,assigned_agent),
  30
+            :method => :delete,
  31
+            :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  32
+            :class => 'btn btn-mini btn-danger' %>
  33
+        </td>
  34
+      </tr>
  35
+    <% end %>
  36
+  </tbody>
  37
+</table>
  38
+
  39
+<h2><%=t ('clients') %></h2>
  40
+
  41
+<table class="table table-striped">
  42
+  <thead>
  43
+    <tr>
  44
+      <th><%=t 'client' %></th>
  45
+    </tr>
  46
+  </thead>
  47
+  <tbody>
  48
+    <% resource.assigned_clients.each do |assigned_client| %>
  49
+      <tr>
  50
+        <td><%= link_to assigned_client.client, assigned_client.client %></td>
  51
+      </tr>
  52
+    <% end %>
  53
+  </tbody>
  54
+</table>
  55
+
  56
+<div class="form-actions">
  57
+  <%= link_to t('.back', :default => t("helpers.links.back")),
  58
+              agencies_path, :class => 'btn'  %>
  59
+  <%= link_to t('.edit', :default => t("helpers.links.edit")),
  60
+              edit_agency_path(@agency), :class => 'btn' %>
  61
+  <%= link_to t('add_client'), new_agency_assigned_client_path(@agency), :class => 'btn btn-success' if can? :manage, AssignedClient %>
  62
+  <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
  63
+              agency_path(@agency),
  64
+              :method => 'delete',
  65
+              :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  66
+              :class => 'btn btn-danger' %>
  67
+</div>
10  app/views/agents/_form.html.erb
... ...
@@ -0,0 +1,10 @@
  1
+<%= simple_form_for @agent, :html => { :class => 'form-horizontal' } do |f| %>
  2
+  <%= f.input :first_name %>
  3
+  <%= f.input :last_name %>
  4
+  
  5
+  <div class="form-actions">
  6
+    <%= f.button :submit, :class => 'btn-primary' %>
  7
+    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
  8
+                agents_path, :class => 'btn' %>
  9
+  </div>
  10
+<% end %>
6  app/views/agents/edit.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<%- model_class = Agent -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human,
  4
+                                   :default => "Edit #{model_class.model_name.human}") %></h1>
  5
+</div>
  6
+<%= render :partial => 'form' %>
38  app/views/agents/index.html.erb
... ...
@@ -0,0 +1,38 @@
  1
+<%- model_class = Agent -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
  4
+</div>
  5
+<table class="table table-striped">
  6
+  <thead>
  7
+    <tr>
  8
+      <th><%= model_class.human_attribute_name(:name) %></th>
  9
+      <% if can? :manage, Agent %>
  10
+        <th><%=t '.actions', :default => t("helpers.actions") %></th>
  11
+      <% end %>
  12
+    </tr>
  13
+  </thead>
  14
+  <tbody>
  15
+    <% @agents.each do |agent| %>
  16
+      <tr>
  17
+        <td><%= link_to agent, agent %></td>
  18
+        <% if can? :manage, agent %>
  19
+          <td>
  20
+            <%= link_to t('.edit', :default => t("helpers.links.edit")),
  21
+                        edit_agent_path(agent), :class => 'btn btn-mini' %>
  22
+            <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
  23
+                        agent_path(agent),
  24
+                        :method => :delete,
  25
+                        :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  26
+                        :class => 'btn btn-mini btn-danger' %>
  27
+          </td>
  28
+        <% end %>
  29
+      </tr>
  30
+    <% end %>
  31
+  </tbody>
  32
+</table>
  33
+
  34
+<% if can? :manage, Agent %>
  35
+  <%= link_to t('.new', :default => t("helpers.links.new")),
  36
+              new_agent_path,
  37
+              :class => 'btn btn-primary' %>
  38
+<% end %>
6  app/views/agents/new.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<%- model_class = Agent -%>
  2
+<div class="page-header">
  3
+  <h1><%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
  4
+                                 :default => "New #{model_class.model_name.human}") %></h1>
  5
+</div>
  6
+<%= render :partial => 'form' %>
84  app/views/agents/show.html.erb
... ...
@@ -0,0 +1,84 @@
  1
+<%- model_class = Agent -%>
  2
+<div class="page-header">
  3
+  <h1><%= @agent %></h1>
  4
+</div>
  5
+
  6
+<h2><%=t 'agencies' %></h2>
  7
+
  8
+<table class="table table-striped">
  9
+  <thead>
  10
+    <tr>
  11
+      <th><%=t 'agency' %></th>
  12
+      <th><%=t 'from' %></th>
  13
+      <th><%=t 'to' %></th>
  14
+      <% if can? :manage, AssignedAgent %>
  15
+        <th><%=t 'actions' %></th>
  16
+      <% end %>
  17
+    </tr>
  18
+  </thead>
  19
+  <tbody>
  20
+    <% resource.assigned_agents.each do |assigned_agent| %>
  21
+      <tr>
  22
+        <td><%= link_to assigned_agent.agency, assigned_agent.agency %></td>
  23
+        <td><%= assigned_agent.start_date %></td>
  24
+        <td><%= assigned_agent.end_date %></td>
  25
+        <% if can? :manage, assigned_agent %>
  26
+        <td>
  27
+            <%= link_to t('.edit', :default => t("helpers.links.edit")), edit_agent_assigned_agent_path(resource,assigned_agent), :class => 'btn btn-mini' %>
  28
+            <%= link_to t('.destroy', :default => t("helpers.links.destroy")), agent_assigned_agent_path(resource,assigned_agent),
  29
+              :method => :delete,
  30
+              :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  31
+              :class => 'btn btn-mini btn-danger' %>
  32
+          </td>
  33
+        <% end %>
  34
+      </tr>
  35
+    <% end %>
  36
+  </tbody>
  37
+</table>
  38
+
  39
+<h2><%=t 'clients' %></h2>
  40
+
  41
+<table class="table table-striped">
  42
+  <thead>
  43
+    <tr>
  44
+      <th><%=t 'client' %></th>
  45
+      <th><%=t 'from' %></th>
  46
+      <th><%=t 'to' %></th>
  47
+      <% if can? :manage, AssignedClient %>
  48
+        <th><%=t 'actions' %></th>
  49
+      <% end %>
  50
+    </tr>
  51
+  </thead>
  52
+  <tbody>
  53
+    <% resource.assigned_clients.each do |assigned_client| %>
  54
+      <tr>
  55
+        <td><%= link_to assigned_client.client, assigned_client.client %></td>
  56
+        <td><%= assigned_client.start_date %></td>
  57
+        <td><%= assigned_client.end_date %></td>
  58
+        <% if can? :manage, assigned_client %>
  59
+          <td>
  60
+            <%= link_to t('.edit', :default => t("helpers.links.edit")), edit_client_assigned_client_path(assigned_client.client,assigned_client), :class => 'btn btn-mini' %>
  61
+            <%= link_to t('.destroy', :default => t("helpers.links.destroy")), client_assigned_client_path(assigned_client.client,assigned_client),
  62
+              :method => :delete,
  63
+              :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
  64
+              :class => 'btn btn-mini btn-danger' %>
  65
+          </td>
  66
+        <% end %>
  67
+      </tr>
  68
+    <% end %>
  69
+  </tbody>
  70
+</table>
  71
+
  72
+<div class="form-actions">
  73