2015-09-14 22:37:00 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
React = require 'react'
|
|
|
|
AccountContactField = require './account-contact-field'
|
|
|
|
ParticipantsTextField = require './participants-text-field'
|
2015-09-15 04:12:28 +08:00
|
|
|
{Actions} = require 'nylas-exports'
|
2015-09-14 22:37:00 +08:00
|
|
|
{RetinaImg} = require 'nylas-component-kit'
|
|
|
|
|
|
|
|
Fields = require './fields'
|
|
|
|
|
|
|
|
class ExpandedParticipants extends React.Component
|
|
|
|
@displayName: "ExpandedParticipants"
|
|
|
|
|
|
|
|
@propTypes:
|
|
|
|
# Arrays of Contact objects.
|
|
|
|
to: React.PropTypes.array
|
|
|
|
cc: React.PropTypes.array
|
|
|
|
bcc: React.PropTypes.array
|
|
|
|
from: React.PropTypes.array
|
|
|
|
|
2015-12-10 04:35:40 +08:00
|
|
|
# The account to which the current draft belongs
|
|
|
|
account: React.PropTypes.object
|
|
|
|
|
2015-09-14 22:37:00 +08:00
|
|
|
# Either "fullwindow" or "inline"
|
|
|
|
mode: React.PropTypes.string
|
|
|
|
|
|
|
|
# The field that should be focused
|
|
|
|
focusedField: React.PropTypes.string
|
|
|
|
|
|
|
|
# An enum array of visible fields. Can be any constant in the `Fields`
|
|
|
|
# dict. We are passed these as props instead of holding it as state
|
|
|
|
# since this component is frequently unmounted and re-mounted every
|
|
|
|
# time it is displayed
|
|
|
|
enabledFields: React.PropTypes.array
|
|
|
|
|
|
|
|
# Callback for when a user changes which fields should be visible
|
2015-12-09 09:44:20 +08:00
|
|
|
onAdjustEnabledFields: React.PropTypes.func
|
2015-09-14 22:37:00 +08:00
|
|
|
|
|
|
|
# Callback for the participants change
|
|
|
|
onChangeParticipants: React.PropTypes.func
|
|
|
|
|
2015-12-09 09:44:20 +08:00
|
|
|
# Callback for the field focus changes
|
|
|
|
onChangeFocusedField: React.PropTypes.func
|
|
|
|
|
2015-09-14 22:37:00 +08:00
|
|
|
@defaultProps:
|
|
|
|
to: []
|
|
|
|
cc: []
|
|
|
|
bcc: []
|
|
|
|
from: []
|
|
|
|
enabledFields: []
|
|
|
|
|
|
|
|
constructor: (@props={}) ->
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@_applyFocusedField()
|
|
|
|
|
|
|
|
componentDidUpdate: ->
|
|
|
|
@_applyFocusedField()
|
|
|
|
|
|
|
|
render: ->
|
2015-12-09 09:44:20 +08:00
|
|
|
<div className="expanded-participants"
|
2015-09-14 22:37:00 +08:00
|
|
|
ref="participantWrap">
|
|
|
|
{@_renderFields()}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
_applyFocusedField: ->
|
|
|
|
if @props.focusedField
|
|
|
|
return unless @refs[@props.focusedField]
|
|
|
|
if @refs[@props.focusedField].focus
|
|
|
|
@refs[@props.focusedField].focus()
|
|
|
|
else
|
|
|
|
React.findDOMNode(@refs[@props.focusedField]).focus()
|
|
|
|
|
|
|
|
_renderFields: =>
|
|
|
|
# Note: We need to physically add and remove these elements, not just hide them.
|
|
|
|
# If they're hidden, shift-tab between fields breaks.
|
|
|
|
fields = []
|
|
|
|
fields.push(
|
|
|
|
<div key="to">
|
|
|
|
<div className="composer-participant-actions">
|
|
|
|
{if Fields.Cc not in @props.enabledFields
|
|
|
|
<span className="header-action show-cc"
|
2015-12-09 09:44:20 +08:00
|
|
|
onClick={ => @props.onAdjustEnabledFields(show: [Fields.Cc]) }>Cc</span>
|
2015-09-14 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{ if Fields.Bcc not in @props.enabledFields
|
|
|
|
<span className="header-action show-bcc"
|
2015-12-09 09:44:20 +08:00
|
|
|
onClick={ => @props.onAdjustEnabledFields(show: [Fields.Bcc]) }>Bcc</span>
|
2015-09-14 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{ if Fields.Subject not in @props.enabledFields
|
|
|
|
<span className="header-action show-subject"
|
2015-12-09 09:44:20 +08:00
|
|
|
onClick={ => @props.onAdjustEnabledFields(show: [Fields.Subject]) }>Subject</span>
|
2015-09-14 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
{ if @props.mode is "inline"
|
|
|
|
<span className="header-action show-popout"
|
2015-10-22 02:03:27 +08:00
|
|
|
title="Popout composer"
|
2015-09-14 22:37:00 +08:00
|
|
|
style={paddingLeft: "1.5em"}
|
2015-09-23 07:02:44 +08:00
|
|
|
onClick={@props.onPopoutComposer}>
|
2015-09-14 22:37:00 +08:00
|
|
|
<RetinaImg name="composer-popout.png"
|
|
|
|
mode={RetinaImg.Mode.ContentIsMask}
|
|
|
|
style={{position: "relative", top: "-2px"}}/>
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<ParticipantsTextField
|
|
|
|
ref={Fields.To}
|
|
|
|
field='to'
|
|
|
|
change={@props.onChangeParticipants}
|
|
|
|
className="composer-participant-field to-field"
|
2015-12-09 09:44:20 +08:00
|
|
|
onFocus={ => @props.onChangeFocusedField(Fields.To) }
|
2015-09-14 22:37:00 +08:00
|
|
|
participants={to: @props['to'], cc: @props['cc'], bcc: @props['bcc']} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
if Fields.Cc in @props.enabledFields
|
|
|
|
fields.push(
|
|
|
|
<ParticipantsTextField
|
|
|
|
ref={Fields.Cc}
|
|
|
|
key="cc"
|
|
|
|
field='cc'
|
|
|
|
change={@props.onChangeParticipants}
|
2015-12-09 09:44:20 +08:00
|
|
|
onEmptied={ => @props.onAdjustEnabledFields(hide: [Fields.Cc]) }
|
|
|
|
onFocus={ => @props.onChangeFocusedField(Fields.Cc) }
|
2015-09-14 22:37:00 +08:00
|
|
|
className="composer-participant-field cc-field"
|
|
|
|
participants={to: @props['to'], cc: @props['cc'], bcc: @props['bcc']} />
|
|
|
|
)
|
|
|
|
|
|
|
|
if Fields.Bcc in @props.enabledFields
|
|
|
|
fields.push(
|
|
|
|
<ParticipantsTextField
|
|
|
|
ref={Fields.Bcc}
|
|
|
|
key="bcc"
|
|
|
|
field='bcc'
|
|
|
|
change={@props.onChangeParticipants}
|
2015-12-09 09:44:20 +08:00
|
|
|
onEmptied={ => @props.onAdjustEnabledFields(hide: [Fields.Bcc]) }
|
|
|
|
onFocus={ => @props.onChangeFocusedField(Fields.Bcc) }
|
2015-09-14 22:37:00 +08:00
|
|
|
className="composer-participant-field bcc-field"
|
|
|
|
participants={to: @props['to'], cc: @props['cc'], bcc: @props['bcc']} />
|
|
|
|
)
|
|
|
|
|
|
|
|
if Fields.From in @props.enabledFields
|
|
|
|
fields.push(
|
|
|
|
<AccountContactField
|
|
|
|
key="from"
|
|
|
|
ref={Fields.From}
|
|
|
|
onChange={ (me) => @props.onChangeParticipants(from: [me]) }
|
2015-12-09 09:44:20 +08:00
|
|
|
onFocus={ => @props.onChangeFocusedField(Fields.From) }
|
2015-12-10 04:35:40 +08:00
|
|
|
account={@props.account}
|
2015-09-14 22:37:00 +08:00
|
|
|
value={@props.from?[0]} />
|
|
|
|
)
|
|
|
|
|
|
|
|
fields
|
|
|
|
|
|
|
|
module.exports = ExpandedParticipants
|