nci/static/js/app/components/projects/selector/index.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-06-14 11:24:31 +00:00
'use strict';
define([
2015-07-09 20:12:24 +00:00
'react', 'react-router', 'reflux', 'app/actions/project',
'app/stores/projects',
2015-06-14 11:24:31 +00:00
'templates/app/components/projects/selector/index'
2015-07-09 20:12:24 +00:00
], function(React, Router, Reflux, ProjectActions, projectsStore, template) {
template = template.locals({
Link: Router.Link
});
2015-06-14 11:24:31 +00:00
return React.createClass({
mixins: [Reflux.ListenerMixin],
componentDidMount: function() {
this.listenTo(projectsStore, this.updateItems);
},
getInitialState: function() {
return {
showSearch: false
};
},
onRunProject: function(projectName) {
ProjectActions.run(projectName)
this.setState({showSearch: false});
},
updateItems: function(projects) {
this.setState({projects: projects});
},
onSearchProject: function() {
this.setState({showSearch: true});
},
onInputMount: function(component) {
var node = React.findDOMNode(component);
if (node) {
node.focus();
}
},
onBlurSearch: function() {
this.setState({showSearch: false});
},
onSearchChange: function(event) {
var query = event.target.value;
this.setState({searchQuery: query});
ProjectActions.readAll({nameQuery: query});
},
render: template,
});
});