Code coverage report for src/components/course-settings/delete-period.cjsx

Statements: 75% (24 / 32)      Branches: 40% (4 / 10)      Functions: 80% (4 / 5)      Lines: 75% (24 / 32)      Ignored: none     

All files » src/components/course-settings/ » delete-period.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                                                                     108× 108× 108× 108×     36× 36× 36×       36× 36×       36×       36×     36×                           36×                                
var BS, CourseGroupingLabel, EMPTY_WARNING, PeriodActions, PeriodStore, React, RosterActions, RosterStore, TutorInput, _, ref, ref1;
 
React = require('react');
 
BS = require('react-bootstrap');
 
_ = require('underscore');
 
ref = require('../../flux/period'), PeriodActions = ref.PeriodActions, PeriodStore = ref.PeriodStore;
 
ref1 = require('../../flux/roster'), RosterActions = ref1.RosterActions, RosterStore = ref1.RosterStore;
 
TutorInput = require('../tutor-input').TutorInput;
 
CourseGroupingLabel = require('../course-grouping-label');
 
EMPTY_WARNING = 'EMPTY';
 
module.exports = React.createClass({
  displayName: 'DeletePeriodLink',
  propTypes: {
    courseId: React.PropTypes.string.isRequired,
    periods: React.PropTypes.array.isRequired,
    activeTab: React.PropTypes.object.isRequired,
    selectPreviousTab: React.PropTypes.func.isRequired
  },
  getInitialState: function() {
    return {
      warning: ''
    };
  },
  performUpdate: function() {
    var id;
    if (this.isPeriodEmpty()) {
      this.refs.overlay.hide();
      this.props.selectPreviousTab();
      id = this.props.activeTab.id;
      return PeriodActions["delete"](id, this.props.courseId);
    } else {
      return this.setState({
        warning: EMPTY_WARNING
      });
    }
  },
  isPeriodEmpty: function() {
    var id, students;
    id = this.props.activeTab.id;
    students = RosterStore.getActiveStudentsForPeriod(this.props.courseId, id);
    return students.length === 0;
  },
  renderForm: function() {
    var deleteButton, deleteQuestion, title, warning;
    Eif (!this.isPeriodEmpty()) {
      this.state.warning = EMPTY_WARNING;
    } else {
      this.state.warning = '';
    }
    deleteQuestion = "Delete '" + this.props.activeTab.name + "'?";
    deleteButton = React.createElement(BS.Button, {
      "className": '-edit-period-confirm',
      "onClick": this.performUpdate
    }, "Delete");
    warning = this.state.warning === EMPTY_WARNING ? React.createElement("span", null, "Only ", React.createElement(CourseGroupingLabel, {
      "courseId": this.props.courseId,
      "lowercase": true
    }), "s without\nstudents enrolled can be deleted.") : void 0;
    title = React.createElement("h4", null, "Delete ", React.createElement(CourseGroupingLabel, {
      "courseId": this.props.courseId
    }));
    return React.createElement(BS.Modal, React.__spread({}, this.props, {
      "title": title,
      "className": "teacher-edit-period-modal"
    }), React.createElement("div", {
      "className": 'modal-body teacher-edit-period-form'
    }, React.createElement("div", {
      "className": '-delete-question'
    }, (this.isPeriodEmpty() ? deleteQuestion : void 0)), React.createElement("div", {
      "className": 'warning'
    }, warning)), React.createElement("div", {
      "className": 'modal-footer'
    }, (this.isPeriodEmpty() ? deleteButton : void 0)));
  },
  render: function() {
    return React.createElement(BS.OverlayTrigger, {
      "ref": 'overlay',
      "rootClose": true,
      "trigger": 'click',
      "overlay": this.renderForm()
    }, React.createElement(BS.Button, {
      "bsStyle": 'link',
      "className": 'edit-period'
    }, React.createElement("i", {
      "className": 'fa fa-trash-o'
    }), "Delete ", React.createElement(CourseGroupingLabel, {
      "courseId": this.props.courseId
    })));
  }
});