Commit 88ca25463b53617a8bea0d42500d8d9d835e3589

Authored by Andrew Buss
1 parent 4b3a411749

fixed broken authorizedFor

Showing 5 changed files with 47 additions and 40 deletions Side-by-side Diff

... ... @@ -67,8 +67,8 @@
67 67 console.log('making the user log in');
68 68 $state.go('login');
69 69 }
70   - if (!UserService.authorizedFor($state, $stateParams)) {
71   - console.log('user not authorized for ' + $state.name);
  70 + if (!UserService.authorizedFor($rootScope.nextState, $rootScope.nextStateParams)) {
  71 + console.log('user not authorized for ' + $rootScope.nextState.name);
72 72 $state.go('addclass');
73 73 }
74 74 };
... ... @@ -169,6 +169,7 @@
169 169 });
170 170 $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
171 171 $rootScope.nextState = toState;
  172 + $rootScope.nextStateParams = toParams;
172 173 console.log('changing state to', toState);
173 174 if (['feed', 'deck', 'cardlist'].indexOf(toState.name) >= 0) {
174 175 localStorage.setItem('last_state', toState.name);
scripts/CardGridController.js View file @ 88ca254
... ... @@ -14,7 +14,7 @@
14 14  
15 15 if (!UserService.isInSection($scope.sectionId)) {
16 16 console.log('user is not enrolled in ' + $scope.sectionId);
17   - return $state.go('addclass');
  17 + $state.go('addclass');
18 18 }
19 19  
20 20 $scope.refreshColumnWidth = function() {
scripts/ClassDropController.js View file @ 88ca254
1 1 angular.module('flashy.ClassDropController', ['ui.router']).
2 2 controller('ClassDropController', function($rootScope, $resource, $scope, $state, $http, UserService) {
3   - $scope.hi = "hi";
  3 + $scope.hi = 'hi';
4 4 $rootScope.SectionResource = $resource('/api/sections/:sectionId/');
5 5 $rootScope.currentSection = {};
6 6 $rootScope.UserService = UserService;
... ... @@ -16,6 +16,6 @@
16 16 console.log('no drop for you');
17 17 });
18 18 };
19   -
  19 +
20 20 });
scripts/FeedController.js View file @ 88ca254
... ... @@ -81,33 +81,10 @@
81 81 });
82 82  
83 83 $scope.pushCard = function() {
84   - var i = 0;
85   - var blanks = [];
86   - $('#new-card-input')[0].childNodes.forEach(function(node) {
87   - if (typeof node.data == 'undefined') {
88   - console.log('undefined node');
89   - }
90   - node = $(node)[0];
91   - if (node.tagName == 'B') {
92   - var text = $(node).text();
93   - console.log(text.length, text);
94   - var leftspaces = 0, rightspaces = 0;
95   - // awful way to find the first non-space character from the left or the right. thanks.js
96   - while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++;
97   - while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++;
98   - if (leftspaces != text.length) blanks.push([i + leftspaces, i + text.length - rightspaces]);
99   - i += text.length;
100   - } else if (!node.data) {
101   - console.log('weird node', node);
102   - i += $(node).text().length;
103   - } else {
104   - i += node.data.length;
105   - }
106   - });
107 84 var myCard = {
108 85 // we can't trim this string because it'd mess up the blanks. Something to fix.
109 86 'text': $('#new-card-input').text(),
110   - 'mask': blanks,
  87 + 'mask': $scope.newCardBlanks,
111 88 section: $scope.section.id
112 89 };
113 90 if (myCard.text == '') {
... ... @@ -159,7 +136,6 @@
159 136 $('#newCard').openModal(modal_options);
160 137 listenForC = false;
161 138 $('#new-card-input').html('Write a flashcard!');
162   -
163 139 };
164 140  
165 141 $scope.closeNewCardModal = function() {
... ... @@ -177,6 +153,8 @@
177 153 $scope.pushCard();
178 154 listenForC = true;
179 155 return false;
  156 + } else {
  157 +
180 158 }
181 159 });
182 160 $('button#blank-selected').click(function() {
183 161  
... ... @@ -184,7 +162,33 @@
184 162 document.execCommand('bold');
185 163 });
186 164 $scope.refreshCards();
  165 + $scope.newCardBlanks = [];
  166 + $scope.refreshNewCardInput = function() {
  167 + $scope.newCardText = $('#new-card-input').text();
  168 + $scope.submit_enabled = $scope.newCardText.length >= 5 && $scope.newCardText.length <= 160;
  169 + $('#new-card-input')[0].childNodes.forEach(function(node) {
  170 + if (typeof node.data == 'undefined') {
  171 + console.log('undefined node');
  172 + }
  173 + node = $(node)[0];
  174 + if (node.tagName == 'B') {
  175 + var text = $(node).text();
  176 + console.log(text.length, text);
  177 + var leftspaces = 0, rightspaces = 0;
  178 + // awful way to find the first non-space character from the left or the right. thanks.js
  179 + while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++;
  180 + while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++;
  181 + if (leftspaces != text.length) $scope.newCardBlanks.push([i + leftspaces, i + text.length - rightspaces]);
  182 + i += text.length;
  183 + } else if (!node.data) {
  184 + console.log('weird node', node);
  185 + i += $(node).text().length;
  186 + } else {
  187 + i += node.data.length;
  188 + }
  189 + });
187 190  
  191 + };
