Allow teams to change their name

This commit is contained in:
nemunaire 2016-01-24 14:23:04 +01:00
parent f050dfce06
commit 136b436af5
7 changed files with 126 additions and 13 deletions

View file

@ -195,10 +195,66 @@ angular.module("FICApp")
$scope.my.exercices[$rootScope.current_exercice].submitted = true;
};
})
.controller("MyTeamController", function($scope, $rootScope) {
.controller("MyTeamController", function($scope, $http, $rootScope, $timeout) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.title = "Edit team";
if ($scope.my) {
$rootScope.title = $scope.my.name;
$rootScope.authors = $scope.my.members.map(function (cur) {
return cur.firstname.capitalize() + " " + cur.lastname.capitalize();
}).join(", ");
}
$scope.newName = "";
$rootScope.message = "";
$rootScope.sberr = "";
$scope.tsubmit = function() {
$rootScope.sberr = "";
if ($scope.newName.length < 1) {
$rootScope.messageClass = {"text-danger": true};
$rootScope.sberr = "Nom d'équipe invalide: pas d'entrée.";
return false;
}
else if ($scope.newName.length > 32) {
$rootScope.messageClass = {"text-danger": true};
$rootScope.sberr = "Nom d'équipe invalide: pas plus de 32 caractères.";
return false;
}
else if (!$scope.newName.match(/^[A-Za-z0-9 àéèêëîïôùûü_-]+$/)) {
$rootScope.messageClass = {"text-danger": true};
$rootScope.sberr = "Nom d'équipe invalide: seuls les caractères alpha-numériques sont autorisés.";
return false;
}
$http({
url: "/submit/name",
method: "POST",
data: {newName: $scope.newName}
}).success(function(data, status, header, config) {
$rootScope.messageClass = {"text-success": true};
$rootScope.message = data.errmsg;
var checkDiff = function() {
$http.get("/my.json").success(function(my) {
console.log(my.name);
if ($scope.my.name != my.name) {
$scope.newName = "";
$rootScope.message = "";
$rootScope.refresh();
} else {
$timeout(checkDiff, 750);
}
});
};
checkDiff();
}).error(function(data, status, header, config) {
$rootScope.messageClass = {"text-danger": true};
$rootScope.message = data.errmsg;
if (status != 402) {
$rootScope.sberr = "Une erreur est survenue lors de l'envoi. Veuillez réessayer dans quelques instants.";
}
});
};
})
.controller("RankController", function($scope, $rootScope) {
$rootScope.current_theme = 0;