Commit c6ac1ffcfc334ab6f9c76d4639c1181ccbc0ca92

Authored by Andrew Buss
1 parent ab5a8bc0fb

refactor; $timeout for add card as well

Showing 1 changed file with 19 additions and 35 deletions Side-by-side Diff

scripts/FeedController.js View file @ c6ac1ff
... ... @@ -60,15 +60,20 @@
60 60 };
61 61  
62 62 $scope.add = function(card) {
63   - console.log('adding card');
64   - for (i = 0; i < $scope.cardCols.length; i++) {
65   - if ($scope.cardCols[i].length == 0) {
66   - $scope.cardCols[i].unshift(card);
67   - return;
68   - }
  63 +
  64 + var colNum = 0;
  65 + while (colNum < $scope.numCols) {
  66 + if ($scope.cardCols[colNum].length == 0) break;
  67 + colNum++;
69 68 }
70   - var colNum = Math.floor(Math.random() * $scope.numCols);
71   - $scope.cardCols[colNum].unshift(card);
  69 + if (colNum == $scope.numCols) {
  70 + colNum = Math.floor(Math.random() * $scope.numCols);
  71 + }
  72 + console.log('adding card to column ' + colNum);
  73 + console.log(card);
  74 + $timeout(function() {
  75 + $scope.cardCols[colNum].unshift(card);
  76 + });
72 77 };
73 78  
74 79 $scope.hide = function(card) {
... ... @@ -86,18 +91,6 @@
86 91 console.log(card);
87 92 };
88 93  
89   - /* Instance creation */
90   - $http.get('/api/sections/' + sectionId + '/feed/').
91   - success(function(data) {
92   - console.log(data);
93   - $scope.cards = data;
94   - $scope.refreshLayout();
95   - console.log('success in refresh cards...');
96   - }).
97   - error(function(err) {
98   - console.log('pulling feed failed');
99   - });
100   -
101 94 var loc = window.location, new_uri;
102 95 if (loc.protocol === 'https:') {
103 96 new_uri = 'wss:';
104 97  
... ... @@ -138,9 +131,8 @@
138 131 i += node.data.length;
139 132 }
140 133 });
141   - text = $('#new-card-input').text();
142 134 var myCard = {
143   - 'text': text,
  135 + 'text': $('#new-card-input').text(),
144 136 'mask': blanks,
145 137 section: sectionId
146 138 };
... ... @@ -154,8 +146,6 @@
154 146 error(function(error) {
155 147 console.log('something went wrong pushing a card!');
156 148 });
157   - listenForC = true;
158   - $('#new-card-input').html('');
159 149 };
160 150  
161 151 /* Key bindings for the whole feed window. Hotkey it up! */
162 152  
163 153  
... ... @@ -183,20 +173,16 @@
183 173  
184 174 $(document).keydown(function(e) {
185 175 var keyed = e.which;
186   - if (keyed == 67 && listenForC) { // "c" or "C" for compose
  176 + if (keyed == 67 && listenForC) { // "c" for compose
187 177 $('#newCard').openModal(modal_options);
188 178 e.preventDefault();
189 179 listenForC = false;
190 180 return false;
191   - } else if (keyed == 27) { // enter or esc, respectively
  181 + } else if (keyed == 27) { // clear on ESC
192 182 listenForC = true;
193 183 document.getElementById('new-card-input').value = '';
194 184 }
195 185 });
196   - $scope.flashcard = '';
197   - $scope.text = '';
198   - var selected_start = 0;
199   - var selected_end = 0;
200 186 $(document).ready(function() {
201 187 $('.tooltipped').tooltip({delay: 50});
202 188 // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
203 189  
204 190  
205 191  
... ... @@ -205,20 +191,18 @@
205 191 if (e.which == 13) {
206 192 e.preventDefault();
207 193 $scope.pushCard();
  194 + $('#new-card-input').html('');
208 195 $('#newCard').closeModal(modal_options);
  196 + listenForC = true;
209 197 return false;
210 198 }
211 199 });
212   - $('#new-card-input').on('mouseup', function() {
213   - console.log('got selection: ' + selected_start);
214   - });
215 200 $('button#blank-selected').click(function() {
216 201 console.log(window.getSelection());
217 202 document.execCommand('bold');
218 203 });
219 204 });
220   - //$scope.refreshCards();
221   - //$scope.refreshLayout();
  205 + $scope.refreshCards();
222 206 $scope.$on('$destroy', function() {
223 207 ws.close();
224 208 $rootScope.currentSection = {};