/*** @jsx React.DOM */ var news_management = createReactClass({ getInitialState: function(props) { return { news: window.news, editing_news: null, new_entry: { title: '', body: '', }, }; }, componentDidUpdate: function() { if (this.focus_element && this.focus_element != this.already_focused) { this.focus_element.focus(); this.already_focused = this.focus_element; } }, deleteExistingNews: function(event, newsid) { $.confirm({ escapeKey: 'Cancel', animation: 'none', closeAnimation: 'none', title: 'Delete Entry', content: 'Are you sure you want to delete this news entry?', buttons: { Delete: { btnClass: 'delete', action: function() { AJAX.post( Link.get('removenews'), {newsid: newsid}, function(response) { this.setState({ news: response.news, }); }.bind(this) ); }.bind(this), }, Cancel: function() { }, } }); event.preventDefault(); }, addNews: function(event) { AJAX.post( Link.get('addnews'), {news: this.state.new_entry}, function(response) { this.setState({ news: response.news, new_entry: { title: '', body: '', }, }); }.bind(this) ); event.preventDefault(); }, saveNews: function(event) { AJAX.post( Link.get('updatenews'), {news: this.state.editing_news}, function(response) { this.setState({ news: response.news, editing_news: null, }); }.bind(this) ); event.preventDefault(); }, previewNews: function(event, entry) { $.confirm({ escapeKey: 'Close', animation: 'none', closeAnimation: 'none', title: entry.title.length > 0 ? entry.title : 'No Title', content: entry.body.length > 0 ? entry.body : 'No body.', buttons: { Close: function() { }, } }); event.preventDefault(); }, renderDate: function(entry) { return ( ); }, renderTitle: function(entry) { if (this.state.editing_news && entry.id == this.state.editing_news.id) { return ( (this.focus_element = c)} value={ this.state.editing_news.title } onChange={function(event) { var entry = this.state.editing_news; entry.title = event.target.value; this.setState({ editing_news: entry, }); }.bind(this)} /> ); } else { return ( { entry.title } ); } }, renderBody: function(entry) { if (this.state.editing_news && entry.id == this.state.editing_news.id) { return (