1+ < div class ="resources-table-container " data-type ="{{ include.type }} ">
2+ < span id ="loading-data "> < i class ="fa fa-spin fa-spinner "> </ i > Loading, please wait...</ span >
3+ < table id ="resources-data " class ="table table-striped table-condensed " cellspacing ="0 " width ="100% "> </ table >
4+ </ div >
5+
6+ < script type ="text/javascript ">
7+ var MIN_HEIGHT = 0 ;
8+
9+ $ ( document ) . ready ( function ( )
10+ {
11+ var tableContainer = $ ( 'div.resources-table-container' ) ;
12+ var fetchType = tableContainer . data ( 'type' ) ;
13+ var ajaxUrl = '/resources/' + fetchType + '.json' ;
14+
15+ $ . getJSON ( ajaxUrl , function ( response )
16+ {
17+ var dataSet = [ ] ;
18+ for ( var i = 0 ; i < response . results . length ; i ++ )
19+ {
20+
21+ var curResult = response . results [ i ] ;
22+ var verifiedIcon = curResult . verified ? '<i class="fa fa-check"></i>' : '' ;
23+ var level = 'Starting Out' ;
24+ switch ( curResult . level )
25+ {
26+ case 1 : level = 'Some Experience' ; break ;
27+ case 2 : level = 'Very Experienced' ; break ;
28+ }
29+
30+ var curData = [ ] ;
31+ curData . push ( curResult . title ) ;
32+ curData . push ( level ) ;
33+ curData . push ( curResult . description ) ;
34+ curData . push ( curResult . type ) ;
35+ curData . push ( verifiedIcon ) ;
36+ curData . push ( '<a href="' + curResult . link + '" class="btn" target="_blank">Get</a>' ) ;
37+ dataSet . push ( curData ) ;
38+ }
39+ var dataTablesOptions = {
40+ data : dataSet ,
41+ columns : [
42+ {
43+ title : 'Title' ,
44+ className : 'col-title'
45+ } , {
46+ title : 'Level' ,
47+ className : 'col-level'
48+ } , {
49+ title : 'Description' ,
50+ className : 'col-description'
51+ } , {
52+ title : 'Type' ,
53+ className : 'col-type'
54+ } , {
55+ title : 'Verified' ,
56+ className : 'col-verified' ,
57+ searchable : false
58+ } , {
59+ title : '' ,
60+ className : 'col-getbtn' ,
61+ orderable : false ,
62+ searchable : false
63+ }
64+ ] ,
65+ drawCallback : function ( )
66+ {
67+ if ( MIN_HEIGHT === 0 )
68+ {
69+ setTimeout ( function ( )
70+ {
71+ MIN_HEIGHT = $ ( 'div.resources-table-container' ) . height ( ) ;
72+ $ ( 'div.resources-table-container' ) . css ( 'min-height' , MIN_HEIGHT ) ;
73+ } , 1000 ) ;
74+ }
75+ }
76+ } ;
77+ $ ( '#loading-data' ) . fadeOut ( ) ;
78+ $ ( '#resources-data' ) . DataTable ( dataTablesOptions ) ;
79+ } ) ;
80+ } ) ;
81+ </ script >
0 commit comments