kellykamay

getdatayear

Aug 4th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //js ko
  2.  
  3. $(document).ready(function() {
  4.    
  5.     let storyTemplate;
  6.     var storyCategory = {};
  7.  
  8.     function getDataByYear(theYear){
  9.         $.ajax({
  10.                 url : '/api/calendar/'+theYear+'/',
  11.                 dataType : 'json',
  12.                 type : 'GET',
  13.                 success: function(data)
  14.                 {
  15.                    
  16.                     // console.log(data)
  17.                     storyTemplate = _.template($('#paper-holder').html());
  18.                     let valuetoPass = storyTemplate({stories:data});
  19.                     $('.paper-box').html(valuetoPass);
  20.  
  21.                 }
  22.         });        
  23.     }
  24.    
  25.     $.ajax({
  26.         url : '/api/category/',
  27.             dataType : 'json',
  28.             type : 'GET',
  29.             success: function(data){
  30.                  
  31.                 // console.log(data);
  32.                storyCategory = data;
  33.                
  34.             }
  35.     });
  36.     console.log(storyCategory);
  37.     _.template.showcatecolor = function (theCateId) {
  38.         for (var i = 0; i < storyCategory.length; i++) {
  39.             if (storyCategory[i].id == theCateId)  {
  40.                 return storyCategory[i].color;
  41.             }
  42.            
  43.         }
  44.         return storyCategory.id[theCateId]
  45.     };
  46.  
  47.     _.template.showmonth = function (themonth) {
  48.         let monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  49.         let d = new Date(themonth); // or d = new Date(date)
  50.            
  51.         return monthNames[d.getMonth()];
  52.     };
  53.  
  54.     //display all years with events
  55.     for (var i = 0; i < allYearsArr.length; i++) {
  56.         $('.slidee').append(
  57.             "<li class='yearitem'>"+allYearsArr[i]+"</li>"
  58.         );
  59.     }
  60.  
  61.     getDataByYear(latestYear);
  62. });
Advertisement
Add Comment
Please, Sign In to add comment