define ['./states/index', './presenter'], (templates, presenter) -> # If some extension provides you can use the type defined in there # to extend your widget. Defaults to Base constructor. # # type: 'Base' # Default values for the options passed to this widget # # Note: the options are passed thorught the html element data # attributes for this widget:
# # options: {} # Widget initialization method, will be called upon loading, options # are already filled with defaults initialize: (options) -> sandbox = @sandbox sandbox.logger.log "initialized!" base = status: 'idle' classes: => "widget #{@state} #{base.status} authenticator" toggle_state: (event) => @state = if @state == 'default' then 'passwords' else 'default' false # Forward the models to the presenter authenticator = message: null email: null password: null button_label: 'Authenticate!' # Authentication state authenticate: (event) -> base.status = "loading" # replace all status sandbox.emit 'user.sign_in', authentication # Listeners authenticated: (session) -> base.status = "success" unauthorized: -> authentication.message = "Ops... seu e-mail ou senha estão incorretos. Tente mais uma vez!