Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  1. .controller('capacitacion', ['$scope', '$http', '$location', '$routeParams', 'firmantesCombo','LEYENDAS',
  2. function($scope,$http,$location, $routeParams,firmantesCombo,LEYENDAS) {
  3. var self = this;
  4. self.leyendas= LEYENDAS;
  5. self.modelo = {};
  6. self.capacitacionId = null;
  7. if ($routeParams!=null && $routeParams.capacitacionId !=null){
  8. self.capacitacionId = $routeParams.capacitacionId;
  9. }
  10. self.inicio = null;
  11. self.fin = null;
  12. self.fechaEmision = null;
  13. self.firmantes = [];
  14. self.provincias = [];
  15. self.localidades = [];
  16. self.tiposcapacitacion = [];
  17. self.tipocapacitacion = {id:null};
  18. firmantesCombo.buscarTiposCapacitacionEnum().success(function(response){
  19. self.modelo = response;
  20. });
  21. firmantesCombo.buscar().success(function(response){
  22. self.firmantes = response._embedded.firmante;
  23. });
  24. firmantesCombo.buscarProvincias().success(function(response){
  25. self.provincias = response._embedded;
  26. });
  27. firmantesCombo.buscarTiposCapacpacitacion().success(function(response){
  28. self.tiposcapacitacion = response._embedded;
  29. });
  30. self.buscarLocalidadesPorProvincia = function(){
  31. firmantesCombo.buscarLocalidadesProvincia(self.capacitacion.provincia.id).success(function(response){
  32. self.localidades = response._embedded;
  33. }).error(function(error){
  34. self.localidades = [];
  35. });
  36. };
  37. self.usarTemplate = function(){
  38. if (self.tipocapacitacion.id!=null){
  39. self.capacitacion.modelo = self.tipocapacitacion.modelo;
  40. self.capacitacion.nombre = self.tipocapacitacion.nombre;
  41. self.capacitacion.provincia = self.tipocapacitacion.provincia;
  42. self.buscarLocalidadesPorProvincia();
  43. self.capacitacion.localidad = self.tipocapacitacion.localidad;
  44. self.capacitacion.firmante1 = self.tipocapacitacion.firmante1;
  45. self.capacitacion.firmante2 = self.tipocapacitacion.firmante2;
  46. self.capacitacion.firmante3 = self.tipocapacitacion.firmante3;
  47. self.capacitacion.logoProvinciaPath = self.tipocapacitacion.logoProvinciaPath;
  48. self.capacitacion.logoCentralPath = self.tipocapacitacion.logoCentralPath;
  49. }
  50. };
  51. self.fechaEmisionDefault = function(){
  52. if ((self.fechaEmision == null && self.fin != null) || (self.fechaEmision != null && self.fin != null && self.fechaEmision < self.fin)){
  53. self.fechaEmision = self.fin;
  54. }
  55. };
  56. $scope.currentPage = 1;
  57. $scope.viewby = 10;
  58. $scope.itemsPerPage = $scope.viewby;
  59. $scope.maxSize = 5; // Number of pager buttons to show
  60. self.enviarConsultaCapacitacion = function(){
  61. if ((self.capacitacionId!=null && self.capacitacionId!="" )||
  62. (self.curso!=null && self.curso!="" )){
  63. $scope.currentPage=1;
  64. }
  65. self.capacitacionId = null;
  66. navegar();
  67. };
  68. var navegar = function(){
  69. var curso="%";
  70. var capacitacionId=null;
  71. if (self.capacitacionId!=null && self.capacitacionId!=""){
  72. capacitacionId=self.capacitacionId;
  73. }
  74. if (self.curso!=null && self.curso!=""){
  75. curso=self.curso+"%";
  76. }
  77.  
  78. if (self.capacitacionId==null || self.capacitacionId==""){
  79. firmantesCombo.buscarCapacitacionesNombreConsulta(curso,$scope.currentPage-1,$scope.itemsPerPage)
  80. .then(function(response) {
  81. $scope.capacitacion = response.data;
  82. $scope.totalItems = response.data.page.totalElements;
  83. $scope.numPages = response.data.page.totalPages;
  84. });
  85. }else{
  86. firmantesCombo.buscarCapacitacion(capacitacionId)
  87. .then(function(response) {
  88. $scope.capacitacion={_embedded: {
  89. capacitacion: []
  90. }
  91. };
  92. $scope.capacitacion._embedded.capacitacion.push(response.data);
  93. $scope.totalItems = 1;
  94. $scope.numPages = 1;
  95. });
  96. };
  97.  
  98.  
  99. };
  100. navegar();
  101. $scope.setPage = function (pageNo) {
  102. $scope.currentPage = pageNo;
  103. };
  104.  
  105. $scope.pageChanged = function() {
  106. console.log('Page changed to: ' + $scope.currentPage);
  107. navegar();
  108. };
  109.  
  110. $scope.setItemsPerPage = function(num) {
  111. $scope.itemsPerPage = num;
  112. $scope.currentPage = 1; // reset to first paghe
  113. navegar();
  114. }
  115. enviar = function(capacitacion){
  116. $http.post($location.protocol() +"://" + $location.host()+":"+$location.port() +
  117. '/diplomaapi/capacitacion',capacitacion).then(function(response) {
  118. navegar();
  119. });
  120. };
  121. enviarEdita = function(capacitacion){
  122. $http.put(capacitacion._links.self.href,capacitacion).then(function(response) {
  123. navegar();
  124. });
  125. };
  126.  
  127. enviarEditaLogos = function(id,logoProvincia,logoCentral){
  128. var fd = new FormData();
  129. fd.append('file', logoProvincia);
  130. var fd2 = new FormData();
  131. fd2.append('file', logoCentral);
  132. $http.post($location.protocol() +"://" + $location.host()+":"+$location.port() +
  133. '/diplomaapi/capacitacion/logoProvincia/'+id,
  134. fd, {
  135. transformRequest: angular.identity,
  136. headers: {'Content-Type': undefined}
  137. }).then(function(response) {
  138.  
  139. $http.post($location.protocol() +"://" + $location.host()+":"+$location.port() +
  140. '/diplomaapi/capacitacion/logoCentral/'+id,
  141. fd2, {
  142. transformRequest: angular.identity,
  143. headers: {'Content-Type': undefined}
  144. }).then(function(response) {
  145. navegar();
  146. });
  147. });
  148. };
  149. $scope.cargoFilter = function () {
  150.  
  151. return function (item) {
  152. return item.posicion=="Directora Nacional" || item.posicion=="Subsecretario Subsecretaría de Gestión de Servicios Audiovisuales";
  153. };
  154.  
  155. };
  156. self.verAcreditacion = function(link,indice){
  157. var valor=indice;
  158. $scope.capacitacion._embedded.capacitacion[valor].acreditaciones = [];
  159. $http.get(link).then(function(response) {
  160. angular.forEach(response.data._embedded.acreditacion, function(value, key) {
  161. $scope.capacitacion._embedded.capacitacion[valor].acreditaciones.push({participanteId:"#/participante/"+value.persona.id,apellido:value.persona.apellido});
  162. });
  163. });
  164.  
  165. };
  166. self.sortMe = function() {
  167. return function(object) {
  168. return object.apellido;
  169. }
  170. };
  171. self.ocultarAcreditacion = function(indice){
  172. $scope.capacitacion._embedded.capacitacion[indice].acreditaciones = null;
  173. }
  174. self.setearCapacitacion = function(capacitacion){
  175. self.capacitacion = capacitacion;
  176. if (self.capacitacion.provincia!=null){
  177. self.buscarLocalidadesPorProvincia();
  178. }
  179. self.inicio = new Date();
  180. if (self.capacitacion.inicio!=null){
  181. self.inicio = new Date(self.capacitacion.inicio);
  182. }
  183. self.fin = new Date();
  184. if (self.capacitacion.fin!=null){
  185. self.fin = new Date(self.capacitacion.fin);
  186. }
  187. self.fechaEmision = new Date();
  188. if (self.capacitacion.fechaEmision!=null){
  189. self.fechaEmision = new Date(self.capacitacion.fechaEmision);
  190. }
  191. self.logos= 1;
  192. $scope.myFileLogoProvincia = capacitacion.logoProvincia;
  193. $scope.myFileLogologoCentral = capacitacion.logoCentral;
  194. };
  195. self.setTipoCapacitacionEnum = function(tipocapacitacionenum){
  196. self.capacitacion.modelo = tipocapacitacionenum;
  197. };
  198. self.setearCargarLogos = function(capacitacion){
  199. self.capacitacion = capacitacion;
  200. self.logos= 2;
  201. $scope.myFileLogoProvincia = capacitacion.logoProvincia;
  202. $scope.myFileLogologoCentral = capacitacion.logoCentral;
  203. };
  204. self.crearCapacitacion = function(){
  205. self.capacitacion = {};
  206. self.localidades = [];
  207. self.inicio = new Date();
  208. self.fin = new Date();
  209. self.fechaEmision = new Date();
  210. self.logos= 1;
  211. };
  212. self.cancelarCapacitacion = function(){
  213. self.localidades = null;
  214. self.inicio=null;
  215. self.fin=null;
  216. self.fechaEmision=null;
  217. if (self.capacitacionId!=null){
  218. self.curso = self.capacitacion.nombre;
  219. navegar();
  220. }
  221. self.capacitacion = null;
  222. self.logos= null;
  223. $scope.myFileLogoProvincia = null;
  224. $scope.myFileLogologoCentral = null;
  225. };
  226. self.cancelarLogos = function(){
  227. self.capacitacion = null;
  228. self.localidades = null;
  229. self.logos= null;
  230. $scope.myFileLogoProvincia = null;
  231. $scope.myFileLogologoCentral = null;
  232. };
  233. self.enviarCapacitacion = function(){
  234. self.capacitacion.inicio = self.inicio;
  235. self.capacitacion.fin = self.fin;
  236. self.capacitacion.fechaEmision = self.fechaEmision;
  237. if (self.capacitacion._links!=null && self.capacitacion._links.self.href!=null){
  238. enviar(self.capacitacion);
  239. }else{
  240. enviar(self.capacitacion);
  241. }
  242. self.capacitacion=null;
  243. self.localidades = null;
  244. self.inicio=null;
  245. self.fin=null;
  246. self.fechaEmision=null;
  247. self.logos= null;
  248. $location.path("/capacitacion");
  249. };
  250. self.enviarLogos = function(){
  251. enviarEditaLogos(self.capacitacion.id,$scope.myFileLogoProvincia,$scope.myFileLogoCentral);
  252. self.capacitacion=null;
  253. self.localidades = null;
  254. self.logos= null;
  255. $scope.myFileLogoProvincia = null;
  256. $scope.myFileLogologoCentral = null;
  257. };
  258. }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement