Initial commit
This commit is contained in:
298
app/js/section/section.controllers.js
Normal file
298
app/js/section/section.controllers.js
Normal file
@@ -0,0 +1,298 @@
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('app.section')
|
||||
.controller('listarMatriculaCtrl', listarMatriculaCtrl)
|
||||
.controller('crearMatriculaCtrl', crearMatriculaCtrl)
|
||||
.controller('actualizarMatriculaCtrl', actualizarMatriculaCtrl)
|
||||
|
||||
listarMatriculaCtrl.$inject = [ '$scope', '$rootScope', '$location', 'sections', '$modal', 'matriculaSeleccionada'];
|
||||
function listarMatriculaCtrl ( $scope, $rootScope, $location, sections, $modal, matriculaSeleccionada ){
|
||||
|
||||
var vm = this;
|
||||
vm.lista = true;
|
||||
$rootScope.actOk = false;
|
||||
$rootScope.loading = true;
|
||||
$rootScope.table = false;
|
||||
|
||||
vm.submit = function() {
|
||||
}
|
||||
|
||||
var matriculaArray = [];
|
||||
sections.query(
|
||||
function(successResult){
|
||||
vm.matricula = successResult;
|
||||
angular.forEach(vm.matricula, function (value){
|
||||
matriculaArray.push({
|
||||
Nombre:value.Nombre,
|
||||
Codigo:value.Codigo,
|
||||
Materia:value.Materia,
|
||||
Semestre:value.Semestre,
|
||||
Estudiantes: value.Estudiantes
|
||||
});
|
||||
});
|
||||
$rootScope.loading = false;
|
||||
$rootScope.table = true;
|
||||
vm.listaMatricula = matriculaArray;
|
||||
},
|
||||
function(data){
|
||||
console.log("Error al obtener los datos.");
|
||||
|
||||
});
|
||||
|
||||
/**************************Eliminar Matricula**************************/
|
||||
/* En este proceso, primero se llama a un Modal el cual se cerciora que
|
||||
el usuario se asegure de eliminar la matricula escogida, el usuario al
|
||||
confirmar su decision llama automaticamente a la funcion que hara la
|
||||
llamada a servicio que borrara la matricula de la base de datos.
|
||||
*/
|
||||
vm.eliminarMatriculaModal = function (index) {
|
||||
|
||||
$rootScope.index = index;
|
||||
$rootScope.botonOk = true;
|
||||
$rootScope.otroBotonOk = false;
|
||||
$rootScope.botonCancelar = true;
|
||||
$rootScope.rsplice = false;
|
||||
$rootScope.eliminarLoading = false;
|
||||
$rootScope.mensaje = "¿Seguro que desea eliminar la matricula?";
|
||||
|
||||
$scope.modalInstance = $modal.open({
|
||||
animation: $rootScope.animationsEnabled,
|
||||
templateUrl: 'partials/matricula/modal/eliminar_matricula_modal.html',
|
||||
scope: $scope,
|
||||
size: 'sm',
|
||||
resolve: {
|
||||
items: function () {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
vm.eliminarMatricula= function (index) {
|
||||
$rootScope.botonOk = false;
|
||||
$rootScope.otroBotonOk = true;
|
||||
$rootScope.botonCancelar = false;
|
||||
$rootScope.urlLo = 'listarMatricula';
|
||||
$rootScope.eliminarLoading = true;
|
||||
var name = vm.matricula[index].Nombre;
|
||||
|
||||
sections.delete({ id: vm.matricula[index]._id },
|
||||
function (successResult) {
|
||||
$rootScope.eliminarLoading = false;
|
||||
$rootScope.rsplice = true;
|
||||
$rootScope.mensaje = "Sección " + name + " eliminada.";
|
||||
},
|
||||
function (errorResult) {
|
||||
$rootScope.eliminarLoading = false;
|
||||
$rootScope.mensaje = "Error al eliminar la sección " + name;
|
||||
console.log('Could not delete from server');
|
||||
});
|
||||
};
|
||||
|
||||
vm.eliminarMatriculaSplice = function (index, rsplice) {
|
||||
if(rsplice){
|
||||
vm.listaMatricula.splice(index, 1);
|
||||
$rootScope.rsplice = false;
|
||||
}
|
||||
};
|
||||
|
||||
/*************************Fin de Eliminar Matricula********************/
|
||||
|
||||
|
||||
vm.modificarMatricula = function (index) {
|
||||
matriculaSeleccionada.Nombre = vm.matricula[index].Nombre;
|
||||
matriculaSeleccionada.Codigo = vm.matricula[index].Codigo;
|
||||
matriculaSeleccionada.Materia = vm.matricula[index].Materia;
|
||||
matriculaSeleccionada.Semestre = vm.matricula[index].Semestre;
|
||||
matriculaSeleccionada.Estudiantes= vm.matricula[index].Estudiantes;
|
||||
$location.url('actualizarMatricula');
|
||||
};
|
||||
|
||||
$rootScope.open = function($event) {
|
||||
$event.preventDefault();
|
||||
$event.stopPropagation();
|
||||
|
||||
$rootScope.opened = true;
|
||||
};
|
||||
|
||||
$scope.ok = function (urlLo) {
|
||||
$location.url(urlLo);
|
||||
$scope.modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
$scope.cancel = function () {
|
||||
$scope.modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
return vm;
|
||||
};
|
||||
|
||||
crearMatriculaCtrl.$inject =
|
||||
['$scope','$rootScope', '$location', 'sections', '$modal', 'courses'];
|
||||
function crearMatriculaCtrl($scope, $rootScope, $location, sections, $modal, courses){
|
||||
|
||||
var vm = this;
|
||||
vm.submitted = false;
|
||||
$rootScope.mensaje = "";
|
||||
|
||||
courses.query(
|
||||
function (successResult) {
|
||||
vm.materias = successResult;
|
||||
},
|
||||
function () {
|
||||
vm.materias = null;
|
||||
});
|
||||
|
||||
vm.submit = function() {
|
||||
|
||||
if (vm.data_input_form.$valid){
|
||||
vm.section = {
|
||||
|
||||
"section": vm.matricula.Nombre,
|
||||
"code": vm.valorMateria.Codigo,
|
||||
"course": vm.valorMateria.Nombre,
|
||||
"semester": vm.matricula.Semestre,
|
||||
"students": vm.matricula.Estudiantes,
|
||||
};
|
||||
|
||||
$scope.modalInstance = $modal.open({
|
||||
animation: $rootScope.animationsEnabled,
|
||||
templateUrl: 'partials/matricula/modal/crear_matricula_modal.html',
|
||||
scope: $scope,
|
||||
size: 'sm',
|
||||
resolve: {
|
||||
items: function () {
|
||||
return $rootScope.items;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sections.save(vm.section,
|
||||
function(){
|
||||
$rootScope.botonOk = true;
|
||||
$rootScope.urlLo = 'listarMatricula';
|
||||
$rootScope.mensaje = "Sección " + vm.matricula.Nombre + " creada";
|
||||
},
|
||||
function(){
|
||||
$rootScope.botonOk = true;
|
||||
$rootScope.urlLo = 'listarMatricula';
|
||||
$rootScope.mensaje = "Error creando la seccion " + vm.matricula.Nombre;
|
||||
});
|
||||
}else{
|
||||
vm.submitted = true;
|
||||
}
|
||||
};
|
||||
|
||||
vm.cargarEstudiantes = function () {
|
||||
|
||||
};
|
||||
|
||||
$scope.ok = function (urlLo) {
|
||||
$location.url(urlLo);
|
||||
$scope.modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
$rootScope.open = function($event) {
|
||||
$event.preventDefault();
|
||||
$event.stopPropagation();
|
||||
|
||||
$rootScope.opened = true;
|
||||
};
|
||||
|
||||
return vm;
|
||||
};
|
||||
|
||||
actualizarMatriculaCtrl.$inject = ['$scope', '$rootScope', '$location', 'sections', '$modal', 'matriculaSeleccionada'];
|
||||
function actualizarMatriculaCtrl($scope, $rootScope, $location, sections, $modal, matriculaSeleccionada){
|
||||
|
||||
var vm = this;
|
||||
vm.lista = true;
|
||||
$rootScope.loading = true;
|
||||
$rootScope.table = false;
|
||||
vm.matricula = matriculaSeleccionada;
|
||||
vm.listaEstudiantes = vm.matricula.Estudiantes;
|
||||
|
||||
|
||||
vm.actualizarMatricula = function() {
|
||||
sections.update(section,
|
||||
function(){
|
||||
$rootScope.botonOk = true;
|
||||
$rootScope.botonCancelar = false;
|
||||
$rootScope.urlLo = 'listarMatricula';
|
||||
$rootScope.mensaje = "Sección actualizada";
|
||||
},
|
||||
function(){
|
||||
$rootScope.botonOk = true;
|
||||
$rootScope.botonCancelar = false;
|
||||
$rootScope.urlLo = 'listarMatricula';
|
||||
$rootScope.mensaje = "Error al actualizar la Sección ";
|
||||
});
|
||||
}
|
||||
|
||||
vm.retirarEstudianteModal = function (index) {
|
||||
$rootScope.index = index;
|
||||
|
||||
$rootScope.botonOk = true;
|
||||
$rootScope.otroBotonOk = false;
|
||||
$rootScope.botonCancelar = true;
|
||||
|
||||
$rootScope.rsplice = false;
|
||||
$rootScope.eliminarLoading = false;
|
||||
$rootScope.mensaje = "¿Desea retirar este estudiante de la Sección?";
|
||||
|
||||
$scope.modalInstance = $modal.open({
|
||||
animation: $rootScope.animationsEnabled,
|
||||
templateUrl: 'partials/matricula/modal/actualizar_matricula_modal.html',
|
||||
scope: $scope,
|
||||
size: 'sm',
|
||||
resolve: {
|
||||
items: function () {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
vm.retirarEstudiante = function (index) {
|
||||
$rootScope.botonOk = false;
|
||||
$rootScope.otroBotonOk = true;
|
||||
$rootScope.botonCancelar = false;
|
||||
$rootScope.urlLo = 'actualizarMatricula';
|
||||
};
|
||||
|
||||
vm.retirarEstudianteSplice = function(index, rsplice) {
|
||||
if(rsplice){
|
||||
vm.listaEstudiantes.splice(index, 1);
|
||||
$rootScope.rsplice = false;
|
||||
|
||||
var section = {
|
||||
'section': vm.matricula.Nombre,
|
||||
'code': vm.matricula.Codigo,
|
||||
'course': vm.matricula.Seccion,
|
||||
'semester': vm.matricula.Semestre,
|
||||
'students': vm.listaEstudiantes
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.open = function($event) {
|
||||
$event.preventDefault();
|
||||
$event.stopPropagation();
|
||||
$rootScope.opened = true;
|
||||
};
|
||||
|
||||
$scope.ok = function (urlLo) {
|
||||
$location.url(urlLo);
|
||||
$scope.modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
$scope.cancel = function () {
|
||||
$scope.modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
return vm;
|
||||
};
|
||||
|
||||
})();
|
79
app/js/section/section.module.js
Normal file
79
app/js/section/section.module.js
Normal file
@@ -0,0 +1,79 @@
|
||||
(function(){
|
||||
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module("app.section", ['ui.router', 'ui.bootstrap'])
|
||||
.run(addStateToScope)
|
||||
.config(getRoutes);
|
||||
|
||||
addStateToScope.$inject = ['$rootScope', '$state', '$stateParams'];
|
||||
function addStateToScope($rootScope, $state, $stateParams){
|
||||
$rootScope.$state = $state;
|
||||
$rootScope.$stateParams = $stateParams;
|
||||
};
|
||||
|
||||
getRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
|
||||
function getRoutes($stateProvider, $urlRouterProvider){
|
||||
$urlRouterProvider.otherwise('/listarMatricula');
|
||||
|
||||
$stateProvider
|
||||
|
||||
.state('listarMatricula', {
|
||||
url: '/listarMatricula',
|
||||
views: {
|
||||
sidebar: {
|
||||
templateUrl: 'partials/sidebar.html',
|
||||
controller: 'sidebarCtrl'
|
||||
},
|
||||
navbar: {
|
||||
templateUrl: 'partials/navbar.html'
|
||||
},
|
||||
content: {
|
||||
templateUrl: 'partials/section/list_section.html',
|
||||
controller: 'listarMatriculaCtrl',
|
||||
controllerAs: 'vm'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('crearMatricula', {
|
||||
url: '/crearMatricula',
|
||||
views: {
|
||||
sidebar: {
|
||||
templateUrl: 'partials/sidebar.html',
|
||||
controller: 'sidebarCtrl'
|
||||
},
|
||||
navbar: {
|
||||
templateUrl: 'partials/navbar.html'
|
||||
},
|
||||
content: {
|
||||
templateUrl: 'partials/section/create_section.html',
|
||||
controller: 'crearMatriculaCtrl',
|
||||
controllerAs: 'vm'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('actualizarMatricula', {
|
||||
url: '/actualizarMatricula',
|
||||
views: {
|
||||
sidebar: {
|
||||
templateUrl: 'partials/sidebar.html',
|
||||
controller: 'sidebarCtrl'
|
||||
},
|
||||
navbar: {
|
||||
templateUrl: 'partials/navbar.html'
|
||||
},
|
||||
content: {
|
||||
templateUrl: 'partials/section/update_section.html',
|
||||
controller: 'actualizarMatriculaCtrl',
|
||||
controllerAs: 'vm'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
};
|
||||
})();
|
||||
|
23
app/js/section/section.services.js
Normal file
23
app/js/section/section.services.js
Normal file
@@ -0,0 +1,23 @@
|
||||
(function(){
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('app.section')
|
||||
.factory('sections', sections)
|
||||
.factory('courses', courses)
|
||||
.value('matriculaSeleccionada',{});
|
||||
|
||||
sections.$inject = ['$resource','$rootScope'];
|
||||
function sections($resource, $rootScope){
|
||||
return $resource('http://'+$rootScope.domainUrl+'/sections/:id', null,
|
||||
{
|
||||
'update': {method:'PUT'}
|
||||
});
|
||||
};
|
||||
|
||||
courses.$inject = ['$resource','$rootScope'];
|
||||
function courses($resource, $rootScope){
|
||||
return $resource('http://'+$rootScope.domainUrl+'/courses');
|
||||
};
|
||||
|
||||
})();
|
Reference in New Issue
Block a user