Permalink
Browse files

Bug [#45960641] Can't add a new user

  • Loading branch information...
1 parent aebb5a4 commit 3d3cb8b469431712e6eb5133cd4c5546f553c5e3 @Veejay Veejay committed Mar 11, 2013
@@ -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")
@@ -46,7 +46,6 @@ class window.StaffPlan.Views.Users.Edit extends StaffPlan.View
model.membership.set resource
@model.preferences.save preferencesAttributes,
success: (resource, response) ->
- console.log resource
Backbone.history.navigate("/users", true)
error: (model, xhr, options) =>
@errorHandler xhr, "preferences"
@@ -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 3d3cb8b

Please sign in to comment.