diff --git a/scripts/CardListController.js b/scripts/CardListController.js
index e30a4ae..34a856c 100644
--- a/scripts/CardListController.js
+++ b/scripts/CardListController.js
@@ -105,7 +105,7 @@ angular.module('flashy.CardListController', ['ui.router', 'angular.filter']).
$(document).off('keydown');
});
- $(document).ready(function(){
+ $(document).ready(function() {
$('.tooltipped').tooltip({delay: 50});
//back to top
@@ -123,27 +123,27 @@ angular.module('flashy.CardListController', ['ui.router', 'angular.filter']).
event.preventDefault();
jQuery('html, body').animate({scrollTop: 0}, duration);
return false;
- })
+ });
});
// to display day of the week badges
$scope.dayofweek = function(item) {
var date = new Date(item.material_date);
- switch(date.getDay()) {
+ switch (date.getDay()) {
case 0:
- return "Su";
+ return 'Su';
case 1:
- return "M";
+ return 'M';
case 2:
- return "T";
+ return 'T';
case 3:
- return "W";
+ return 'W';
case 4:
- return "R";
+ return 'R';
case 5:
- return "F";
+ return 'F';
case 6:
- return "Sa";
+ return 'Sa';
}
};
diff --git a/scripts/FeedController.js b/scripts/FeedController.js
index 737ae86..a1ef7f0 100644
--- a/scripts/FeedController.js
+++ b/scripts/FeedController.js
@@ -2,12 +2,16 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate']).
controller('FeedController', function($scope, $rootScope, $stateParams, $state, $http, $window, $timeout, UserService) {
console.log('Hello from feed');
- sectionId = $stateParams.sectionId;
+ sectionId = parseInt($stateParams.sectionId);
+ if (!UserService.isInSection(sectionId)) {
+ return $state.go('addclass');
+ }
$rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId});
$scope.cards = false;
$scope.cardCols = []; // organized data
$scope.numCols = 0;
+
function calculate_cols() {
var avail = $window.innerWidth - 17;
return Math.max(1, Math.floor(avail / 250));
@@ -59,6 +63,7 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate']).
}).
error(function(err) {
console.log('refresh fail');
+ console.log(err);
});
};
@@ -130,20 +135,20 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate']).
ws.onclose = function(e) {
console.log('connection closed');
};
-
- var resetModal = function() {
- $('#new-card-input').html('');
+
+ var resetModal = function() {
+ $('#new-card-input').html('');
$('#newCard').closeModal(modal_options);
- }
-
+ };
+
$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');
- return resetModal();
- }
+ if (typeof node.data == 'undefined') {
+ console.log('undefined node');
+ return resetModal();
+ }
node = $(node)[0];
console.log(node);
if (node.tagName == 'B') {
@@ -159,10 +164,10 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate']).
'mask': blanks,
section: sectionId
};
- if (myCard.text == '') {
- console.log('blank flashcard not pushed:' + myCard.text);
- return resetModal();
- }
+ if (myCard.text == '') {
+ console.log('blank flashcard not pushed:' + myCard.text);
+ return resetModal();
+ }
$http.post('/api/flashcards/', myCard).
success(function(data) {
console.log('flashcard pushed: ' + myCard.text);
@@ -174,7 +179,7 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate']).
error(function(error) {
console.log('something went wrong pushing a card!');
});
- return resetModal();
+ return resetModal();
};
/* Key bindings for the whole feed window. Hotkey it up! */
diff --git a/scripts/HelpController.js b/scripts/HelpController.js
index 0a1ad8f..87fc336 100644
--- a/scripts/HelpController.js
+++ b/scripts/HelpController.js
@@ -1,6 +1,6 @@
angular.module('flashy.HelpController', ['ui.router']).
controller('HelpController', ['$scope', '$state', '$http', '$timeout', 'UserService',
- function ($scope, $state, $http, $timeout, UserService) {
+ function($scope, $state, $http, $timeout, UserService) {
}
]);
diff --git a/scripts/RootController.js b/scripts/RootController.js
index 3c2ed35..6388155 100644
--- a/scripts/RootController.js
+++ b/scripts/RootController.js
@@ -1,6 +1,6 @@
angular.module('flashy.RootController', ['ui.router', 'ngResource']).
- controller('RootController', function ($rootScope, $resource, $scope, $state, UserService, $window, $templateCache) {
+ controller('RootController', function($rootScope, $resource, $scope, $state, UserService, $window, $templateCache) {
$rootScope.SectionResource = $resource('/api/sections/:sectionId/');
window.rootscope = $rootScope;
window.userservice = UserService;
@@ -18,7 +18,7 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource']).
closeOnClick: true // Closes side-nav on
clicks, useful for Angular/Meteor
}
);
- var postlogin = function (data) {
+ var postlogin = function(data) {
$scope.user = data;
//UserService.redirectToDefaultState($state);
};
@@ -36,14 +36,14 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource']).
new_uri += '//' + loc.host;
var ws = new WebSocket(new_uri + '/ws/rce/?subscribe-broadcast');
- ws.onopen = function () {
+ ws.onopen = function() {
console.log('websocket connected');
};
- ws.onmessage = function (e) {
+ ws.onmessage = function(e) {
console.log('got websocket message ' + e.data);
data = JSON.parse(e.data);
if (data.event_type == 'reload') {
- Materialize.toast('This page will refresh in 10 seconds and clear the template cache. Sorry for the inconvenience!', 10000, '', function () {
+ Materialize.toast('This page will refresh in 10 seconds and clear the template cache.', 10000, '', function() {
$templateCache.removeAll();
$window.location.reload();
});
@@ -52,23 +52,23 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource']).
eval(data.command);
}
};
- ws.onerror = function (e) {
+ ws.onerror = function(e) {
console.error(e);
};
- ws.onclose = function (e) {
+ ws.onclose = function(e) {
console.log('connection closed');
};
- $rootScope.$on('account_locked', function () {
+ $rootScope.$on('account_locked', function() {
UserService.logout();
if ($rootScope.locked_toast_active) return;
$rootScope.locked_toast_active = true;
- Materialize.toast('Thanks for trying Flashy! To ensure quality content, we ask that you verify your email before continuing', 4000, '', function () {
+ Materialize.toast('Thanks for trying Flashy! To ensure quality content, we ask that you verify your email before continuing', 4000, '', function() {
$rootScope.locked_toast_active = undefined;
});
$state.go('login');
});
- $rootScope.$on('server_error', function (error) {
+ $rootScope.$on('server_error', function(error) {
Materialize.toast('A server error occurred! Proceed with caution', 4000);
});
diff --git a/scripts/UserService.js b/scripts/UserService.js
index f7ec45a..767da1e 100644
--- a/scripts/UserService.js
+++ b/scripts/UserService.js
@@ -41,6 +41,9 @@ angular.module('flashy.UserService', ['ui.router']).
rv = this.isResolved() && _user.email;
return rv;
};
+ this.isInSection = function(sectionId) {
+ return (_user.sectionIdList.indexOf(sectionId) > 0);
+ };
this.redirectToDefaultState = function($state) {
console.log('redirecting user to their default state');
if (!this.isLoggedIn()) return $state.go('login');