# @cjsx React.DOM $ = require('jquery') React = require('react/addons') Modal = require('react-bootstrap/lib/Modal') Button = require('react-bootstrap/lib/Button') TagsInput = require('react-tagsinput') CardModel = require('../models/card') module.exports = React.createClass mixins: [React.addons.LinkedStateMixin] displayName: 'Edit' getInitialState: ()-> updating: false title: @props.card.get('title') content: @props.card.get('content') tags: @props.card.get('tags') || [] errors: false shaking: false dontCloseDialog: false createSuccess: false onChangeTitle: (event)-> @setState title: event.target.value onChangeContent: (event)-> @setState content: event.target.value onChangeDontCloseDialog: (event)-> @setState dontCloseDialog: !@state.dontCloseDialog onClickOk: (event)-> event.preventDefault() @setState updating: true if @props.card.isNew() attributes = {title: @state.title, content: @state.content, tags: @state.tags} else attributes = {new_title: @state.title, content: @state.content, tags: @state.tags} @props.card.save attributes, success: ()=> @setState updating: false if @props.card.isNew() if @state.dontCloseDialog @setState createSuccess: true errors: null title: '' content: '' tags: [] @props.card = new CardModel() @props.card._isNew = true else @props.onRequestHide() @props.card.set 'title', @state.title location.hash = '/' + encodeURIComponent(@state.title) else @props.onRequestHide() @props.card = new CardModel() @props.card._isNew = true error: (model, response, options)=> @setState errors: response.responseJSON.card.errors @setState updating: false @setState shaking: true setTimeout (=> @setState shaking: false), 300 render: -> else } animation={false}>
{ if @state.errors
    { for key, errors of @state.errors for error in errors
  • {key + ' ' + error}
  • }
else if @state.createSuccess
  You created a card successfully. Let's create next one.
}