FeedController.js
2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
angular.module('flashy.FeedController', ['ui.router']).
controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function($scope, $stateParams, $state, $http) {
console.log('Hello from feed');
sectionId = $stateParams.sectionId;
$scope.cards = [];
$scope.cards[0] = {'id': 1, 'title': 'title1', 'content': 'abc'};
$scope.cards[1] = {'id': 2, 'title': 'title2', 'content': 'xyz'};
$scope.cards[2] = {'id': 2, 'title': 'title3', 'content': 'qwe'};
$http.get('/api/sections/' + sectionId + '/flashcards/').
success(function(data) {
for (var i = 0; i < data.length; i++) {
cards.push({'title': data[i].title, 'content': data[i].content});
}
}).
error(function(err) {
console.log('no');
});
$scope.viewDeck = function() {
$state.go('deck');
console.log('go to deck');
};
$scope.pullCard = function(card) {
var index = $scope.cards.indexOf(card);
console.log($scope.cards[index]);
};
$scope.pushCard = function() {
console.log('make! card content:' + $scope.text);
var pushed = new Date(Date.now());
console.log(pushed.toString());
// attempt to make card :(
$http.post('/api/flashcards/', {'text': $scope.text, 'pushed': pushed, 'mask': []}).
success(function(data) {
console.log('No way, really?');
}).
error(function(error) {
console.log('haha, n00b');
});
$scope.text = '';
};
$scope.flashcard = 'hi i am a flashcard. I need to be really long and awesome I ain\'t ' +
'know how long I am right now. Is it good enough now?????????? Howz about now???';
$scope.text = '';
$(document).ready(function() {
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal({
dismissible: true, // Modal can be dismissed by clicking outside of the modal
opacity: 0, // Opacity of modal background
in_duration: 300, // Transition in duration
out_duration: 200, // Transition out duration
/*ready: function() { alert('Ready'); }, // Callback for Modal open
complete: function() { alert('Closed'); } // Callback for Modal close*/
}
);
});
}]);