_ = require 'underscore-plus'
React = require 'react'
TemplateStore = require './template-store'
{Actions, Message, DatabaseStore} = require 'inbox-exports'
{Popover, Menu, RetinaImg} = require 'ui-components'
class TemplatePicker extends React.Component
@displayName: 'TemplatePicker'
@containerStyles:
order:2
constructor: (@props) ->
@state =
searchValue: ""
templates: TemplateStore.items()
componentDidMount: =>
@unsubscribe = TemplateStore.listen @_onStoreChange
componentWillUnmount: =>
@unsubscribe() if @unsubscribe
render: =>
button =
headerComponents = [
]
footerComponents = [
Save as Template...
Open Templates Folder...
]
_filteredTemplates: (search) =>
search ?= @state.searchValue
items = TemplateStore.items()
return items unless search.length
_.filter items, (t) ->
t.name.toLowerCase().indexOf(search.toLowerCase()) == 0
_onStoreChange: =>
@setState
templates: @_filteredTemplates()
_onSearchValueChange: =>
newSearch = event.target.value
@setState
searchValue: newSearch
templates: @_filteredTemplates(newSearch)
_onChooseTemplate: (template) =>
Actions.insertTemplateId({templateId:template.id, draftLocalId: @props.draftLocalId})
@refs.popover.close()
_onManageTemplates: =>
Actions.showTemplates()
_onNewTemplate: =>
Actions.createTemplate({draftLocalId: @props.draftLocalId})
module.exports = TemplatePicker