| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- var React = require('react'),
- ReactDOM = require('react-dom'),
- classNames = require('classnames'),
- Core = require('./core.js').Core,
- ThingModal = require('./ThingModal.js'),
- ThingList = require('./ThingList.js'),
- SearchBox = require('./SearchBox.js');
- var Application = React.createClass({
- handleThingAdd: function () {
- this.refs.modalAdd.openModal();
- },
- handleThingEdit: function (thing) {
- this.refs.modalAdd.openModal(thing);
- },
- handleThingDelete: function (thing) {
- console.log('del', thing)
- },
- getInitialState: function () {
- return { data: [], busy: false };
- },
- componentDidMount: function () {
- this.refresh();
- },
- refresh: function () {
- var that = this;
- that.setState({ data: [], busy: true });
- Core.thingsGet('', function (error, result) {
- if (error) return console.error(error);
- that.setState({ data: result, busy: false });
- });
- },
- render: function () {
- var things = this.state.busy ? <center><i className="spinner"></i></center> : <ThingList data={this.state.data} onEdit={this.handleThingEdit} onDelete={this.handleThingDelete}/>;
- return (
- <div>
- <ThingModal ref="modalAdd" onAdded={this.refresh} onUpdated={this.refresh}/>
- <div className="container">
- <div className="row">
- <div className="col-md-4"></div>
- <div className="col-md-4">
- <button role="button" className="btn btn-success btn-block" onClick={this.handleThingAdd}>Add</button>
- </div>
- <div className="col-md-4"></div>
- </div>
- <div className="row">
- <div className="col-md-2"></div>
- <div className="col-md-8">
- <SearchBox />
- </div>
- <div className="col-md-2"></div>
- </div>
- <div className="row">
- <div className="col-md-2"></div>
- <div className="col-md-8">
- {things}
- </div>
- <div className="col-md-2"></div>
- </div>
- </div>
- </div>
- );
- }
- });
- module.exports = Application;
|