Skip to content

Instantly share code, notes, and snippets.

@pjmorse
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjmorse/8827845 to your computer and use it in GitHub Desktop.
Save pjmorse/8827845 to your computer and use it in GitHub Desktop.
saveNewSubscriber: ->
@content.get("subscriber").save().then(
(subscriber) =>
$("#modal-dialog-component").modal("hide")
App.Notifications.pushSuccess Em.I18n.t "notifications.added", model : "Subscriber"
# if subscriber.company?.order_profile?.warehouse?
# TODO: Need to get first the orderProfile, then its warehouse, from the API
return subscriber.get("company")
,
(response) =>
setErrorMessages response.errors, "subscriber" if response.errors?
unless @content.get("subscriber").get("currentState.stateName") is "root.loaded.created.inFlight"
@content.get("subscriber").send "becameValid"
).then(
(company) =>
console.log "Got company #{company.name}"
return company.get("orderProfile")
).then(
(orderProfile) =>
console.log "Got the order profile: #{orderProfile.name} with warehouse #{orderProfile.warehouse_id}"
return orderProfile.get("warehouse")
).then(
(warehouse) =>
console.log "Got warehouse: #{warehouse.get('name')}"
@set("warehouseSelected", subscriber.company.order_profile.warehouse)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment