Last active
December 11, 2015 00:58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
State = (hash) -> Em.State.extend hash | |
TransitionTo = Em.State.transitionTo | |
C = null | |
Receivers.WithdrawController = Em.ObjectController.extend | |
receiverController: null | |
router: null | |
init: -> | |
@_super() | |
C = @ | |
@stateMachine = Em.StateManager.create | |
initialState: 'hiding' | |
modal: null | |
controller: C | |
hiding: State | |
launchModal: TransitionTo 'launched.specifyAmount.waiting' | |
launched: State | |
setup: (sm) -> | |
rc = C.get("receiverController") | |
C._connectModal Receivers.WithdrawModalPane, Em.Object.create amount: rc.get("withdrawable") | |
exit: (sm) -> C._disconnectModal() | |
# Actions | |
cancelWithdrawal: TransitionTo 'hiding' | |
# States | |
specifyAmount: State | |
setup: (sm) -> | |
C.connectOutlet | |
viewClass: Receivers.WithdrawIndexView | |
waiting: State | |
submitWithdrawal: (sm) -> | |
# TODO validate fields here. | |
sm.transitionTo 'inProcess' | |
inProcess: State | |
enter: -> | |
alert "Submitting form" | |
_afterControllerInjection: ( -> | |
# This gets fired during injections. Wait til all the | |
# other controlls have been injected first. | |
# 1) Add access to receiver controller | |
# 2) Save router (though also available as 'controllers') | |
# 3) Set event target to the stateMachine | |
@runLater 0, => | |
@connectControllers "receiver" | |
@router = @target | |
@target = @stateMachine | |
).observes("namespace") | |
_connectModal: (viewClass, withdrawal) -> | |
@modal = viewClass.create | |
controller: @ | |
fadeIn: 200 | |
@set("content", withdrawal) | |
_disconnectModal: -> | |
@modal.dismiss(200) | |
@modal = null | |
launchModal: -> | |
rc = @get("receiverController") | |
switch rc.get("item_blocking_withdrawal") | |
when "insufficient_funds" | |
minimum = Shared.asMoney manifest.constants.minimumWithdrawalAmount | |
withdrawable = rc.get "withdrawable" | |
alert "Sorry, the minimum withdrawal amount is $#{minimum}. Present Balance: $#{withdrawable}" | |
when "enter_info" | |
if confirm "You haven't filled out your mailing address yet, would you like to do that now?" | |
@router.send 'toSettings' | |
else | |
@stateMachine.send 'launchModal' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment