Blame view

scripts/FlashcardFactory.js 3.18 KB
140291561   Andrew Buss   EMMM VEEEE SEEEE
1
  angular.module('flashy.FlashcardFactory', ['ui.router']).
a8ff455c2   Kevin Mach   editing card in p...
2
      factory('Flashcard', function ($http, UserService) {
bf0941f00   Andrew Buss   continue refactor...
3
          var FlashcardCache = [];
5673511eb   Andrew Buss   more feed refacto...
4
          var Deck = null;
99e9786ec   Andrew Buss   try to fix issue ...
5
          var Flashcard = function (data) {
bf0941f00   Andrew Buss   continue refactor...
6
              if (typeof data == 'number') return FlashcardCache[data];
5673511eb   Andrew Buss   more feed refacto...
7
              if (FlashcardCache[data.id]) return FlashcardCache[data.id];
140291561   Andrew Buss   EMMM VEEEE SEEEE
8
              for (var k in data) this[k] = data[k];
140291561   Andrew Buss   EMMM VEEEE SEEEE
9
10
11
12
              this.textPieces = [];
              this.mask.sort(function (a, b) {
                  return a[0] - b[0];
              });
140291561   Andrew Buss   EMMM VEEEE SEEEE
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   Andrew Buss   more refactoring;...
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   Tetranoir   animations incomp...
25
26
27
28
  			this.moveUp = false;
  			this.moveDown = false;
  			this.colNum = 0;
  			this.colRank = 0;
bf0941f00   Andrew Buss   continue refactor...
29
              FlashcardCache[this.id] = this;
140291561   Andrew Buss   EMMM VEEEE SEEEE
30
          };
70c2390ab   Andrew Buss   unbreak deck, car...
31

140291561   Andrew Buss   EMMM VEEEE SEEEE
32
          Flashcard.prototype.isInDeck = function () {
dc454dbeb   Andrew Buss   card list vaguely...
33
              return !(typeof Deck.contains(this.id) === 'undefined');
140291561   Andrew Buss   EMMM VEEEE SEEEE
34
          };
43f34fa03   Andrew Buss   more refactoring;...
35
          Flashcard.prototype.pullUnpull = function () {
b06f64922   Andrew Buss   fix pullUnpull fo...
36
              if (this.isInDeck()) this.unpull();
aa99249e0   Rachel Lee   Fix ugly flashcar...
37
              else this.pull();
140291561   Andrew Buss   EMMM VEEEE SEEEE
38
39
          };
          Flashcard.prototype.pull = function () {
70c2390ab   Andrew Buss   unbreak deck, car...
40
              if (this.isInDeck()) return console.log('Not pulling', this.id, "because it's already in deck");
140291561   Andrew Buss   EMMM VEEEE SEEEE
41
42
43
              return $http.post('/api/flashcards/' + this.id + '/pull/');
          };
          Flashcard.prototype.unpull = function () {
70c2390ab   Andrew Buss   unbreak deck, car...
44
              if (!this.isInDeck()) return console.log('Not unpulling', this.id, "because it's not in deck");
140291561   Andrew Buss   EMMM VEEEE SEEEE
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   Andrew Buss   card list vaguely...
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   Andrew Buss   try to fix issue ...
57
58
59
          Flashcard.linkDeck = function(deck){
              Deck = deck;
          }
140291561   Andrew Buss   EMMM VEEEE SEEEE
60

a8ff455c2   Kevin Mach   editing card in p...
61
62
63
64
          Flashcard.prototype.edit = function () {
  
  
            var editableText = this.formatted_text;
a8ff455c2   Kevin Mach   editing card in p...
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   Kevin Mach   editing card in p...
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   Kevin Mach   editing card in p...
82

45cc59836   Kevin Mach   edit stuff
83
84
85
  		
  		
          
a8ff455c2   Kevin Mach   editing card in p...
86
87
88
  
        
          
45cc59836   Kevin Mach   edit stuff
89
          
fbb202c4c   Kevin Mach   made a few change...
90

a8ff455c2   Kevin Mach   editing card in p...
91

140291561   Andrew Buss   EMMM VEEEE SEEEE
92
          return Flashcard;
aa99249e0   Rachel Lee   Fix ugly flashcar...
93
      });