| 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 | 2×
2×
2×
2×
2×
2×
2×
209×
209×
209×
209×
59×
209×
209×
209×
188×
188×
187×
187×
187×
130×
188×
188×
209×
209×
209×
209×
209×
209×
209×
209×
21×
20×
1×
188×
188×
188×
| var CourseStore, NewTabLink, React, _;
React = require('react');
_ = require('underscore');
NewTabLink = require('../new-tab-link');
CourseStore = require('../../flux/course').CourseStore;
module.exports = React.createClass({
displayName: 'BrowseTheBook',
contextTypes: {
router: React.PropTypes.func
},
getDefaultProps: function() {
return {
bsStyle: 'primary',
onlyShowBrowsable: true
};
},
propTypes: {
courseId: React.PropTypes.string,
ecosystemId: React.PropTypes.string,
chapterId: React.PropTypes.number,
sectionId: React.PropTypes.number,
page: React.PropTypes.string,
unstyled: React.PropTypes.bool,
onlyShowBrowsable: React.PropTypes.bool,
bsStyle: React.PropTypes.string
},
getLinkProps: function() {
var linkProps, omitProps, transferProps;
linkProps = {
className: 'view-reference-guide'
};
Iif (this.props.className) {
linkProps.className += " " + this.props.className;
}
if (!this.props.unstyled) {
linkProps.className += " btn btn-" + this.props.bsStyle;
}
omitProps = _.chain(this.propTypes).keys().union(['children', 'className', 'unstyled']).value();
transferProps = _.omit(this.props, omitProps);
return _.extend({}, transferProps, linkProps);
},
buildRouteProps: function(courseId) {
var courseEcosystemId, ecosystemId, linkType, queryParams, ref, routeProps;
if (!this.props.page) {
ecosystemId = this.props.ecosystemId;
courseEcosystemId = (ref = CourseStore.get(courseId)) != null ? ref.ecosystem_id : void 0;
if (ecosystemId !== courseEcosystemId) {
queryParams = {
ecosystemId: ecosystemId
};
}
}
linkType = this.props.page ? 'viewReferenceBookPage' : this.props.section ? 'viewReferenceBookSection' : 'viewReferenceBook';
return routeProps = {
to: linkType,
params: {
courseId: courseId,
cnxId: this.props.page,
section: this.props.section
},
query: queryParams
};
},
getCourseId: function() {
return this.props.courseId || this.context.router.getCurrentParams().courseId;
},
canBrowse: function(courseId) {
var ref;
return (courseId != null) && !((ref = CourseStore.get(courseId)) != null ? ref.is_concept_coach : void 0);
},
render: function() {
var courseId, linkProps, routeProps, text;
courseId = this.getCourseId();
text = this.props.children || 'Browse the Book';
linkProps = this.getLinkProps();
if (!this.canBrowse(courseId)) {
if (this.props.onlyShowBrowsable) {
return null;
} else {
return React.createElement("span", React.__spread({}, linkProps), text);
}
}
routeProps = this.buildRouteProps(courseId);
linkProps = _.extend({}, routeProps, linkProps);
return React.createElement(NewTabLink, React.__spread({}, linkProps), text);
}
});
|