Application.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var React = require('react'),
  2. ReactDOM = require('react-dom'),
  3. classNames = require('classnames'),
  4. Core = require('./core.js').Core,
  5. ThingModal = require('./ThingModal.js'),
  6. ThingList = require('./ThingList.js'),
  7. SearchBox = require('./SearchBox.js');
  8. var Application = React.createClass({
  9. handleThingAdd: function () {
  10. this.refs.modalAdd.openModal();
  11. },
  12. handleThingEdit: function (thing) {
  13. this.refs.modalAdd.openModal(thing);
  14. },
  15. handleThingDelete: function (thing) {
  16. console.log('del', thing)
  17. },
  18. getInitialState: function () {
  19. return { data: [], busy: false };
  20. },
  21. componentDidMount: function () {
  22. this.refresh();
  23. },
  24. refresh: function () {
  25. var that = this;
  26. that.setState({ data: [], busy: true });
  27. Core.thingsGet('', function (error, result) {
  28. if (error) return console.error(error);
  29. that.setState({ data: result, busy: false });
  30. });
  31. },
  32. render: function () {
  33. var things = this.state.busy ? <center><i className="spinner"></i></center> : <ThingList data={this.state.data} onEdit={this.handleThingEdit} onDelete={this.handleThingDelete}/>;
  34. return (
  35. <div>
  36. <ThingModal ref="modalAdd" onAdded={this.refresh} onUpdated={this.refresh}/>
  37. <div className="container">
  38. <div className="row">
  39. <div className="col-md-4"></div>
  40. <div className="col-md-4">
  41. <button role="button" className="btn btn-success btn-block" onClick={this.handleThingAdd}>Add</button>
  42. </div>
  43. <div className="col-md-4"></div>
  44. </div>
  45. <div className="row">
  46. <div className="col-md-2"></div>
  47. <div className="col-md-8">
  48. <SearchBox />
  49. </div>
  50. <div className="col-md-2"></div>
  51. </div>
  52. <div className="row">
  53. <div className="col-md-2"></div>
  54. <div className="col-md-8">
  55. {things}
  56. </div>
  57. <div className="col-md-2"></div>
  58. </div>
  59. </div>
  60. </div>
  61. );
  62. }
  63. });
  64. module.exports = Application;