context = window rest = context.JK.Rest() logger = context.JK.logger AppStore = context.AppStore UserStore = context.UserStore SubscriptionStore = context.SubscriptionStore SubscriptionActions = context.SubscriptionActions profileUtils = context.JK.ProfileUtils @AccountSubscriptionScreen = React.createClass({ mixins: [ ICheckMixin, Reflux.listenTo(AppStore, "onAppInit"), Reflux.listenTo(UserStore, "onUserChanged"), Reflux.listenTo(SubscriptionStore, "onSubscriptionChanged") ] subRef: null onAppInit: (@app) -> @app.bindScreen('account/subscription', {beforeShow: @beforeShow, afterShow: @afterShow, beforeHide: @beforeHide, beforeLeave: @beforeLeave}) onUserChanged: (userState) -> @setState({user: userState?.user}) onSubscriptionChanged: (subscription) -> @setState({subscription: subscription}) beforeHide: (e) -> @screenVisible = false return true beforeShow: (e) -> @allowLeave = false SubscriptionActions.updateSubscription() forceUpdate: () -> this.refs.sub.onSubmit() userMustLeave: (location) -> @allowLeave = true window.location.href = '/client' + location beforeLeave: (data) -> console.debug("subscription beforeLeave", @allowLeave) if !this.refs.sub? || @allowLeave return true else if this.refs.sub? if !this.refs.sub.state.selectedPlan? console.log("no selected plan; can leave") return true buttons = [] buttons.push({name: 'LEAVE ANYWAY', buttonStyle: 'button-grey', click: (() => (@userMustLeave(data.hash)))}) buttons.push({ name: 'UPDATE PLAN', buttonStyle: 'button-orange', click: (() => (@forceUpdate())) }) context.JK.Banner.show({ title: "Subscription Not Updated", html: '