Blame view
scripts/FlashcardFactory.js
3.18 KB
140291561
|
1 |
angular.module('flashy.FlashcardFactory', ['ui.router']). |
a8ff455c2
|
2 |
factory('Flashcard', function ($http, UserService) { |
bf0941f00
|
3 |
var FlashcardCache = []; |
5673511eb
|
4 |
var Deck = null; |
99e9786ec
|
5 |
var Flashcard = function (data) { |
bf0941f00
|
6 |
if (typeof data == 'number') return FlashcardCache[data]; |
5673511eb
|
7 |
if (FlashcardCache[data.id]) return FlashcardCache[data.id]; |
140291561
|
8 |
for (var k in data) this[k] = data[k]; |
140291561
|
9 10 11 12 |
this.textPieces = []; this.mask.sort(function (a, b) { return a[0] - b[0]; }); |
140291561
|
13 14 15 16 17 18 19 |
var i = 0; this.mask.forEach(function (blank) { this.textPieces.push({text: this.text.slice(i, blank[0])}); this.textPieces.push({text: this.text.slice(blank[0], blank[1]), blank: true}); i = blank[1]; }, this); this.textPieces.push({text: this.text.slice(i)}); |
0dfc72586
|
20 21 22 23 24 |
this.formatted_text = ''; for (i in this.textPieces) { p = this.textPieces[i]; this.formatted_text += p.blank ? '<b>' + p.text + '</b>' : p.text; } |
14c79dd79
|
25 26 27 28 |
this.moveUp = false; this.moveDown = false; this.colNum = 0; this.colRank = 0; |
bf0941f00
|
29 |
FlashcardCache[this.id] = this; |
140291561
|
30 |
}; |
70c2390ab
|
31 |
|
140291561
|
32 |
Flashcard.prototype.isInDeck = function () { |
dc454dbeb
|
33 |
return !(typeof Deck.contains(this.id) === 'undefined'); |
140291561
|
34 |
}; |
43f34fa03
|
35 |
Flashcard.prototype.pullUnpull = function () { |
b06f64922
|
36 |
if (this.isInDeck()) this.unpull(); |
aa99249e0
|
37 |
else this.pull(); |
140291561
|
38 39 |
}; Flashcard.prototype.pull = function () { |
70c2390ab
|
40 |
if (this.isInDeck()) return console.log('Not pulling', this.id, "because it's already in deck"); |
140291561
|
41 42 43 |
return $http.post('/api/flashcards/' + this.id + '/pull/'); }; Flashcard.prototype.unpull = function () { |
70c2390ab
|
44 |
if (!this.isInDeck()) return console.log('Not unpulling', this.id, "because it's not in deck"); |
140291561
|
45 46 47 48 49 |
return $http.post('/api/flashcards/' + this.id + '/unpull/'); }; Flashcard.prototype.hide = function () { return $http.post('/api/flashcards/' + this.id + '/hide/'); }; |
dc454dbeb
|
50 51 52 53 54 55 56 |
Flashcard.prototype.unhide = function () { return $http.post('/api/flashcards/' + this.id + '/unhide/'); }; Flashcard.cleanup = function () { Deck = null; FlashcardCache = []; }; |
99e9786ec
|
57 58 59 |
Flashcard.linkDeck = function(deck){ Deck = deck; } |
140291561
|
60 |
|
a8ff455c2
|
61 62 63 64 |
Flashcard.prototype.edit = function () { var editableText = this.formatted_text; |
a8ff455c2
|
65 66 67 68 69 70 71 72 |
$('.modal-trigger').leanModal({ dismissible: true, // Modal can be dismissed by clicking outside of the modal opacity: .5, // Opacity of modal background in_duration: 300, // Transition in duration out_duration: 200, // Transition out duration ready: function () { $('#edit-card-input').html(editableText); |
a8ff455c2
|
73 74 75 76 77 78 79 80 81 |
}, // Callback for Modal open complete: function () { console.log("EDIT MODAL CLOSED"); } // Callback for Modal close }); }; |
a8ff455c2
|
82 |
|
45cc59836
|
83 84 85 |
|
a8ff455c2
|
86 87 88 |
|
45cc59836
|
89 |
|
fbb202c4c
|
90 |
|
a8ff455c2
|
91 |
|
140291561
|
92 |
return Flashcard; |
aa99249e0
|
93 |
}); |