Code coverage report for src/components/task-plan/footer.cjsx

Statements: 64.06% (41 / 64)      Branches: 69.23% (18 / 26)      Functions: 50% (6 / 12)      Lines: 64.06% (41 / 64)      Ignored: none     

All files » src/components/task-plan/ » footer.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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180                                                           19×                                         19× 19× 19× 19×                                                                               27× 27× 27× 27× 27× 27× 27× 27× 27× 27× 26×                   26×         26×                             27×                   27× 21×                 27×              
var AsyncButton, BS, BackButton, PlanFooter, PlanHelper, PlanPublishActions, PlanPublishStore, React, Router, TaskPlanActions, TaskPlanStore, TutorDialog, ref, ref1;
 
React = require('react');
 
BS = require('react-bootstrap');
 
Router = require('react-router');
 
ref = require('../../flux/task-plan'), TaskPlanStore = ref.TaskPlanStore, TaskPlanActions = ref.TaskPlanActions;
 
ref1 = require('../../flux/plan-publish'), PlanPublishStore = ref1.PlanPublishStore, PlanPublishActions = ref1.PlanPublishActions;
 
PlanHelper = require('../../helpers/plan');
 
AsyncButton = require('openstax-react-components').AsyncButton;
 
TutorDialog = require('../tutor-dialog');
 
BackButton = require('../buttons/back-button');
 
PlanFooter = React.createClass({
  displayName: 'PlanFooter',
  contextTypes: {
    router: React.PropTypes.func
  },
  propTypes: {
    id: React.PropTypes.string.isRequired,
    courseId: React.PropTypes.string.isRequired,
    goBackToCalendar: React.PropTypes.func
  },
  getDefaultProps: function() {
    return {
      goBackToCalendar: (function(_this) {
        return function() {
          return _this.context.router.transitionTo('taskplans', {
            courseId: courseId
          });
        };
      })(this)
    };
  },
  getInitialState: function() {
    return {
      isEditable: TaskPlanStore.isEditable(this.props.id),
      publishing: TaskPlanStore.isPublishing(this.props.id),
      saving: TaskPlanStore.isSaving(this.props.id)
    };
  },
  checkPublishingStatus: function(published) {
    var planId, planStatus;
    planId = this.props.id;
    if (published["for"] === planId) {
      planStatus = {
        publishing: PlanPublishStore.isPublishing(planId)
      };
      this.setState(planStatus);
      if (PlanPublishStore.isDone(planId)) {
        PlanPublishStore.removeAllListeners("progress." + planId + ".*", this.checkPublishingStatus);
        return TaskPlanActions.load(planId);
      }
    }
  },
  componentWillMount: function() {
    var plan, publishState;
    plan = TaskPlanStore.get(this.props.id);
    publishState = PlanHelper.subscribeToPublishing(plan, this.checkPublishingStatus);
    return this.setState({
      publishing: publishState.isPublishing
    });
  },
  saved: function() {
    var courseId;
    courseId = this.props.courseId;
    TaskPlanStore.removeChangeListener(this.saved);
    return this.props.goBackToCalendar();
  },
  onDelete: function() {
    var courseId, id, ref2;
    ref2 = this.props, id = ref2.id, courseId = ref2.courseId;
    if (confirm('Are you sure you want to delete this?')) {
      TaskPlanActions["delete"](id);
      return this.props.goBackToCalendar();
    }
  },
  onSave: function() {
    this.setState({
      saving: true,
      publishing: false
    });
    return this.props.onSave();
  },
  onPublish: function() {
    this.setState({
      publishing: true,
      saving: false,
      isEditable: TaskPlanStore.isEditable(this.props.id)
    });
    return this.props.onPublish();
  },
  onViewStats: function() {
    var courseId, id, ref2;
    ref2 = this.props, id = ref2.id, courseId = ref2.courseId;
    return this.context.router.transitionTo('viewStats', {
      courseId: courseId,
      id: id
    });
  },
  render: function() {
    var backButton, backToCalendarParams, cancelButton, clickedSelectProblem, courseId, deleteLink, deleteable, getBackToCalendarParams, helpInfo, id, isEditable, isFailed, isWaiting, onCancel, onPublish, onSave, plan, publishButton, ref2, saveLink, saveable, tips;
    ref2 = this.props, id = ref2.id, courseId = ref2.courseId, clickedSelectProblem = ref2.clickedSelectProblem, onPublish = ref2.onPublish, onSave = ref2.onSave, onCancel = ref2.onCancel, getBackToCalendarParams = ref2.getBackToCalendarParams;
    isEditable = this.state.isEditable;
    plan = TaskPlanStore.get(id);
    saveable = !(TaskPlanStore.isPublished(id) || TaskPlanStore.isPublishing(id));
    isWaiting = TaskPlanStore.isSaving(id) || TaskPlanStore.isPublishing(id) || TaskPlanStore.isDeleteRequested(id);
    deleteable = !TaskPlanStore.isNew(id) && !(TaskPlanStore.isOpened(id) && TaskPlanStore.isPublished(id)) && !isWaiting;
    isFailed = TaskPlanStore.isFailed(id);
    tips = React.createElement(BS.Popover, null, React.createElement("p", null, React.createElement("strong", null, "Publish"), " will make the assignment visible to students on the open date.\nIf open date is today, it will be available immediately."), React.createElement("p", null, React.createElement("strong", null, "Cancel"), " will discard all changes and return to the calendar."), React.createElement("p", null, React.createElement("strong", null, "Save as draft"), " will add the assignment to the teacher calendar only.\nIt will not be visible to students, even if the open date has passed."));
    if (isEditable) {
      publishButton = React.createElement(AsyncButton, {
        "bsStyle": 'primary',
        "className": '-publish',
        "onClick": this.onPublish,
        "isWaiting": isWaiting && this.state.publishing,
        "isFailed": isFailed,
        "waitingText": 'Publishing…',
        "disabled": isWaiting,
        "isJob": true
      }, 'Publish');
      cancelButton = React.createElement(BS.Button, {
        "aria-role": 'close',
        "disabled": isWaiting,
        "onClick": onCancel
      }, "Cancel");
      helpInfo = React.createElement(BS.OverlayTrigger, {
        "trigger": 'click',
        "placement": 'top',
        "overlay": tips,
        "rootClose": true
      }, React.createElement(BS.Button, {
        "className": "footer-instructions",
        "bsStyle": "link"
      }, React.createElement("i", {
        "className": "fa fa-info-circle"
      })));
    } else {
      backToCalendarParams = getBackToCalendarParams();
      backButton = React.createElement(Router.Link, React.__spread({}, backToCalendarParams, {
        "className": 'btn btn-default'
      }), "Back to Calendar");
    }
    if (deleteable) {
      deleteLink = React.createElement(AsyncButton, {
        "className": 'delete-link pull-right',
        "onClick": this.onDelete,
        "isWaiting": TaskPlanStore.isDeleting(id),
        "isFailed": isFailed,
        "waitingText": 'Deleting…'
      }, React.createElement("i", {
        "className": "fa fa-trash"
      }), " Delete Assignment");
    }
    if (saveable) {
      saveLink = React.createElement(AsyncButton, {
        "className": '-save',
        "onClick": this.onSave,
        "isWaiting": isWaiting && this.state.saving,
        "isFailed": isFailed,
        "waitingText": 'Saving…',
        "disabled": isWaiting
      }, 'Save as Draft');
    }
    return React.createElement("div", {
      "className": 'footer-buttons'
    }, publishButton, cancelButton, backButton, saveLink, helpInfo, deleteLink);
  }
});
 
module.exports = PlanFooter;