Permalink
Browse files

Merge pull request #96 from rescuedcode/bug_add_new_user_doesnt_work_…

…on_staffplans

Bug add new user doesnt work on staffplans
  • Loading branch information...
fermion committed Mar 18, 2013
2 parents 37faaef + 3d3cb8b commit 8fca439ae24087c83c8cbca810e4b302be52075c
@@ -1,6 +1,7 @@
class window.StaffPlan.Models.Membership extends StaffPlan.Model
- initialize: (options) ->
+ initialize: (attributes, options={}) ->
@companyId = options.company_id
+ @parent = options.parent
url: ->
mid = if @id then "/#{@id}" else ""
@@ -9,9 +10,11 @@ class window.StaffPlan.Models.Membership extends StaffPlan.Model
toJSON: ->
membership:
archived: @get("archived")
+ user_id: @get("user_id")
company_id: @get("company_id")
disabled: @get("disabled")
employment_status: @get("employment_status")
+ salary: @get("salary")
full_time_equivalent: @get("full_time_equivalent")
id: @get("id")
payment_frequency: @get("payment_frequency")
@@ -70,10 +70,8 @@ class StaffPlan.Routers.StaffPlan extends Support.SwappingRouter
@swap userShow
userNew: ->
- user = new window.StaffPlan.Models.User
userNew = new window.StaffPlan.Views.Users.New
router: @
- model: user
collection: window.StaffPlan.users
@swap userNew
@@ -39,9 +39,10 @@ class window.StaffPlan.Views.Users.New extends StaffPlan.View
@collection.create userAttributes,
success: (model, response) =>
# We have a new user
- membership = new window.StaffPlan.Models.Membership
+ membership = new window.StaffPlan.Models.Membership {user_id: model.id, company_id: window.StaffPlan.currentCompany.id},
company_id: window.StaffPlan.currentCompany.id
- membership.save (_.extend membershipAttributes, {user_id: model.id}),
+ parent: model
+ membership.save membershipAttributes,
success: (resource, response) ->
# Set the newly saved membership on the user
model.membership.set resource
View
@@ -21,8 +21,8 @@ def for_company(company)
after_update do |user|
terminator = user.versions.last.try(:terminator)
- if terminator.present? and terminator.to_i != user.id
- User.find_by_id(terminator.to_i).update_timestamp!
+ if terminator.present? && (terminator.to_i != user.id)
+ User.where(:id => terminator.to_i).first.try(&:update_timestamp!)
end
end

0 comments on commit 8fca439

Please sign in to comment.