@@ -41,7 +41,7 @@ $(function () {
4141 //We want the problem to render in a `li` since it will be included in a list
4242 tagName :"li" ,
4343 //Add the 'problem' class to every problem
44- className : "problem" ,
44+ // className: "problem",
4545 //This is the template for a problem, the html is defined in SetMaker3.pm
4646 template : _ . template ( $ ( '#problem-template' ) . html ( ) ) ,
4747
@@ -85,7 +85,6 @@ $(function () {
8585 problem . render ( ) ;
8686 }
8787
88- this . el . setAttribute ( 'data-path' , problem . get ( 'path' ) ) ;
8988 this . el . id = this . model . cid ;
9089
9190
@@ -251,6 +250,124 @@ $(function () {
251250 } ) ;
252251
253252
253+ //##The browse View
254+ var BrowseView = Backbone . View . extend ( {
255+ template :_ . template ( $ ( '#Library-template' ) . html ( ) ) ,
256+
257+ events :{
258+ "click .next_group" : "loadNextGroup"
259+ } ,
260+
261+ initialize : function ( ) {
262+ var self = this ;
263+ this . group_size = 25 ;
264+ this . model . get ( 'problems' ) . on ( 'reset' , this . render , this ) ;
265+ this . model . get ( 'problems' ) . on ( 'syncing' , function ( value ) {
266+ if ( value ) {
267+ $ ( "[href=#" + self . model . get ( 'name' ) + "]" ) . addClass ( "syncing" ) ;
268+ } else {
269+ $ ( "[href=#" + self . model . get ( 'name' ) + "]" ) . removeClass ( "syncing" ) ;
270+ }
271+ } , this ) ;
272+ this . model . get ( 'problems' ) . on ( 'alert' , function ( message ) { alert ( message ) ; } ) ;
273+
274+ if ( ! ( this . model . get ( 'problems' ) . length > 0 ) ) {
275+ this . model . get ( 'problems' ) . fetch ( ) ;
276+ }
277+ } ,
278+
279+ render : function ( ) {
280+
281+ var self = this ;
282+
283+ if ( $ ( '#problems_container #' + this . model . get ( 'name' ) ) . length == 0 ) {
284+ $ ( '#problems_container' ) . tabs ( 'add' , "#" + this . model . get ( 'name' ) , this . model . get ( 'name' ) + " (" + this . model . get ( 'problems' ) . length + ")" ) ; //could move to an after?
285+ this . setElement ( document . getElementById ( this . model . get ( 'name' ) ) ) ;
286+ } else {
287+ //select
288+ $ ( '#problems_container' ) . tabs ( 'select' , this . model . get ( 'name' ) ) ;
289+ $ ( "[href=#" + this . model . get ( 'name' ) + "]" ) . html ( this . model . get ( 'name' ) + " (" + this . model . get ( 'problems' ) . length + ")" ) ;
290+ }
291+
292+ if ( self . model . get ( 'problems' ) . syncing ) {
293+ $ ( "[href=#" + self . model . get ( 'name' ) + "]" ) . addClass ( "syncing" ) ;
294+ }
295+
296+ this . $el . addClass ( "library_tab" ) ;
297+ this . startIndex = 0 ;
298+
299+ var jsonInfo = this . model . toJSON ( ) ;
300+ jsonInfo [ 'group_size' ] = this . group_size ;
301+
302+ jsonInfo [ 'enough_problems' ] = ( this . model . get ( 'problems' ) . length > this . startIndex ) ? "block" : "none" ;
303+
304+ this . $el . html ( this . template ( jsonInfo ) ) ;
305+
306+ this . loadNextGroup ( ) ;
307+
308+ return this ;
309+ } ,
310+ //Define a new function loadNextGroup so that we can just load a few problems at once,
311+ //otherwise things get unwieldy :P
312+ loadNextGroup : function ( ) {
313+
314+ var problems = this . model . get ( 'problems' ) ;
315+ console . log ( problems . length ) ;
316+ for ( var i = 0 ; i < this . group_size && this . startIndex < problems . length ; i ++ , this . startIndex ++ ) {
317+ console . log ( "adding a problem" ) ;
318+ var problem = problems . at ( this . startIndex ) ;
319+ var view = new ProblemView ( { model : problem , remove_display : true } ) ;
320+ this . $ ( ".list" ) . append ( view . render ( ) . el ) ;
321+ }
322+
323+ if ( ! ( this . model . get ( 'problems' ) . length > this . startIndex ) ) {
324+ this . $ ( ".next_group" ) . css ( 'display' , "none" ) ;
325+ }
326+ }
327+
328+ } ) ;
329+
330+ var BrowseListView = Backbone . View . extend ( {
331+ tagName :'span' ,
332+ template :_ . template ( $ ( '#LibraryList-template' ) . html ( ) ) ,
333+
334+ events : {
335+ //'change .list': 'lib_selected'
336+ } ,
337+
338+ initialize :function ( ) {
339+ var self = this ;
340+ this . model . on ( "change:library_subjects" , this . render , this ) ;
341+ this . model . on ( "change:library_chapters" , this . render , this ) ;
342+ this . model . on ( "change:library_section" , this . render , this ) ;
343+ } ,
344+
345+ render :function ( ) {
346+
347+ var self = this ;
348+ if ( self . model . syncing ) {
349+ self . $el . addClass ( "syncing white" ) ;
350+ }
351+ this . $el . html ( this . template ( { name : this . options . name } ) ) ;
352+ self . $ ( "." + this . options . name + ".list" ) . on ( 'change' , function ( event ) { self . lib_selected ( event ) } ) ;
353+ this . addAll ( ) ;
354+ return this ;
355+ } ,
356+
357+ section_selected :function ( event ) {
358+ var self = this ;
359+ self . $el . removeClass ( "syncing white" ) ;
360+ var selectedLib = this . model . getByCid ( event . target . value ) ;
361+ if ( selectedLib ) {
362+ var view = new LibraryListView ( { model :selectedLib . get ( 'children' ) , name : selectedLib . cid } ) ;
363+ this . $ ( '.' + this . options . name + ".children" ) . html ( view . render ( ) . el ) ;
364+ libToLoad = selectedLib ;
365+ }
366+ }
367+
368+ } ) ;
369+
370+
254371 //##The main Set view
255372 var SetView = Backbone . View . extend ( {
256373 template :_ . template ( $ ( '#set-template' ) . html ( ) ) ,
@@ -341,7 +458,7 @@ $(function () {
341458 var self = this ;
342459 this . model . get ( 'problems' ) . on ( 'all' , function ( ) { self . render ( ) } , this ) ;
343460 this . model . get ( 'problems' ) . on ( 'alert' , function ( message ) { alert ( message ) ; } ) ;
344- this . model . on ( 'highlight' , function ( ) { self . $el . addClass ( "contains_problem" ) } ) ;
461+ this . model . on ( 'highlight' , function ( ) { console . log ( "highlight " + self . model . get ( 'name' ) ) ; self . $el . addClass ( "contains_problem" ) } ) ;
345462 } ,
346463
347464 render :function ( ) {
@@ -506,9 +623,7 @@ $(function () {
506623 highlightSets : function ( event ) {
507624 switch ( event . type ) {
508625 case "mouseenter" :
509- //console.log(this.getAttribute("data-path"));
510626 var problemPath = event . currentTarget . getAttribute ( "data-path" ) ;
511-
512627 this . homeworkSets . each ( function ( set ) {
513628 if ( set . get ( 'problems' ) . find ( function ( problem ) { return problem . get ( 'path' ) == problemPath } ) ) {
514629 set . trigger ( 'highlight' ) ;
0 commit comments