Blame view
scripts/CardListController.js
5.01 KB
dc454dbeb
|
1 2 |
angular.module('flashy.CardListController', ['ui.router', 'angular.filter', 'ngSanitize', 'flashy.DeckFactory']). controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams, Flashcard, Deck) { |
dc71f53b1
|
3 |
// cards array |
dc454dbeb
|
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
sectionId = parseInt($stateParams.sectionId); $scope.deck = new Deck(sectionId, { cardPullCallback: function(card) { Materialize.toast('Pulled!', 3000); }, cardUnpullCallback: function(card) { Materialize.toast('Unpulled!', 3000); }, cardHideCallback: function(card) { card.is_hidden = true; Materialize.toast('Hidden!', 3000); }, cardUnhideCallback: function(card) { card.is_hidden = false; Materialize.toast('Unhidden!', 3000); } }); |
dc71f53b1
|
21 22 |
$rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); $scope.cards = []; |
54c942ddf
|
23 |
|
ff2397443
|
24 |
$http.get('/api/sections/' + sectionId + '/flashcards/?hidden=yes'). |
4c3a5e272
|
25 |
success(function(data) { |
dc454dbeb
|
26 |
for (i in data) $scope.cards[data[i].id] = new Flashcard(data[i], $scope.deck); |
dc71f53b1
|
27 |
}). |
4c3a5e272
|
28 |
error(function(err) { |
dc71f53b1
|
29 30 |
console.log('pulling feed failed'); }); |
5466bf8e0
|
31 |
|
e52721a27
|
32 |
// flag/report card |
362cfb056
|
33 34 35 36 |
$scope.flag = function(card) { $http.post('/api/flashcards/' + card.id + '/report/'). success(function(data) { console.log(card.text + ' reported'); |
362cfb056
|
37 38 |
}). error(function(err) { |
e52721a27
|
39 |
console.log('no flag for you'); |
362cfb056
|
40 41 |
}); }; |
dc71f53b1
|
42 |
// toggle button text from show to hide |
4c3a5e272
|
43 44 45 46 47 |
$(function() { $('#showHidden').click(function() { $(this).text(function(i, text) { return text === 'Show Hidden' ? 'Hide Hidden' : 'Show Hidden'; }); |
dc71f53b1
|
48 49 |
}); }); |
e52721a27
|
50 |
|
4c3a5e272
|
51 |
$scope.$on('$destroy', function() { |
dc71f53b1
|
52 53 54 |
$rootScope.currentSection = {}; $(document).off('keydown'); }); |
54c942ddf
|
55 |
|
107013870
|
56 |
$(document).ready(function() { |
362cfb056
|
57 58 59 60 61 62 63 64 65 66 67 68 |
$('.tooltipped').tooltip({delay: 50}); //back to top var offset = 300; var duration = 300; $(window).scroll(function() { if ($(this).scrollTop() > offset) { $('.back-to-top').fadeIn(duration); } else { $('.back-to-top').fadeOut(duration); } }); |
e52721a27
|
69 |
$('.back-to-top').click(function(event) { |
362cfb056
|
70 |
event.preventDefault(); |
e52721a27
|
71 |
$('html, body').animate({scrollTop: 0}, duration); |
362cfb056
|
72 |
return false; |
107013870
|
73 |
}); |
362cfb056
|
74 |
}); |
8bc4d0271
|
75 |
|
362cfb056
|
76 |
// to display day of the week badges |
8bc4d0271
|
77 |
$scope.dayofweek = function(item) { |
70c2390ab
|
78 79 |
var date = new Date(item.material_date); return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; |
8bc4d0271
|
80 |
}; |
de7bd6a9b
|
81 82 |
// checkbox filter $scope.filter = { |
70c2390ab
|
83 84 85 86 87 88 89 90 91 92 |
'week1': true, 'week2': true, 'week3': true, 'week4': true, 'week5': true, 'week6': true, 'week7': true, 'week8': true, 'week9': true, 'week10': true, |
de7bd6a9b
|
93 94 95 |
}; $scope.filterByDate = function(item) { |
70c2390ab
|
96 97 98 99 100 101 102 103 104 105 106 |
var week = item.material_week_num; return (week == 1 && $scope.filter['week1']) || (week == 2 && $scope.filter['week2']) || (week == 3 && $scope.filter['week3']) || (week == 4 && $scope.filter['week4']) || (week == 5 && $scope.filter['week5']) || (week == 6 && $scope.filter['week6']) || (week == 7 && $scope.filter['week7']) || (week == 8 && $scope.filter['week8']) || (week == 9 && $scope.filter['week9']) || (week == 10 && $scope.filter['week10']); |
de7bd6a9b
|
107 |
}; |
dc454dbeb
|
108 109 110 111 |
$scope.$on('$destroy', function() { $scope.deck.cleanup(); Flashcard.cleanup(); }); |
de7bd6a9b
|
112 |
|
dc71f53b1
|
113 |
} |
36887911f
|
114 |
). |
70c2390ab
|
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
filter('displayCard', function($sce) { return function(card) { // text to display as html var cardText = ''; var start = 0; // where to start next string break // get all display pieces and blank pieces for (var i = 0; i < card.mask.length; i++) { cardText = cardText.concat(card.text.substring(start, card.mask[i][0])); cardText = cardText.concat('<b>'); cardText = cardText.concat(card.text.substring(card.mask[i][0], card.mask[i][1])); cardText = cardText.concat('</b>'); start = card.mask[i][1]; } // get remaining dislay pieces, if any if (start != card.mask.length - 1) cardText = cardText.concat(card.text.substring(start)); return $sce.trustAsHtml(cardText); }; }); |