188 192 $scope.shuffleCards = function() {
189 193 $timeout(function() {
190 194 (function(o) {
templates/feed.html View file @ 88ca254
... ... @@ -29,9 +29,9 @@
29 29 <div class="card cyan-text text-darken-2"
30 30 style="width:300px; height:180px; margin-bottom:0; font-size:120%;">
31 31 <div class="valign-wrapper">
32   - <div id="new-card-input" ng-model="newcardtext" style="outline:0px solid transparent;"
  32 + <div id="new-card-input" ng-model="newCardFormattedText" style="outline:0px solid transparent;"
33 33 class="card-content valign center-align"
34   - contenteditable>
  34 + contenteditable select-non-editable="true" ng-change="refreshNewCardInput()">
35 35  
36 36 </div>
37 37 </div>
... ... @@ -45,9 +45,10 @@
45 45  
46 46 </div>
47 47 <div class="row">
48   - <button class="btn modal-close tooltipped" type="submit" ng-click="pushCard()" data-position="left"
49   - data-delay="50" ng-class="newcardtext.length >= 5?{}:'disabled'"
50   - data-tooltip="Enter">Submit
  48 + <button class="btn modal-close tooltipped" type="submit" ng-click="pushCard()"
  49 + data-position="left"
  50 + data-delay="50" ng-class="submit_enabled?{}:'disabled'"
  51 + data-tooltip="Enter">Contribute
51 52 <i class="mdi-hardware-keyboard-return right"></i>
52 53 </button>
53 54 </div>
54 55  
55 56  
... ... @@ -56,14 +57,15 @@
56 57 data-tooltip="Ctrl-B">Blank Selected Text
57 58 </button>
58 59 </div>
59   - <div class="row" ng-show="newcardtext">
60   - {{newcardtext.length}}/160 characters
  60 + <div class="row" ng-show="newCardText" ng-style="(newCardText.length>160)?{color:'red'}:{}">
  61 + {{newCardText.length}}/160 characters
61 62 </div>
62   - <div class="row" ng-show="newcardtext.length < 5">
  63 + <div class="row" ng-show="newCardText.length < 5">
63 64 Please write a little more!
64 65 </div>
65   - <div class="row" ng-show="newcardtext.length > 140">
66   - You'
  66 + <div class="row" ng-show="newCardText.length > 140">
  67 + Good flashcards have a<br>
  68 + single atomic fact
67 69 </div>
68 70 </div>
69 71 </form>