From 88ca25463b53617a8bea0d42500d8d9d835e3589 Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Mon, 1 Jun 2015 03:54:35 -0700 Subject: [PATCH] fixed broken authorizedFor --- config.js | 5 ++-- scripts/CardGridController.js | 2 +- scripts/ClassDropController.js | 4 ++-- scripts/FeedController.js | 54 +++++++++++++++++++++++------------------- templates/feed.html | 22 +++++++++-------- 5 files changed, 47 insertions(+), 40 deletions(-) diff --git a/config.js b/config.js index dcd83f5..b352550 100644 --- a/config.js +++ b/config.js @@ -67,8 +67,8 @@ angular.module('flashy', [ console.log('making the user log in'); $state.go('login'); } - if (!UserService.authorizedFor($state, $stateParams)) { - console.log('user not authorized for ' + $state.name); + if (!UserService.authorizedFor($rootScope.nextState, $rootScope.nextStateParams)) { + console.log('user not authorized for ' + $rootScope.nextState.name); $state.go('addclass'); } }; @@ -169,6 +169,7 @@ angular.module('flashy', [ }); $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { $rootScope.nextState = toState; + $rootScope.nextStateParams = toParams; console.log('changing state to', toState); if (['feed', 'deck', 'cardlist'].indexOf(toState.name) >= 0) { localStorage.setItem('last_state', toState.name); diff --git a/scripts/CardGridController.js b/scripts/CardGridController.js index d771ef9..2d5e64b 100644 --- a/scripts/CardGridController.js +++ b/scripts/CardGridController.js @@ -14,7 +14,7 @@ angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSoc if (!UserService.isInSection($scope.sectionId)) { console.log('user is not enrolled in ' + $scope.sectionId); - return $state.go('addclass'); + $state.go('addclass'); } $scope.refreshColumnWidth = function() { diff --git a/scripts/ClassDropController.js b/scripts/ClassDropController.js index 6dc901c..e715fd5 100644 --- a/scripts/ClassDropController.js +++ b/scripts/ClassDropController.js @@ -1,6 +1,6 @@ angular.module('flashy.ClassDropController', ['ui.router']). controller('ClassDropController', function($rootScope, $resource, $scope, $state, $http, UserService) { - $scope.hi = "hi"; + $scope.hi = 'hi'; $rootScope.SectionResource = $resource('/api/sections/:sectionId/'); $rootScope.currentSection = {}; $rootScope.UserService = UserService; @@ -16,5 +16,5 @@ angular.module('flashy.ClassDropController', ['ui.router']). console.log('no drop for you'); }); }; - + }); diff --git a/scripts/FeedController.js b/scripts/FeedController.js index 9cc8ea5..bb9c843 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -81,33 +81,10 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' }); $scope.pushCard = function() { - var i = 0; - var blanks = []; - $('#new-card-input')[0].childNodes.forEach(function(node) { - if (typeof node.data == 'undefined') { - console.log('undefined node'); - } - node = $(node)[0]; - if (node.tagName == 'B') { - var text = $(node).text(); - console.log(text.length, text); - var leftspaces = 0, rightspaces = 0; - // awful way to find the first non-space character from the left or the right. thanks.js - while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; - while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; - if (leftspaces != text.length) blanks.push([i + leftspaces, i + text.length - rightspaces]); - i += text.length; - } else if (!node.data) { - console.log('weird node', node); - i += $(node).text().length; - } else { - i += node.data.length; - } - }); var myCard = { // we can't trim this string because it'd mess up the blanks. Something to fix. 'text': $('#new-card-input').text(), - 'mask': blanks, + 'mask': $scope.newCardBlanks, section: $scope.section.id }; if (myCard.text == '') { @@ -159,7 +136,6 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' $('#newCard').openModal(modal_options); listenForC = false; $('#new-card-input').html('Write a flashcard!'); - }; $scope.closeNewCardModal = function() { @@ -177,6 +153,8 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' $scope.pushCard(); listenForC = true; return false; + } else { + } }); $('button#blank-selected').click(function() { @@ -184,7 +162,33 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' document.execCommand('bold'); }); $scope.refreshCards(); + $scope.newCardBlanks = []; + $scope.refreshNewCardInput = function() { + $scope.newCardText = $('#new-card-input').text(); + $scope.submit_enabled = $scope.newCardText.length >= 5 && $scope.newCardText.length <= 160; + $('#new-card-input')[0].childNodes.forEach(function(node) { + if (typeof node.data == 'undefined') { + console.log('undefined node'); + } + node = $(node)[0]; + if (node.tagName == 'B') { + var text = $(node).text(); + console.log(text.length, text); + var leftspaces = 0, rightspaces = 0; + // awful way to find the first non-space character from the left or the right. thanks.js + while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; + while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; + if (leftspaces != text.length) $scope.newCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); + i += text.length; + } else if (!node.data) { + console.log('weird node', node); + i += $(node).text().length; + } else { + i += node.data.length; + } + }); + }; $scope.shuffleCards = function() { $timeout(function() { (function(o) { diff --git a/templates/feed.html b/templates/feed.html index 3ea235e..dcc5c3c 100644 --- a/templates/feed.html +++ b/templates/feed.html @@ -29,9 +29,9 @@
-
+ contenteditable select-non-editable="true" ng-change="refreshNewCardInput()">
@@ -45,9 +45,10 @@
-
@@ -56,14 +57,15 @@ data-tooltip="Ctrl-B">Blank Selected Text -
- {{newcardtext.length}}/160 characters +
+ {{newCardText.length}}/160 characters
-
+
Please write a little more!
-
- You' +
+ Good flashcards have a
+ single atomic fact
-- 1.9.1