/**
 * Created by YouHan on 2016/6/14.
 */
(function () {
    var React = require('react');
    var api = require('./../common/api');

    var MD = require('material-ui');
    var RaisedButton = MD.RaisedButton;
    var Card = MD.Card;
    var CardText = MD.CardText;
    var CardHeader = MD.CardHeader;
    var CardActions = MD.CardActions;

    var ProjectToggle = React.createClass({
        click: function () {
            var me = this;
            api.project.updateRelease(this.props.item).then(function () {
                me.props.update();
            });
        },
        render: function () {
            return (
                <Card className="manage-project-list-card">
                    <CardText>
                        <b>{this.props.item.name}</b><br/>
                        <span>Current Release : {this.props.item.releaseName}</span>
                        <RaisedButton label="Next Release" primary={true} onClick={this.click}></RaisedButton>
                    </CardText>
                </Card>
            )
        }
    });

    var ProjectManage = React.createClass({
        getInitialState: function () {
            return {
                list: []
            }
        },
        componentWillMount: function () {
            this.reload();
        },
        reload: function () {
            var me = this
            api.project.get().then(function (data) {
                me.setState({
                    list: data.val()
                })
            })
        },
        renderLi: function (item) {
            if (item.id !== 999) {
                return (
                    <ProjectToggle item={item} key={item.id} update={this.reload}></ProjectToggle>
                );
            }
        },
        render: function () {
            return (
                <div>
                    <Card className="projectCard">
                        <CardHeader
                            title="Project"
                            actAsExpander={true}
                            showExpandableButton={true}
                        />
                        <CardText expandable={true}>
                            {this.state.list.map(this.renderLi)}
                        </CardText>
                        <CardActions expandable={true}>
                        </CardActions>
                    </Card>
                </div>
            )
        }
    });
    module.exports = ProjectManage;
})();
@@ -334,16 +334,50 @@
 Actions;
+%0A    var TextField = MD.TextField;
 %0A%0A    va
@@ -1220,16 +1220,45 @@
 list: %5B%5D
+,%0A                project: ''
 %0A       
@@ -1530,16 +1530,49 @@
 ta.val()
+,%0A                    project: ''
 %0A       
@@ -1574,32 +1574,33 @@
               %7D)
+;
 %0A            %7D)%0A
@@ -1598,16 +1598,17 @@
       %7D)
+;
 %0A       
@@ -1862,387 +1862,1305 @@
     
-render: function () %7B%0A            return (%0A                %3Cdiv%3E%0A                    %3CCard className=%22projectCard%22%3E%0A                        %3CCardHeader%0A                            title=%22Project%22%0A                            actAsExpander=%7Btrue%7D%0A                            showExpandableButton=%7Btrue%7D%0A                        /%3E%0A                        %3CCardText expandable=%7Btrue%7D
+changeProject: function (e) %7B%0A            this.setState(%7B%0A                list: this.state.list,%0A                project: e.target.value%0A            %7D);%0A        %7D,%0A        add: function () %7B%0A            var me = this;%0A            api.project.save(%7B%0A                name: this.state.project%0A            %7D).then(function () %7B%0A                me.reload();%0A            %7D);%0A        %7D,%0A        render: function () %7B%0A            return (%0A                %3Cdiv%3E%0A                    %3CCard className=%22projectCard%22%3E%0A                        %3CCardHeader%0A                            title=%22Project%22%0A                            actAsExpander=%7Btrue%7D%0A                            showExpandableButton=%7Btrue%7D%0A                        /%3E%0A                        %3CCardText expandable=%7Btrue%7D%3E%0A                            %3CCard className=%22manage-project-list-card%22%3E%0A                                %3CCardText%3E%0A                                    %3CTextField%0A                                        value=%7Bthis.state.project%7D%0A                                        onChange=%7Bthis.changeProject%7D%0A                                    /%3E%0A                                    %3CRaisedButton label=%22Add%22 primary=%7Btrue%7D onClick=%7Bthis.add%7D%3E%3C/RaisedButton%3E%0A                                %3C/CardText%3E%0A                            %3C/Card
 %3E%0A  

add project in manage page