Code coverage report for src/components/course-settings/add-student.cjsx

Statements: 33.33% (10 / 30)      Branches: 0% (0 / 2)      Functions: 0% (0 / 15)      Lines: 33.33% (10 / 30)      Ignored: none     

All files » src/components/course-settings/ » add-student.cjsx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142                                                                                                                                                                                                                                                                        
var BLANK_STUDENT, BS, BindStoreMixin, Field, React, RosterActions, RosterStore, TutorInput, _, ref;
 
React = require('react');
 
BS = require('react-bootstrap');
 
_ = require('underscore');
 
ref = require('../../flux/roster'), RosterActions = ref.RosterActions, RosterStore = ref.RosterStore;
 
TutorInput = require('../tutor-input').TutorInput;
 
BindStoreMixin = require('../bind-store-mixin');
 
BLANK_STUDENT = {
  first_name: '',
  last_name: '',
  email: '',
  password: ''
};
 
Field = React.createClass({
  displayName: 'AddStudentField',
  propTypes: {
    label: React.PropTypes.string.isRequired,
    name: React.PropTypes.string.isRequired,
    "default": React.PropTypes.string.isRequired,
    onChange: React.PropTypes.func.isRequired,
    autofocus: React.PropTypes.bool
  },
  componentDidMount: function() {
    if (this.props.autofocus) {
      return this.refs.input.focus();
    }
  },
  onChange: function(value) {
    return this.props.onChange(value);
  },
  render: function() {
    return React.createElement(TutorInput, {
      "ref": "input",
      "label": this.props.label,
      "default": this.props["default"],
      "required": true,
      "onChange": this.onChange
    });
  }
});
 
module.exports = React.createClass({
  displayName: 'AddStudentLink',
  propTypes: {
    courseId: React.PropTypes.string.isRequired,
    period: React.PropTypes.object.isRequired
  },
  mixins: [BindStoreMixin],
  bindStore: RosterStore,
  bindEvent: 'created',
  getInitialState: function() {
    return _.clone(BLANK_STUDENT);
  },
  performUpdate: function() {
    var student;
    this.refs.overlay.hide();
    student = _.extend(_.clone(this.state), {
      period_id: this.props.period.id
    });
    RosterActions.create(this.props.courseId, student);
    return this.setState(_.clone(BLANK_STUDENT));
  },
  renderForm: function() {
    return React.createElement(BS.Popover, React.__spread({
      "className": 'teacher-add-student-form',
      "title": 'Student Information:'
    }, this.props), React.createElement(Field, {
      "label": 'First Name',
      "name": 'first_name',
      "default": this.state.first_name,
      "onChange": ((function(_this) {
        return function(val) {
          return _this.setState({
            first_name: val
          });
        };
      })(this)),
      "autofocus": true
    }), React.createElement(Field, {
      "label": 'Last Name',
      "name": 'last_name',
      "default": this.state.last_name,
      "onChange": ((function(_this) {
        return function(val) {
          return _this.setState({
            last_name: val
          });
        };
      })(this))
    }), React.createElement(Field, {
      "label": 'Email',
      "name": 'email',
      "default": this.state.email,
      "onChange": ((function(_this) {
        return function(val) {
          return _this.setState({
            email: val
          });
        };
      })(this))
    }), React.createElement(Field, {
      "label": 'Password',
      "name": 'password',
      "default": this.state.password,
      "onChange": ((function(_this) {
        return function(val) {
          return _this.setState({
            password: val
          });
        };
      })(this))
    }), React.createElement(BS.Button, {
      "block": true,
      "onClick": this.performUpdate
    }, "Create ", React.createElement("i", {
      "className": 'fa fa-angle-double-right'
    })));
  },
  render: function() {
    return React.createElement(BS.OverlayTrigger, {
      "ref": 'overlay',
      "rootClose": true,
      "trigger": 'click',
      "placement": 'right',
      "overlay": this.renderForm()
    }, React.createElement(BS.Button, {
      "block": true
    }, React.createElement("i", {
      "className": 'fa fa-plus'
    }), " Add Student"));
  }
});