2015-03-21 01:23:50 +08:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
React = require 'react'
|
|
|
|
{Actions, Message, DraftStore} = require 'inbox-exports'
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
class TemplateStatusBar extends React.Component
|
|
|
|
@displayName: 'TemplateStatusBar'
|
2015-03-21 01:23:50 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
@propTypes:
|
2015-03-21 01:23:50 +08:00
|
|
|
draftLocalId: React.PropTypes.string
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
constructor: (@props) ->
|
|
|
|
@state = draft: null
|
2015-03-21 01:23:50 +08:00
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
componentDidMount: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
@_proxy = DraftStore.sessionForLocalId(@props.draftLocalId)
|
|
|
|
@unsubscribe = @_proxy.listen(@_onDraftChange, @)
|
|
|
|
if @_proxy.draft()
|
|
|
|
@_onDraftChange()
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
componentWillUnmount: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
@unsubscribe() if @unsubscribe
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
render: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
if @_draftUsesTemplate()
|
|
|
|
<div className="template-status-bar">
|
|
|
|
Press "tab" to quickly fill in the blanks - highlighting will not be visible to recipients.
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
<div></div>
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_onDraftChange: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
@setState(draft: @_proxy.draft())
|
|
|
|
|
2015-05-01 04:08:29 +08:00
|
|
|
_draftUsesTemplate: =>
|
2015-03-21 01:23:50 +08:00
|
|
|
return unless @state.draft
|
|
|
|
@state.draft.body.search(/<code[^>]*class="var[^>]*>/i) > 0
|
2015-05-01 04:08:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = TemplateStatusBar
|