github.com/komosa/bug@v0.3.1/bug-serve/jsx/BugApp.js (about) 1 var BugApp = React.createClass({ 2 3 componentDidMount: function() { 4 var that = this; 5 AjaxGet("/issues/", function(response) { 6 that.setState({ 7 "Bugs" : JSON.parse(response) 8 }); 9 }); 10 AjaxGet("/settings", function(response) { 11 that.setState({ 12 "Settings" : JSON.parse(response) 13 }); 14 }) 15 }, 16 getInitialState : function() { 17 return { 18 "Settings" : {}, 19 "Title" : "Open Issues", 20 "Bugs": [], 21 "SelectedBugJSON" : null 22 } 23 }, 24 selectBugHandler: function(e) { 25 e.preventDefault(); 26 var bug = e.currentTarget.textContent; 27 var that = this; 28 AjaxGet("/issues/" + bug + "?format=json", function(response) { 29 that.setState({SelectedBug : JSON.parse(response)}); 30 }); 31 }, 32 resetSelected: function() { 33 this.setState({ "SelectedBug" : null}); 34 }, 35 render: function() { 36 var content; 37 if(this.state.SelectedBug != null) { 38 content = <BugPage Title={this.state.SelectedBug.Title} Description={this.state.SelectedBug.Description} onBack={this.resetSelected} AllBugs={this.state.Bugs} onOtherBugClicked={this.selectBugHandler}/> 39 } else { 40 content = <BugList Title={this.state.Title} Bugs={this.state.Bugs} onBugClicked={this.selectBugHandler} /> 41 } 42 return (<div> 43 <h1>Issues for: {this.state.Settings.Title}</h1> 44 <div> 45 {content} 46 </div> 47 </div>); 48 } 49 }); 50 51 var AjaxGet = function(url, callback) { 52 var xmlhttp = new XMLHttpRequest(); 53 xmlhttp.onreadystatechange = function() { 54 if (this.readyState === 4 && this.status == 200) { 55 callback(this.responseText) 56 } 57 } 58 xmlhttp.open("GET", url, true); 59 xmlhttp.send() 60 }