lib/carte/client/views/header.cjsx in carte-server-0.0.23 vs lib/carte/client/views/header.cjsx in carte-server-0.0.24

- old
+ new

@@ -10,10 +10,11 @@ module.exports = React.createClass displayName: 'Header' getInitialState: ()-> searchText: '' + isCheckedIncludeContent: false componentWillMount: ()-> console.log 'header mounted' @onSync = ()=> console.log 'model new calback' @@ -30,36 +31,48 @@ for tag in @props.router.query.tags.split(',') searchText.push '#' + tag if @props.router.query.title searchText.push @props.router.query.title @setState searchText: searchText.join(' ') + if @props.router.query.content + @setState isCheckedIncludeContent: true @forceUpdate() @props.router.on "route", @callback componentWillUnmount: -> console.log 'componentWillMount un' @props.router.off "route", @callback + onChangeIncludeContent: (event)-> + @setState isCheckedIncludeContent: !@state.isCheckedIncludeContent, ()=> + @search() if @state.searchText != '' + onChangeSearchText: (event)-> @setState searchText: event.target.value - onKeyPressSearchText: (event)-> + onKeyDownSearchText: (event)-> + console.log 'press', event if event.keyCode == 13 # ENTER console.log '13 enter' event.preventDefault() - tags = [] - titles = [] - for searchText in @state.searchText.split(' ') - if match = searchText.match(/^#(.+)/) - tags.push(match[1]) - else - titles.push(searchText) - query = {} - query.title = titles.join(' ') if titles.length > 0 - query.tags = tags.join(',') if tags.length > 0 - location.hash = '/?' + $.param(query) + @search() + search: -> + console.log @state + tags = [] + titles = [] + for searchText in @state.searchText.split(' ') + if match = searchText.match(/^#(.+)/) + tags.push(match[1]) + else + titles.push(searchText) + query = {} + query.title = titles.join(' ') if titles.length > 0 + query.content = titles.join(' ') if titles.length > 0 && @state.isCheckedIncludeContent + query.tags = tags.join(',') if tags.length > 0 + location.hash = '/?' + $.param(query) + render: -> <nav className="navbar navbar-default" style={{padding:"0px",backgroundColor:"white",marginBottom:"5px"}}> <div className="container-fluid"> <div className="navbar-header"> <a className="navbar-brand" onClick={helpers.reload if !config.icon_link} href={if config.icon_link then config.icon_link else "#/"} style={{paddingTop:"10px"}}> @@ -70,10 +83,16 @@ </a> </div> <div> <form className="navbar-form navbar-left" role="search"> <div className="form-group"> - <input type="text" className="form-control" value={@state.searchText} onChange={@onChangeSearchText} onKeyPress={@onKeyPressSearchText} placeholder='Search ...' /> + <input type="text" className="form-control" value={@state.searchText} onChange={@onChangeSearchText} onKeyDown={@onKeyDownSearchText} placeholder='Search ...' /> + </div> + &nbsp; + <div className="checkbox"> + <label> + <input type="checkbox" checked={@state.isCheckedIncludeContent} onChange={@onChangeIncludeContent} /> Include content + </label> </div> </form> <ul className="nav navbar-nav navbar-right"> <li> <ModalTrigger modal={<Edit card={@card} />}>