refactorized rootScope.user

parent 882fab6a
......@@ -24,7 +24,7 @@ var dashboardControllers = angular.module('dashboardControllers', ['dashboardCon
//
//
dashboardControllers.controller('MainCtrl', function MainCtrl(
$scope, $window, $location, $translate, $rootScope, $timeout) {
$scope, $window, $location, $translate, $rootScope, $timeout<) {
$scope.user = $rootScope.user;
......
......@@ -8,8 +8,6 @@ dashboardControllers.controller('AdminLicensesCtrl', function AdminLicensesCtrl(
$scope, $window, $http, config, $translate, ngToast) {
// The parameter 'config' is injected from config.js (defined in dashboardConfig module)
$scope.user = $rootScope.user;
// Don't show the message at the begining
$scope.showmessagesupervisor = false;
$scope.new_numbers = [];
......@@ -22,7 +20,7 @@ dashboardControllers.controller('AdminLicensesCtrl', function AdminLicensesCtrl(
// Get all licenses for the user
$http
.get(config.backend + '/license/' + $scope.user.email)
.get(config.backend + '/license/' + $rootScope.user.email)
.success(function(data, status, headers, config) {
$scope.licenses = data;
})
......
......@@ -20,8 +20,6 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$translate,
ngToast) {
$scope.user = $rootScope.user;
$scope.emptyStudentPicto = {
id: null,
picto: {
......@@ -475,7 +473,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
return $scope.studentData;
},
supervisor: function () {
return $scope.user;
return $rootScope.user;
},
onlyOwn: function () {
return false;
......@@ -528,7 +526,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
return $scope.studentData;
},
supervisor: function () {
return $scope.user;
return $rootScope.user;
},
onlyOwn: function () {
return false;
......@@ -588,7 +586,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
return studentPicto;
},
sup: function () {
return $scope.user;
return $rootScope.user;
},
stu: function () {
return $scope.studentData;
......@@ -614,7 +612,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
return studentPicto;
},
sup: function () {
return $scope.user;
return $rootScope.user;
},
stu: function () {
return $scope.studentData;
......@@ -651,7 +649,7 @@ dashboardControllers.controller('StudentCollectionsCtrl', function StudentCollec
$http.post(config.backend + '/scene/stu/' + $scope.studentData.id, {
name: name,
id_sup: $scope.user.id,
id_sup: $rootScope.user.id,
categories: $scope.newSceneCat,
id_stu: $scope.studentData.id
})
......
......@@ -6,8 +6,6 @@
dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstructionsCtrl(
$rootScope, $scope, $stateParams, $http, config, $window, $translate, $modal, ngToast, newconfirm) {
$scope.user = $rootScope.user;
// For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'instructions';
......@@ -25,7 +23,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
// Query to meta_methods to fill the select fill with precharged methods
// and supervisor template methods
$http
.get(config.backend+'/method/template/' + $scope.user.id)
.get(config.backend+'/method/template/' + $rootScope.user.id)
.success(function(data, status, headers, config) {
for (var i = 0; i < data.length; i++) {
data[i].disabled = data[i].lang != $translate.use();
......@@ -119,7 +117,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
$translate('confirmation').then(function(translation) {
newconfirm(translation).then(function() {
if($scope.method_selected.supervisor == $scope.user.id){
if($scope.method_selected.supervisor == $rootScope.user.id){
$http
.delete(config.backend+'/method/template/' + $scope.method_selected.id)
.success(function(data, status, headers, config) {
......@@ -167,13 +165,13 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
$scope.save_as_template = function(method){
$http
.post(config.backend+'/method/save', { 'id_met': method.id, 'id_sup': $scope.user.id, 'lang': $scope.user.lang })
.post(config.backend+'/method/save', { 'id_met': method.id, 'id_sup': $rootScope.user.id, 'lang': $rootScope.user.lang })
.then( //success
function(data, status, headers, config) {
//console.log('Saved method as template:' + JSON.stringify(data));
// Add to select method
$scope.methods_available.push({ id: method.id, name: method.name, lang: $scope.user.lang});
$scope.methods_available.push({ id: method.id, name: method.name, lang: $rootScope.user.lang});
ngToast.success({
content: $translate.instant('method_saved', {method_name: method.name}),
......
......@@ -13,8 +13,6 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$translate,
ngToast) {
$scope.user = $rootScope.user;
// For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'session';
......@@ -122,7 +120,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.then(
function(data, status, headers, config2) {
$http // creamos un nuevo try
.post(config.backend+'/try/', {ws: $scope.ws, student: $scope.studentData.id, supervisor: $scope.user.id, begin:new Date().toISOString() })
.post(config.backend+'/try/', {ws: $scope.ws, student: $scope.studentData.id, supervisor: $rootScope.user.id, begin:new Date().toISOString() })
.then(
function(data, status, headers, config) {
$scope.load_tries();
......@@ -179,7 +177,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
$http
.post(config.backend+'/ws', {
"id_sup": $scope.user.id,
"id_sup": $rootScope.user.id,
"id_stu": $scope.studentData.id,
"id_ins": $scope.selected.instruction.id
})
......@@ -243,7 +241,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/action', {
"type": "endsession",
"student": $scope.studentData.id,
"supervisor": $scope.user.id,
"supervisor": $rootScope.user.id,
})
.success(function(data, status, headers, _config) {
// Adding resume action to the list of actions
......@@ -286,7 +284,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/action', {
"type": "pausesession",
"student": $scope.studentData.id,
"supervisor": $scope.user.id
"supervisor": $rootScope.user.id
})
.success(function(data, status, headers, config) {
// adding pause action to the list of actions
......@@ -313,7 +311,7 @@ dashboardControllers.controller('StudentSessionCtrl', function StudentSessionCtr
.post(config.backend+'/action', {
"type": "resumesession",
"student": $scope.studentData.id,
"supervisor": $scope.user.id,
"supervisor": $rootScope.user.id,
})
.success(function(data, status, headers, config) {
// Adding resume action to the list of actions
......
......@@ -3,7 +3,17 @@
//-----------------------
// Instructions Controller
//-----------------------
dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($scope, $stateParams, $http, config, $window, $translate, $modal, ngToast, newconfirm) {
dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl(
$scope,
$rootScope,
$stateParams,
$http,
config,
$window,
$translate,
$modal,
ngToast,
newconfirm) {
// ----------------------------------------------------------------------
// METHODS
......@@ -20,7 +30,7 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Query to meta_methods to fill the select fill with precharged methods
// and supervisor template methods
$http
.get(config.backend+'/method/template/owned/' + $scope.user.id)
.get(config.backend+'/method/template/owned/' + $rootScope.user.id)
.success(function(data, status, headers, config) {
// Add to list
$scope.methods = data;
......@@ -38,8 +48,8 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
var new_data = {
name: $translate.instant("new_method"),
id_sup: $scope.user.id,
lang: $scope.user.lang,
id_sup: $rootScope.user.id,
lang: $rootScope.user.lang,
};
$http
......@@ -101,7 +111,7 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
method: method.id,
name: $translate.instant("new_instruction"),
objective: $translate.instant("new_objective"),
lang: $scope.user.lang
lang: $rootScope.user.lang
};
$http
......
......@@ -18,13 +18,11 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
config,
CONSTANTS) {
$scope.user = $rootScope.user;
// Don't show the message at the begining
$scope.showmessage = false;
// Restore user values from sessionStorage
$scope.formdata = JSON.parse(JSON.stringify($scope.user));
$scope.formdata = JSON.parse(JSON.stringify($rootScope.user));
$scope.changeImg = function () {
......@@ -55,15 +53,15 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
data: {
filename: name,
folder: 'supervisors',
id: $scope.user.id,
id: $rootScope.user.id,
file: Upload.dataUrltoBlob(dataUrl, name)
}
})
.then(
function (res) {
$timeout(function () {
$scope.user.pic = '/upload/supervisorAvatar/' + res.data.file.name;
$window.sessionStorage.user = JSON.stringify($scope.user);
$rootScope.user.pic = '/upload/supervisorAvatar/' + res.data.file.name;
$window.sessionStorage.user = JSON.stringify($rootScope.user);
cb();
});
}, function (res) {
......@@ -99,7 +97,7 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
// Comprobation for new email
// If no change, it is deleted from supervisor object
if (supervisor.email === $scope.user.email) {
if (supervisor.email === $rootScope.user.email) {
delete supervisor.email;
}
......@@ -108,8 +106,8 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
$http.put(config.backend + '/sup/' + supervisor.id, supervisor)
.success(function (data) {
$scope.user = JSON.parse(JSON.stringify(data));
$window.sessionStorage.user = JSON.stringify($scope.user);
$rootScope.user = JSON.parse(JSON.stringify(data));
$window.sessionStorage.user = JSON.stringify($rootScope.user);
ngToast.success({ content: $translate.instant('data_saved') });
})
.error(function () {
......
......@@ -18,8 +18,6 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
IOService,
CONSTANTS) {
$scope.user = $rootScope.user;
// --------------------------------------------------------
// Create new account
// --------------------------------------------------------
......@@ -72,7 +70,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
current_method: 'no_method',
current_instruction: 'no_instruction',
license_number: null,
id_sup: $scope.user.id
id_sup: $rootScope.user.id
};
$scope.slide.state ='accounts';
......@@ -93,7 +91,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
$scope.addExisting = function () {
// Send link call to server
$http.post(config.backend + '/stu/license/sup/' + $scope.user.id, {license: $scope.formdata.license_number})
$http.post(config.backend + '/stu/license/sup/' + $rootScope.user.id, {license: $scope.formdata.license_number})
.success(function (data) {
loadStudents();
$scope.slide.rightTo('confirmation');
......@@ -158,7 +156,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
function loadStudents() {
// Get list of supervisor's students
$http.get(config.backend + '/sup/' + $scope.user.id + '/students')
$http.get(config.backend + '/sup/' + $rootScope.user.id + '/students')
.success(function (data) {
$scope.students = data;
})
......@@ -172,7 +170,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
*/
$scope.unlink_student = function (student) {
if ($window.confirm($translate.instant('confirmation'))) {
$http.delete(config.backend + '/stu/' + student.id + '/sup/' + $scope.user.id)
$http.delete(config.backend + '/stu/' + student.id + '/sup/' + $rootScope.user.id)
.success(function () {
var i;
for (i = 0; i < $scope.students.length; i++) {
......@@ -202,7 +200,7 @@ dashboardControllers.controller('StudentsCtrl', function StudentsCtrl(
IOService.on('linkSupervisorToStudent', function (eventData) {
eventData.sup_id = parseInt(eventData.sup_id, 10);
eventData.stu_id = parseInt(eventData.stu_id, 10);
if (eventData.sup_id === $scope.user.id) {
if (eventData.sup_id === $rootScope.user.id) {
IOService.get('/stu/' + eventData.stu_id, function (studentData) {
var i;
var studentAlreadyAdded = false;
......
......@@ -21,8 +21,6 @@ dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl(
if (!$window.sessionStorage.user)
return $scope.logout();
$scope.user = $rootScope.user;
// Link to setup
$scope.setup = function(){
$location.path('/setup');
......@@ -32,7 +30,7 @@ dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl(
IOService.post('/sup/subscribe', {
action: 'subscribe',
attributes: {
id_sup: $scope.user.id,
id_sup: $rootScope.user.id,
ui: 'PDB'
}
});
......@@ -51,7 +49,7 @@ dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl(
return null;
},
supervisor: function () {
return $scope.user;
return $rootScope.user;
},
onlyOwn: function () {
return true;
......
......@@ -6,8 +6,6 @@
dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl(
$rootScope, $scope, $window, $http, config, $translate, ngToast) {
$scope.user = $rootScope.user;
$scope.inputs = {
search_str: '',
email: ''
......@@ -17,7 +15,7 @@ dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl(
function loadSupervisors() {
$http
.get(config.backend+'/sup/' + $scope.user.id + '/supervisors')
.get(config.backend+'/sup/' + $rootScope.user.id + '/supervisors')
.success(function(data, status, headers, config) {
$scope.supervisors_list = data;
console.log($scope.supervisors_list);
......@@ -33,7 +31,7 @@ dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl(
*/
$scope.searchSup = function () {
if (!$scope.user.isOffice) {
if (!$rootScope.user.isOffice) {
console.log("Forbidden action. You're not an office!");
return;
}
......@@ -63,13 +61,13 @@ dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl(
*/
$scope.confirmLink = function () {
if (!$scope.user.isOffice) {
if (!$rootScope.user.isOffice) {
console.log("Forbidden action. You're not an office!");
return;
}
$scope.showmessagesupfound = false;
$http
.post(config.backend+'/sup/' + $scope.supToAdd.id + '/off/' + $scope.user.id)
.post(config.backend+'/sup/' + $scope.supToAdd.id + '/off/' + $rootScope.user.id)
.success(function(data, status, headers, config) {
loadSupervisors();
ngToast.success($translate.instant('supervisor_added_notified'));
......@@ -90,13 +88,13 @@ dashboardControllers.controller('SupervisorsCtrl', function SupervisorsCtrl(
*/
$scope.unlinkSupervisor = function (id) {
if (!$scope.user.isOffice) {
if (!$rootScope.user.isOffice) {
console.log("Forbidden action. You're not an office!");
return;
}
$http
.delete(config.backend+'/sup/' + id + '/off/' + $scope.user.id)
.delete(config.backend+'/sup/' + id + '/off/' + $rootScope.user.id)
.success(function(data, status, headers, config) {
loadSupervisors();
ngToast.success($translate.instant('supervisor_deleted'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment