# @cjsx React.DOM $ = require('jquery') React = require('react') Modal = require('react-bootstrap/lib/Modal') Button = require('react-bootstrap/lib/Button') Loader = require('react-loader') module.exports = React.createClass displayName: 'Edit' getInitialState: ()-> updating: false title: @props.card.get('title') content: @props.card.get('content') errors: false onChangeTitle: -> @setState title: event.target.value onChangeContent: -> @setState content: event.target.value onClickOk: ()-> event.preventDefault() @setState updating: true if @props.card.isNew() attributes = {title: @state.title, content: @state.content} else attributes = {new_title: @state.title, content: @state.content} @props.card.save attributes, success: ()=> @setState updating: false @props.onRequestHide() @props.card.set 'title', @state.title if @props.card.isNew() location.hash = '/' + @state.title error: (model, response, options)=> console.log response.responseJSON @setState errors: response.responseJSON.card.errors @setState updating: false render: ->
{ if @state.errors
    { for key, errors of @state.errors for error in errors
  • {key + ' ' + error}
  • }
}