2015-03-10 09:25:53 +08:00
|
|
|
_ = require 'underscore-plus'
|
|
|
|
React = require 'react'
|
2015-04-09 10:25:00 +08:00
|
|
|
{ListTabular, ModelList} = require 'ui-components'
|
2015-03-10 09:25:53 +08:00
|
|
|
{timestamp, subject} = require './formatting-utils'
|
|
|
|
{Actions,
|
2015-04-09 10:25:00 +08:00
|
|
|
DatabaseStore,
|
|
|
|
ComponentRegistry} = require 'inbox-exports'
|
|
|
|
DraftListStore = require './draft-list-store'
|
2015-03-10 09:25:53 +08:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
DraftList = React.createClass
|
|
|
|
displayName: 'DraftList'
|
|
|
|
|
2015-04-09 10:25:00 +08:00
|
|
|
componentWillMount: ->
|
2015-03-12 05:20:17 +08:00
|
|
|
snippet = (html) =>
|
|
|
|
@draftSanitizer ?= document.createElement('div')
|
|
|
|
@draftSanitizer.innerHTML = html
|
|
|
|
text = @draftSanitizer.innerText
|
|
|
|
text[0..140]
|
|
|
|
|
2015-03-10 09:25:53 +08:00
|
|
|
c1 = new ListTabular.Column
|
|
|
|
name: "Name"
|
2015-04-07 02:46:20 +08:00
|
|
|
width: 200
|
2015-03-10 09:25:53 +08:00
|
|
|
resolver: (draft) =>
|
2015-04-09 10:25:00 +08:00
|
|
|
Participants = ComponentRegistry.findViewByName('Participants')
|
|
|
|
return <div></div> unless Participants
|
2015-03-10 09:25:53 +08:00
|
|
|
<div className="participants">
|
2015-04-07 02:46:20 +08:00
|
|
|
<Participants participants={[].concat(draft.to, draft.cc, draft.bcc)}
|
2015-03-10 09:25:53 +08:00
|
|
|
context={'list'} clickable={false} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
c2 = new ListTabular.Column
|
2015-04-07 02:46:20 +08:00
|
|
|
name: "Message"
|
2015-03-10 09:25:53 +08:00
|
|
|
flex: 4
|
|
|
|
resolver: (draft) ->
|
2015-04-07 02:46:20 +08:00
|
|
|
attachments = []
|
|
|
|
if draft.files?.length > 0
|
|
|
|
attachments = <div className="thread-icon thread-icon-attachment"></div>
|
|
|
|
<span className="details">
|
|
|
|
<span className="subject">{subject(draft.subject)}</span>
|
|
|
|
<span className="snippet">{snippet(draft.body)}</span>
|
|
|
|
{attachments}
|
|
|
|
</span>
|
2015-03-10 09:25:53 +08:00
|
|
|
|
2015-04-07 02:46:20 +08:00
|
|
|
c3 = new ListTabular.Column
|
2015-03-10 09:25:53 +08:00
|
|
|
name: "Date"
|
|
|
|
flex: 1
|
|
|
|
resolver: (draft) ->
|
|
|
|
<span className="timestamp">{timestamp(draft.date)}</span>
|
|
|
|
|
2015-04-09 10:25:00 +08:00
|
|
|
@columns = [c1, c2, c3]
|
|
|
|
@commands =
|
|
|
|
'core:remove-item': @_onDelete
|
2015-03-10 09:25:53 +08:00
|
|
|
|
2015-04-09 10:25:00 +08:00
|
|
|
render: ->
|
|
|
|
<ModelList
|
|
|
|
dataStore={DraftListStore}
|
|
|
|
columns={@columns}
|
|
|
|
commands={@commands}
|
|
|
|
onDoubleClick={@_onDoubleClick}
|
|
|
|
itemClassProvider={ -> }
|
|
|
|
className="draft-list"
|
|
|
|
collection="draft" />
|
2015-03-10 09:25:53 +08:00
|
|
|
|
2015-04-09 10:25:00 +08:00
|
|
|
_onDoubleClick: (item) ->
|
|
|
|
DatabaseStore.localIdForModel(item).then (localId) ->
|
|
|
|
Actions.composePopoutDraft(localId)
|
|
|
|
|
|
|
|
# Additional Commands
|
2015-03-10 09:25:53 +08:00
|
|
|
|
2015-04-09 10:25:00 +08:00
|
|
|
_onDelete: ({focusedId}) ->
|
|
|
|
item = @state.dataView.getById(focusedId)
|
|
|
|
return unless item
|
2015-03-10 09:25:53 +08:00
|
|
|
DatabaseStore.localIdForModel(item).then (localId) ->
|
|
|
|
Actions.destroyDraft(localId)
|
|
|
|
@_onShiftSelectedIndex(-1)
|