se-hub/templates/js/controllers/campusesController.js
Matan Bar Yosef 380228947b -Bugs fixing
- Create class bug - fixed

- Work in progress (classes, projects) - need to check API
2015-06-27 12:45:44 +03:00

70 lines
1.7 KiB
JavaScript

angular.module('SeHub')
.controller('campusesController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope)
{
$scope.threeSizedArray =[];
$scope.campusesEmpty = false;
var token = $cookies['com.sehub.www'];
apiService.getCampusesByUser(token).success(function(data) // Get all the campuses
{
$scope.campuses = data;
console.log("INSIDE " + $scope.campuses);
init(); // Executing the function to initialize campuses display
}).error(function() {
// TODO
});
console.log($scope.campuses);
var init = function()
{
var i, j, counter = 0;
var newLength = 0;
if($scope.campuses != null)
{
if(($scope.campuses.length % 3) === 0)
{
newLength = ($scope.campuses.length / 3);
}
else
{
newLength = (Math.ceil($scope.campuses.length / 3)); // Rounds number up
}
console.log("length: " + newLength);
$scope.threeSizedArray.length = newLength;
for(j = 0; j < newLength; j++)
{
$scope.threeSizedArray[j] = [3]; // Creating array in size of 3 in each array cell
}
for(i = 0; i < newLength; i++)
{
for(j = 0; j < newLength; j++)
{
if($scope.campuses[(3*i) + j] != null)
{
$scope.threeSizedArray[i][j] = $scope.campuses[(3*i) + j];
}
}
}
}
else
{
$scope.campusesEmpty = true;
}
console.log($scope.threeSizedArray); // TODO REMOVE
}
$scope.goToCampus = function(campusId) // Will pass you to courses by specific campus
{
$location.path('/myClasses/' + campusId.toString());
}
}]);