Code coverage report for src/components/tutor-dialog.cjsx

Statements: 90.91% (40 / 44)      Branches: 61.11% (11 / 18)      Functions: 87.5% (14 / 16)      Lines: 90.91% (40 / 44)      Ignored: none     

All files » src/components/ » tutor-dialog.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                                                                 13× 13×                                                                                                                          
var BS, DetachedTutorDialog, DialogProperties, Promise, React, TutorDialog, _;
 
BS = require('react-bootstrap');
 
React = require('react');
 
_ = require('underscore');
 
Promise = require('es6-promise').Promise;
 
DialogProperties = {
  title: React.PropTypes.string.isRequired,
  onOk: React.PropTypes.func.isRequired,
  onCancel: React.PropTypes.func.isRequired,
  body: React.PropTypes.element.isRequired,
  show: React.PropTypes.bool,
  buttons: React.PropTypes.arrayOf(React.PropTypes.element),
  className: React.PropTypes.string
};
 
DetachedTutorDialog = React.createClass({
  displayName: 'DetachedTutorDialog',
  propTypes: DialogProperties,
  getInitialState: function() {
    return {
      show: true
    };
  },
  componentWillReceiveProps: function(nextProps) {
    Eif (nextProps.show != null) {
      return this.setState({
        show: nextProps.show
      });
    }
  },
  _hide: function() {
    return this.setState({
      show: false
    });
  },
  hide: function() {
    this._hide();
    return this.props.onCancel();
  },
  render: function() {
    var buttons, classes;
    if (!this.state.show) {
      return null;
    }
    buttons = this.props.buttons || [
      React.createElement(BS.Button, {
        "key": 'ok',
        "className": 'ok',
        "onClick": _.compose(this.props.onOk, this._hide),
        "bsStyle": 'primary'
      }, "OK"), React.createElement(BS.Button, {
        "key": 'cancel',
        "className": 'cancel',
        "onClick": _.compose(this.props.onCancel, this._hide)
      }, "Cancel")
    ];
    classes = ['tutor-dialog'];
    Iif (this.props.className) {
      classes.push(this.props.className);
    }
    return React.createElement(BS.Modal, {
      "className": classes.join(' '),
      "onRequestHide": this.hide,
      "title": this.props.title
    }, React.createElement("div", {
      "className": 'modal-body'
    }, this.props.body), React.createElement("div", {
      "className": 'modal-footer'
    }, buttons));
  }
});
 
module.exports = TutorDialog = React.createClass({
  displayName: 'TutorDialog',
  propTypes: _.omit(DialogProperties, 'body'),
  componentDidMount: function() {
    var base;
    return TutorDialog.show(_.extend({}, this.props, {
      body: this.props.children
    })).then(((function(_this) {
      return function() {
        var base;
        return typeof (base = _this.props).onOk === "function" ? base.onOk.apply(base, arguments) : void 0;
      };
    })(this)), typeof (base = this.props).onCancel === "function" ? base.onCancel.apply(base, arguments) : void 0);
  },
  componentWillUnmount: function() {
    return TutorDialog.hide(this.props);
  },
  componentWillReceiveProps: function(newProps) {
    return TutorDialog.update(newProps);
  },
  render: function() {
    return null;
  },
  statics: {
    show: function(props) {
      return new Promise((function(_this) {
        return function(onOk, onCancel) {
          var div;
          props = _.extend(_.clone(props), {
            onOk: onOk,
            onCancel: onCancel,
            show: true
          });
          if (_this.dialog) {
            _this.dialog.replaceProps(props);
          } else {
            div = document.body.appendChild(document.createElement('div'));
            div.className = '-tutor-dialog-parent';
            _this.dialog = React.render(React.createElement(DetachedTutorDialog, props), div);
          }
          return _this.dialog;
        };
      })(this));
    },
    hide: function() {
      var ref;
      return (ref = this.dialog) != null ? ref.hide() : void 0;
    },
    update: function(props) {
      var ref;
      return (ref = this.dialog) != null ? ref.setProps(props) : void 0;
    }
  }
});