var BS, ChapterSectionType, PerformanceForecast, React, _;
React = require('react');
BS = require('react-bootstrap');
_ = require('underscore');
PerformanceForecast = require('../../flux/performance-forecast');
ChapterSectionType = require('./chapter-section-type');
module.exports = React.createClass({
displayName: 'PracticeButton',
propTypes: {
courseId: React.PropTypes.string.isRequired,
title: React.PropTypes.string.isRequired,
sections: React.PropTypes.arrayOf(ChapterSectionType)
},
contextTypes: {
router: React.PropTypes.func
},
onClick: function() {
var courseId, page_ids, ref, sections;
ref = this.props, courseId = ref.courseId, sections = ref.sections;
page_ids = PerformanceForecast.Helpers.pagesForSections(sections);
Eif (!_.isEmpty(page_ids)) {
return this.context.router.transitionTo('viewPractice', {
courseId: courseId
}, {
page_ids: page_ids
});
}
},
render: function() {
var button, classNames, isDisabled, page_ids, sections, tooltip;
sections = this.props.sections;
page_ids = PerformanceForecast.Helpers.pagesForSections(sections);
classNames = ['practice', this.props.practiceType];
isDisabled = _.isEmpty(page_ids);
if (isDisabled) {
classNames.push('disabled');
}
button = React.createElement(BS.Button, {
"className": classNames.join(' '),
"onClick": this.onClick
}, this.props.title, React.createElement("i", null));
if (isDisabled) {
tooltip = React.createElement(BS.Tooltip, null, "No problems are available for practicing");
return React.createElement(BS.OverlayTrigger, {
"placement": 'top',
"overlay": tooltip
}, button);
} else {
return button;
}
}
});
|