estrattoreCtrl.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. app.controller('estrattoreCtrl',
  2. function ($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, utilsSvc, PianiEstrazioneDistinte, FunzioniOrdinanti) {
  3. var vm=this;
  4. vm.records = [];
  5. vm.decodeStatus = function(status){
  6. switch (status) {
  7. case 1: return 'Tutte le disposizioni estratte';
  8. case 2: return 'Alcune disposizioni non estratte per errori di convalida';
  9. case 3: return 'Alcune disposizioni non estratte';
  10. case 4: return 'Estrazione non effettuata';
  11. }
  12. }
  13. vm.init = function() {
  14. PianiEstrazioneDistinte.List().$promise.then(function (data){
  15. vm.records = data;
  16. },
  17. function(error){
  18. utilsSvc.handleHttpError(error);
  19. })
  20. }
  21. vm.delegatiFirma = function(ev) {
  22. $mdDialog.show({
  23. targetEvent:ev,
  24. templateUrl: 'templates/delegatiFirma.html',
  25. controller: 'delegatiFirmaCtrl',
  26. multiple: true
  27. }).then(function(){
  28. });
  29. }
  30. vm.nuovoPiano = function($event) {
  31. PianiEstrazioneDistinte.New().$promise.then(function(res){
  32. vm.records.push(res);
  33. vm.modificaPiano(vm.records.length-1, $event);
  34. })
  35. }
  36. vm.modificaPiano = function(idx, ev) {
  37. if (typeof vm.records=="undefined" || typeof vm.records[idx]=="undefined")
  38. return
  39. var piano = angular.copy(vm.records[idx]);
  40. $mdDialog.show({
  41. templateUrl: 'templates/dettaglioEstrattore.html',
  42. controller: 'dettaglioEstrattoreCtrl',
  43. targetEvent: ev,
  44. locals: {piano:piano}
  45. })
  46. .then(function(args){
  47. vm.init();
  48. },
  49. function(){
  50. }
  51. );
  52. }
  53. vm.eliminaPiano = function(idx, ev) {
  54. utilsSvc.showConfirm("Confermi l'eliminazione dell'elemento?",'Conferma')
  55. .then(function(res){
  56. PianiEstrazioneDistinte.Delete({id: vm.records[idx].id})
  57. .$promise.then(function(res){
  58. if (res.value==0)
  59. utilsSvc.showMessage('Eliminazione effettuata');
  60. else
  61. utilsSvc.show("Si è verificato un errore durante l'eliminazione del piano: " +res.value);
  62. vm.init();
  63. },
  64. function(err){
  65. utilsSvc.handleHttpError(err);
  66. vm.init();
  67. }
  68. )
  69. })
  70. }
  71. vm.init();
  72. });