| 2154 | } |
| 2155 | |
| 2156 | checkForCourseOption (levelOriginal) { |
| 2157 | const showButton = courseInstance => { |
| 2158 | this.$el.find(`.level-info-container[data-level-original='${levelOriginal}'] .course-version`) |
| 2159 | .removeClass('hidden') |
| 2160 | .data({ 'course-id': courseInstance.get('courseID'), 'course-instance-id': courseInstance.id }) |
| 2161 | } |
| 2162 | |
| 2163 | if (this.courseInstance) { |
| 2164 | showButton(this.courseInstance) |
| 2165 | } else { |
| 2166 | if (!me.get('courseInstances')?.length) { return } |
| 2167 | this.courseOptionsChecked = this.courseOptionsChecked ?? {} |
| 2168 | if (this.courseOptionsChecked[levelOriginal]) { return } |
| 2169 | this.courseOptionsChecked[levelOriginal] = true |
| 2170 | const courseInstances = new CocoCollection([], { url: `/db/course_instance/-/find_by_level/${levelOriginal}`, model: CourseInstance }) |
| 2171 | courseInstances.comparator = ci => -(ci.get('members')?.length ?? 0) |
| 2172 | this.supermodel.loadCollection(courseInstances, 'course_instances') |
| 2173 | this.listenToOnce(courseInstances, 'sync', () => { |
| 2174 | if (this.destroyed) { return } |
| 2175 | const courseInstance = courseInstances.models[0] |
| 2176 | if (courseInstance) { |
| 2177 | showButton(courseInstance) |
| 2178 | } |
| 2179 | }) |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | preloadTopHeroes () { |
| 2184 | for (const heroID of ['captain', 'knight']) { |