-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (37 loc) · 1.01 KB
/
index.js
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
define('pages.Index', function(page) {
var th = this;
var el = $$(page.container);
var subjectId = 1;
removeTemplate('tmlChapters');
compileTemplates(['tmlChapters']);
// load chapters
$$.mb.controller.post({
url: $$.mb.url('api/study/getChapters'),
subjectId: subjectId
}, {
onSuccess: function(box) {
box = $$.mb.cnv.fromJson(box);
var chapters = Template7.templates.tmlChapters({chapters: box.chapters});
el.find('.chapter-list').html(chapters);
}
});
// choose chapter
el.on('click', '.chapter-item', function(e) {
var id = $$(this).closest('.chapter-item').data('id')
// load subchapters
$$.mb.controller.post({
url: $$.mb.url('api/study/getSubChapters'),
chapterId: id
}, {
onSuccess: function(box) {
box = $$.mb.cnv.fromJson(box);
var ctx = $$.extend({}, $$(e.target).closest('.chapter-item').dataset());
ctx.subChapters = box.subChapters;
page.view.router.load({
url: 'pages/chapter.html',
context: ctx
});
}
});
})
});