@@ -2,13 +2,17 @@ var TextbookCard = {
2
2
name : 'TextbookCard' ,
3
3
dom_target : undefined ,
4
4
term : undefined ,
5
- missing_book_error : false ,
6
5
7
6
render_init : function ( ) {
8
- var term = ( TextbookCard . term === undefined ) ? 'current' : TextbookCard . term ;
9
- WSData . fetch_book_data ( term , TextbookCard . render_upon_data , TextbookCard . textbook_error ) ;
10
- WSData . fetch_course_data_for_term ( term , TextbookCard . render_upon_data , TextbookCard . _render_error ) ;
11
- // may need to add a missing_course_error
7
+ if ( TextbookCard . term === 'current' ) {
8
+ if ( ! window . card_display_dates . is_before_eof_7days_of_term ) {
9
+ $ ( "#TextbookCard" ) . hide ( ) ;
10
+ return ;
11
+ }
12
+ }
13
+
14
+ WSData . fetch_course_data_for_term ( TextbookCard . term , TextbookCard . render_upon_data , TextbookCard . render_error ) ;
15
+ WSData . fetch_book_data ( TextbookCard . term , TextbookCard . render_upon_data , TextbookCard . textbook_error ) ;
12
16
} ,
13
17
14
18
@@ -20,38 +24,32 @@ var TextbookCard = {
20
24
//If more than one data source, multiple callbacks point to this function
21
25
//Delay rendering until all requests are complete
22
26
//Do something smart about not showing error if AJAX is pending
23
- if ( ! TextbookCard . _has_all_data ( ) ) {
24
- return ;
27
+ if ( TextbookCard . _has_all_data ( ) ) {
28
+ TextbookCard . _render ( ) ;
25
29
}
26
- TextbookCard . _render ( ) ;
27
30
} ,
28
31
29
32
textbook_error : function ( ) {
30
- TextbookCard . missing_book_error = true ;
31
- TextbookCard . _render_error ( ) ;
32
- } ,
33
-
34
- _render_error : function ( ) {
35
- if ( TextbookCard . missing_book_error ) {
36
- }
37
- else {
38
- var source = $ ( "#textbook_card" ) . html ( ) ;
39
- var template = Handlebars . compile ( source ) ;
40
- TextbookCard . dom_target . html ( template ( { 'no_books' : true ,
41
- 'term' : TextbookCard . term }
42
- ) ) ;
33
+ var book_error_code = WSData . book_data_error_code ( ) ;
34
+ var course_error_code = WSData . course_data_error_code ( ) ;
35
+ if ( book_error_code === 404 && ( course_error_code === null || course_error_code === 404 ) ) {
36
+ $ ( "#TextbookCard" ) . hide ( ) ;
37
+ return ;
43
38
}
39
+ TextbookCard . dom_target . html ( CardWithError . render ( "Textbook" ) ) ;
44
40
} ,
45
41
46
42
_render : function ( ) {
47
43
var term = TextbookCard . term ;
48
44
var course_data = WSData . course_data_for_term ( term ) ;
45
+ var no_book_assigned = true ;
49
46
var registered = true ;
50
47
var section_book_data = [ ] ;
51
48
if ( course_data . sections . length === 0 ) {
52
49
registered = false ;
53
50
} else {
54
51
var textbook_data = TextBooks . process_book_data ( WSData . book_data ( term ) , course_data ) ;
52
+
55
53
$ . each ( textbook_data . sections , function ( sec_idx , section ) {
56
54
var required = 0 ;
57
55
var optional = 0 ;
@@ -61,18 +59,27 @@ var TextbookCard = {
61
59
} else {
62
60
optional += 1 ;
63
61
}
62
+ if ( no_book_assigned ) {
63
+ no_book_assigned = false ;
64
+ }
64
65
} ) ;
65
66
var course_id = section . curriculum + " " + section . course_number + " " + section . section_id ;
66
67
67
68
var section_data = { "course_id" : course_id ,
69
+ "color_id" : section . color_id ,
68
70
"required" : required ,
69
- "optional" : optional
71
+ "total" : required + optional ,
72
+ "no_course_books" : ( required + optional ) ? false :true
70
73
} ;
71
74
section_book_data . push ( section_data ) ;
72
75
} ) ;
73
76
}
74
77
var template_data = { "registered" : registered ,
75
78
"term" : term ,
79
+ "no_book_assigned" : no_book_assigned ,
80
+ "quarter" : course_data . quarter ,
81
+ "year" : course_data . year ,
82
+ "summer_term" : course_data . summer_term ,
76
83
"sections" : section_book_data } ;
77
84
78
85
var source = $ ( "#textbook_card" ) . html ( ) ;
0 commit comments