server/admin/static/js/app.js

95 lines
2.8 KiB
JavaScript

angular.module("FICApp", ["ngRoute", "ngResource"])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when("/themes", {
controller: "ThemesListController",
templateUrl: "views/theme-list.html"
})
.when("/themes/:themeId", {
controller: "ThemeController",
templateUrl: "views/theme.html"
})
.when("/themes/:themeId/:exerciceId", {
controller: "ExerciceController",
templateUrl: "views/exercice.html"
})
.when("/teams", {
controller: "TeamsListController",
templateUrl: "views/team-list.html"
})
.when("/teams/new", {
controller: "TeamNewController",
templateUrl: "views/team-new.html"
});
$locationProvider.html5Mode(true);
});
angular.module("FICApp")
.factory("Team", function($resource) {
return $resource("/api/teams/:teamId", { teamId: '@id' }, {
'save': {method: 'PATCH'},
})
});
angular.module("FICApp")
.factory("Theme", function($resource) {
return $resource("/api/themes/:themeId", null, {
'save': {method: 'PATCH'},
})
});
angular.module("FICApp")
.factory("Exercice", function($resource) {
return $resource("/api/themes/:themeId/:exerciceId", null, {
'query': {method: "GET", url: "/api/themes/:themeId/exercices", isArray: true},
'save': {method: 'PATCH'},
})
});
angular.module("FICApp")
.controller("ThemesListController", function($scope, Theme, $location) {
$scope.themes = Theme.query();
$scope.fields = ["id", "name"];
$scope.show = function(id) {
$location.url("/themes/" + id);
};
})
.controller("ThemeController", function($scope, Theme, $routeParams) {
$scope.theme = Theme.get({ themeId: $routeParams.themeId });
$scope.fields = ["name"];
$scope.saveTheme = function() {
this.theme.$save({themeId: this.theme.themeId});
}
})
.controller("ExercicesListController", function($scope, Exercice, $routeParams, $location) {
$scope.exercices = Exercice.query({ themeId: $routeParams.themeId });
$scope.fields = ["id", "title", "statement", "videoURI"];
$scope.show = function(id) {
$location.url("/themes/" + $routeParams.themeId + "/" + id);
};
})
.controller("ExerciceController", function($scope, Theme, $routeParams) {
$scope.exercice = Exercice.get({ themeId: $routeParams.themeId });
$scope.fields = ["name", "statement", "hint", "videoURI"];
$scope.saveTheme = function() {
this.exercice.$save({ themeId: this.exercice.themeId, exerciceId: this.exercice.exerciceId});
}
})
.controller("TeamsListController", function($scope, Team, $location) {
$scope.teams = Team.query();
$scope.fields = ["id", "name"];
$scope.show = function(id) {
$location.url("/teams/" + id);
};
})
.controller("TeamNewController", function($scope, Team, $location) {
$scope.contact = new Team({
})
});