# @cjsx React.DOM @Header = React.createClass( propTypes: site: React.PropTypes.object.isRequired getInitialState: -> { alert: null, success: null, loading: false } handleSync: -> return if @state.loading @setState(loading: true) $.post("/api/syncs").always(@handleResponse).done(@handleSyncSuccess).fail(@handleError) handleDeploy: -> return if @state.loading @setState(loading: true) $.post("/api/deploys").always(@handleResponse).done(@handleDeploySuccess).fail(@handleError) handleResponse: -> @setState(loading: false) handleSyncSuccess: (response) -> @setState(success: response.syncs.join("\n").replace(/\n/g, "
")) setTimeout(@removeSuccess, 5000) $(document).trigger("fetchPosts") handleDeploySuccess: (response) -> @setState(success: response.deploys.join("\n")) setTimeout(@removeSuccess, 5000) $(document).trigger("fetchPosts") handleError: (error) -> @setState(alert: error.responseJSON?.errors.join("\n").replace(/\n/g, "
")) removeSuccess: -> @setState(success: null) if @isMounted() handleBlur: -> @setState(alert: null, success: null) if @isMounted() render: ->
{
if @state.alert} {
if @state.success}
)