jce-mobile-app/www/js/controllers.js

491 lines
22 KiB
JavaScript
Raw Normal View History

2015-01-10 22:11:51 +00:00
angular.module('starter.controllers', [])
/*======================================
= AppCtrl - Main =
======================================*/
.controller('AppCtrl', function($scope, $ionicModal, $timeout, $ionicPopup, $ionicViewService, $location) {
2015-01-10 22:11:51 +00:00
$scope.lock = {};
2015-01-10 22:11:51 +00:00
var newNotes = false;
$scope.logged = false;
var userStr = window.localStorage['userInfo'] || null;
if(userStr !== null)
$scope.userData = JSON.parse(userStr);
else
$scope.userData = null;
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/Aouth.html', {
2015-01-10 22:11:51 +00:00
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
if((window.localStorage['userInfo'] || null) === null )
$scope.isLoggedIn = false;
else
$scope.isLoggedIn = true;
2015-01-10 22:11:51 +00:00
// Triggered in the Aouth modal to close it
$scope.closeAouth = function() {
2015-01-10 22:11:51 +00:00
$scope.modal.hide();
};
// Aouth for Grades
$scope.Aouth = function() {
console.log("Clicked GoOn - password enterd: "+ $scope.lock.password + "\nThe logs pass is: "+window.localStorage['password']);
if($scope.lock.password === (window.localStorage['password'] || null)){ //ok
$scope.lock.password = "";
$scope.modal.hide();
$ionicViewService.nextViewOptions({
disableBack: true });
$location.path( "/app/grades" );
}else{
var alertPopup = $ionicPopup.alert({
title: 'סיסמה שגוייה',
template: 'טעות בסיסמה'
});
alertPopup.then(function(res) {
$scope.modal.hide();
});
}
2015-01-10 22:11:51 +00:00
};
$scope.logout = function(){
localStorage.clear();
navigator.app.exitApp();
};
$scope.openGrades = function(){
var localSettingsStr = window.localStorage['Settings'] || null;
if (localSettingsStr !== null){
var isLocked = (JSON.parse(localSettingsStr))[0].val;
}
if(isLocked){
console.log("[JCE] [INFO]: Grades Locked");
$scope.modal.show();
}
else{
console.log("Unlocked");
$ionicViewService.nextViewOptions({
disableBack: true });
$location.path( "/app/grades" );
}
};
2015-01-10 22:11:51 +00:00
$scope.menuClicked = function(){
if((window.localStorage['userInfo'] || null) === null ){
$scope.isLoggedIn = false;
}else
$scope.isLoggedIn = true;
};
2015-01-10 22:11:51 +00:00
})
////////////////////////////////////////////////////////////////
.controller('PlaylistsCtrl', function($scope) {
$scope.playlists = [
{ title: 'Reggae', id: 1 },
{ title: 'Chill', id: 2 },
{ title: 'Dubstep', id: 3 },
{ title: 'Indie', id: 4 },
{ title: 'Rap', id: 5 },
{ title: 'Cowbell', id: 6 }
];
})
.controller('PlaylistCtrl', function($scope, $stateParams) {
})
/*=============================================
= Grades - controller =
=============================================*/
.controller('GradesCtrl', function($scope, $stateParams, $http) {
var gradesStr = window.localStorage['grades'] || null;
var fixGrades = new Array;
var j = 0;
//console.log(gradesStr);
if(gradesStr != null){
grades = JSON.parse(gradesStr);
for(var i = 0; i < grades.length ; i++){
console.log("In loop #: "+i);
console.log(JSON.stringify(fixGrades));
if( i != 0){
if(grades[i].subject_code != grades[i-1].subject_code){
fixGrades.push({
"subject": grades[i].subject,
"credits": grades[i].credits,
"subject_code": grades[i].subject_code,
"year": grades[i].year,
"tests": [{
"moed": grades[i].moed,
"final_grade": grades[i].final_grade
}]
});
j++;
}else{
fixGrades[j-1].tests.push({
"moed": grades[i].moed,
"final_grade": grades[i].final_grade
});
}
}else{
fixGrades.push({
"subject": grades[i].subject,
"credits": grades[i].credits,
"subject_code": grades[i].subject_code,
"year": grades[i].year,
"tests": [{
"moed": grades[i].moed,
"final_grade": grades[i].final_grade
}]
});
j++;
}
}
console.log(JSON.stringify(fixGrades));
$scope.grades = fixGrades;
}
// $scope.getMedal = function(grade){
// if(grade < 55){
// return "https://wiki.openttd.org/images/1/10/Face-Sick-120px.png";
// }else if( 55<= grade && grade < 70){
// return "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcT6UK4UUxagOktpvJR_P433nvOeTDuV3rOxd0Mswo8T-tRueFmN";
// }else if( 70<= grade && grade < 80){
// return "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRz0_NkZP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0uF9l93eqrrOrg5FlUOOaifOOHVL6modUy3IFxGD6Nyb9JOsqOnp6qGO/d+pm+3rJuXd3eh2VPXwyAB3JO4q8qJZZZGDUcze1AZNZJG/ZqKAw6l5aUBSfVICu+qQFWeYEWKA0NC9Mp8LqA6Ml9O8j9IhvySN72ei8d+9YaB9K4ZiMVRBFNA4OjkaHscOB3HgRrBHEKmRNE5VTJoieqWTR4lp5phJXyvpaVxbSsJbK8ajUFp1i/wB2Du39C2qacfU9yqc8mTSsZE0BgC2CsJKpAV5KpAVpKpAVpKtAVpKtAVpKpAU31bmPZJGbPYQ5p5x8FGcIzi4y2ZmMnF5R9LeCjSBtXh7LbWWaRwBvYdAIcOpaujbinU94/juNnVYk1Yv1fnvO0W4aoIAQHmvh0xMx4f4pp1yHlercNHe7uWpe+K2Ffnl/wbNK4a5z/j3PKsPeGRNA4LbNYc+q50BPT469mom4QEk2IRyDUbFAZFZUOG3WEBlSVSArvqkBXfVICtJUoD2X+zvpA4iqo3m4aP0mEHcCQ2QDmuWnrVVi7yUT2cla7Zacr4SMWbDQuYXFrqhwpmuG0BwJcQd3JBHWp1rilzIy5I8oOCCKMeJIIstoqMiomLTY6kBUkq0BWkq0BWkq0BWkqkBXkq0BWfUoCJ0pKA9e/s9YoW1EsRJyus3mu4Et72O7Vp2Pg1MX+5NextQXHRJftafufQK3DVBACA8d8NYMkFY7dC6ij6LvLne9q5vHnW48Fg3ZLGmXm8nl7KrkjoXSNIikqkBXkqkBXfV86AjfiB3lAU5KpAQOmKAjLigEQG/obi9XS1DpqMSF+QxuLGZ7NcQdYsfR7lhpPcyjs/8AqRjno1H8j/aq+CBnLErtNampbG3EYpQ1rrh
// }else{
// return "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRR0zMfWYUcjYyXjGUQY3tDj04rIFfi_CThbaolxTt_38eL1hkFmQ";
// }
// return "sdfgg";
// };
2015-01-10 22:11:51 +00:00
})
/*=============================================
= Settings - controller =
=============================================*/
.controller('SettingsCtrl', function($scope, $stateParams, $http) {
var localSettingsStr = window.localStorage['Settings'] || null;
if (localSettingsStr === null){
2015-01-20 09:06:17 +00:00
var settings_list = [ {text:"נעל גיליון ציונים", val: false}];//, //[0]
//{text:"הצג מזג אויר", val: false} ]; //[1]
console.log("[JCE] [info]: No settings found!");
}
else{
settings_list = JSON.parse(localSettingsStr);
console.log("[JCE] [info]: settings found!");
}
$scope.settings = settings_list;
$scope.toggled = function(){
console.log("[JCE] [info]: Setting Changed");
window.localStorage['Settings'] = JSON.stringify($scope.settings);
2015-01-10 22:11:51 +00:00
};
2015-01-10 22:11:51 +00:00
})
/*=============================================
= Aguda News - controller =
=============================================*/
.controller('AgudaCtrl', function($scope, $stateParams, $http) {
var aguda = window.localStorage['agudaPosts'] || null;
console.log(aguda);
console.log("[JCE] [INFO] at AgudaCtrl if there is a print. its OK");
if(aguda != null){
$scope.agudaAll = JSON.parse(aguda);
}
})
2015-01-20 09:06:17 +00:00
2015-01-10 22:11:51 +00:00
/*=============================================
= JCE News - controller =
=============================================*/
.controller('JCENewsCtrl', function($scope, $stateParams, $http) {
var notesStr = window.localStorage['notes'] || null;
console.log(notesStr);
if(notesStr != null)
$scope.newss = JSON.parse(notesStr);
2015-01-20 09:06:17 +00:00
})
/*=============================================
= Calendar - controller =
=============================================*/
.controller('CalendarCtrl', function($scope, $stateParams, $http) {
var calendarStr = window.localStorage['calendar'] || null;
console.log(calendarStr);
if(calendarStr != null)
$scope.calendar = JSON.parse(calendarStr);
2015-01-10 22:11:51 +00:00
})
/*=============================================
= Login Controller =
=============================================*/
.controller('LoginCtrl', function($scope, $http, $location, $ionicPopup, $ionicViewService, $timeout, $ionicLoading, ApiService) {
2015-01-10 22:11:51 +00:00
var userStr = window.localStorage['userInfo'] || null;
$scope.loginData = {};
2015-01-10 22:11:51 +00:00
if(userStr !== null){
$ionicViewService.nextViewOptions({
disableBack: true
});
$location.path( "/app/home" ); //Start app
}
else
$scope.userData = null;
// Perform the login action when the user submits the login form
$scope.doLogin = function() {
ApiService.login($scope.loginData.username, $scope.loginData.password);
2015-01-10 22:11:51 +00:00
$ionicLoading.show({template: 'אנא המתן...'}); //close the popup after 3 seconds for some reason
$timeout(function() {
$ionicLoading.hide();
if( (window.localStorage['userInfo'] || false) != false){
window.localStorage['password'] = $scope.loginData.password;
2015-01-10 22:11:51 +00:00
var alertPopup = $ionicPopup.alert({
title: 'ברוכים הבאים!',
template: 'ההתחברות בוצעה בהצלחה!'
});
2015-01-10 22:11:51 +00:00
alertPopup.then(function(res) {
$ionicViewService.nextViewOptions({
disableBack: true
});
2015-01-10 22:11:51 +00:00
$location.path( "/app/home" ); //Start app
2015-01-10 22:11:51 +00:00
});
}
}, 2000);
2015-01-10 22:11:51 +00:00
2015-01-10 22:11:51 +00:00
};
})
/*=======================================
= home Controller =
=======================================*/
.controller('homeCtrl', function($scope, $stateParams, $ionicViewService, $location, $timeout, $rootScope, $ionicModal, ApiService) {
2015-01-10 22:11:51 +00:00
$scope.lock = {};
2015-01-10 22:11:51 +00:00
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/Aouth.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
2015-01-10 22:11:51 +00:00
$scope.update = function(){
console.log("[JCE] [info]: Refreshing...");
ApiService.update();
$timeout(function() {
$scope.$broadcast('scroll.refreshComplete'); //close the popup after 3 seconds for some reason
}, 3000);
2015-01-10 22:11:51 +00:00
if(window.localStorage['newNotes'] === "true")
$scope.newNotes = true;
else
$scope.newNotes = false;
if(window.localStorage['newGrades'] === "true")
$scope.newGrades = true;
else
$scope.newGrades = false;
if(window.localStorage['newAguda'] === "true")
$scope.newAguda = true;
else
$scope.newAguda = false;
2015-01-10 22:11:51 +00:00
};
$scope.update();
$scope.goToNotes = function(){
window.localStorage['newNotes'] = "false";
$scope.newNotes = false;
$ionicViewService.nextViewOptions({
disableBack: true
});
$location.path( "/app/jcenews" );
};
2015-02-01 21:36:42 +00:00
$scope.goToAguda = function(){
window.localStorage['newAguda'] = "false";
$scope.newAguda = false;
$ionicViewService.nextViewOptions({
disableBack: true
});
$location.path( "/app/aguda" );
};
2015-01-10 22:11:51 +00:00
$scope.goToGrades = function(){
var localSettingsStr = window.localStorage['Settings'] || null;
if (localSettingsStr !== null){
var isLocked = (JSON.parse(localSettingsStr))[0].val;
}
if(isLocked){
console.log("[JCE] [INFO]: Grades Locked");
$scope.modal.show();
}
else{
window.localStorage['newGrades'] = "false";
$scope.newGrades = false;
console.log("Unlocked");
$ionicViewService.nextViewOptions({
disableBack: true });
$location.path( "/app/grades" );
}
2015-01-10 22:11:51 +00:00
};
$scope.isLoggedIn = function(){
if($scope.userData == null)
return false;
console.log("[JCE] [Info] User hase loged in once!");
return true;
};
$scope.$watch('isLoggedIn', function() {
//
});
if(window.localStorage['newNotes'] == "true"){
$scope.newNotes = true;
}else{
$scope.newNotes = false;
}
2015-02-01 21:36:42 +00:00
if(window.localStorage['newAguda'] == "true"){
$scope.newAguda = true;
}else{
$scope.newAguda = false;
}
2015-01-10 22:11:51 +00:00
var userStr = window.localStorage['userInfo'] || null;
if(userStr !== null)
$scope.userData = JSON.parse(userStr);
else
$scope.userData = null;
// Triggered in the Aouth modal to close it
$scope.closeAouth = function() {
$scope.modal.hide();
};
// Aouth for Grades
$scope.Aouth = function() {
console.log("Clicked GoOn - password enterd: "+ $scope.lock.password + "\nThe logs pass is: "+window.localStorage['password']);
2015-01-10 22:11:51 +00:00
if($scope.lock.password === (window.localStorage['password'] || null)){ //ok
$scope.lock.password = "";
$scope.modal.hide();
window.localStorage['newGrades'] = "false";
$scope.newGrades = false;
$ionicViewService.nextViewOptions({
disableBack: true });
$location.path( "/app/grades" );
}else{
var alertPopup = $ionicPopup.alert({
title: 'סיסמה שגוייה',
template: 'טעות בסיסמה'
});
alertPopup.then(function(res) {
$scope.modal.hide();
});
}
};
//////////////////////////////////////////////////////////
$scope.version = "0.1.30alpha-develop_perview";
/////////////////////////////////////////////////////////
2015-01-10 22:11:51 +00:00
});