tabellaFlussiNonSedaCtrl.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. app.controller('tabellaFlussiNonSedaCtrl',
  2. function($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, $routeParams, $mdBottomSheet, $mdMedia, FlussiNonSeda, utilsSvc) {
  3. var vm=this;
  4. vm.maxItems = 0;
  5. vm.itemsPerPage = 100;
  6. vm.selectedIndex=-1;
  7. vm.records=[];
  8. vm.filter={
  9. filterText: '',
  10. orderField:null
  11. }
  12. vm.setSelected=function(idx) {
  13. vm.selectedIndex = idx;
  14. }
  15. vm.columnWidths=[
  16. 120, //0
  17. 140, //1
  18. 120, //2
  19. 380 //3
  20. ];
  21. vm.getListHeight = function() {
  22. containerHeight = ($window.innerHeight - $('#container').position().top - $('#view').position().top);
  23. return {'height': containerHeight + 'px'};
  24. };
  25. $window.addEventListener('resize', onResize);
  26. function onResize() {
  27. $scope.$digest();
  28. }
  29. $scope.$on('$destroy', function() {
  30. $window.removeEventListener('resize', onResize);
  31. });
  32. vm.getColumnWidth = // }
  33. // this.lastStartIdx = index;
  34. function(idx) {
  35. return {
  36. 'width': vm.columnWidths[idx] + 'px',
  37. 'min-width':vm.columnWidths[idx] + 'px',
  38. 'margin-left':'8px',
  39. 'margin-right':'8px'
  40. };modalitaGenerazione
  41. }
  42. vm.getMaxListWidth = function() {
  43. var res=0;
  44. for (var i=0;i<vm.columnWidths.length;i++)
  45. res += vm.columnWidths[i]+6+8+10;
  46. $('#container').css('width',($('#header').width()+96)+'px');
  47. return {'width': res+ 'px!important;'}
  48. }
  49. vm.setOrderField = function(field) {
  50. if (vm.filter.orderField!=field)
  51. vm.filter.orderField = field;
  52. else
  53. vm.filter.orderField = "-" +field;
  54. vm.getFlussiNonSeda();
  55. }
  56. vm.eliminaElemento=function(idx,event) {
  57. event.preventDefault();
  58. event.stopPropagation();
  59. utilsSvc.showConfirm("Conferma", "Confermi la cancellazione dell'elemento selezionato?")
  60. .then(function(res){
  61. FlussiNonSeda.Delete({id:vm.records[idx].id})
  62. .$promise.then(function(data){
  63. utilsSvc.showMessage('Eliminazione effettuata');
  64. vm.getFlussiNonSeda();
  65. })
  66. })
  67. }
  68. vm.nuovoElemento=function(event) {
  69. FlussiNonSeda.New()
  70. .$promise.then(function(data){
  71. data.tipologia="RID";
  72. vm.records.push(data);
  73. vm.editElemento(vm.records.length-1,event);
  74. })
  75. }
  76. vm.editElemento = function(idx, ev) {
  77. $mdDialog.show({
  78. targetEvent:ev,
  79. templateUrl: 'templates/flussoNonSeda.html',
  80. controller: 'flussoNonSedaCtrl',
  81. locals: {item: vm.records[idx], descrizione: vm.decodeTipologia(vm.records[idx].tipologia)},
  82. multiple: true
  83. }).then(function(res){
  84. vm.records[idx] = res;
  85. FlussiNonSeda.save({},res).$promise.then(
  86. function(res){
  87. //vm.records[idx] = res;
  88. utilsSvc.showMessage('Salvataggio modifiche effettuato');
  89. vm.getFlussiNonSeda();
  90. },
  91. function(err){
  92. utilsSvc.handleHttpError(err);
  93. }
  94. );
  95. });
  96. }
  97. vm.decodeTipologia = function(tipologia) {
  98. return utilsSvc.decodeTipologia(tipologia);
  99. }
  100. vm.infiniteItems = {
  101. numLoaded_: 0,
  102. toLoad_: 0,
  103. loading_:false,
  104. lastStartIdx:-1,
  105. listPromise:null,
  106. canceler: $q.defer(),
  107. // Required.
  108. getItemAtIndex: function(index) {
  109. if (vm.maxItems==0 || index>vm.maxItems)
  110. return null;
  111. if (!vm.infiniteItems.loading_)
  112. if (index > vm.records.length) {
  113. this.fetchMoreItems_(index);
  114. return null;
  115. }
  116. return vm.records [index];
  117. },
  118. getLength: function() {
  119. return vm.maxItems;
  120. },
  121. fetchMoreItems_: function(index) {
  122. if (this.toLoad_ < index) {
  123. this.toLoad_ += vm.itemsPerPage;
  124. utilsSvc.showWaitMessage('Ricerca in corso...');
  125. vm.infiniteItems.loading_ = true;
  126. this.listPromise = FlussiNonSeda.List({start: vm.records.length,size:Math.max(vm.records.length+index,vm.itemsPerPage)}).$promise;
  127. var mod=this;
  128. this.listPromise.then(
  129. function(data){
  130. vm.infiniteItems.loading_ = false;
  131. vm.infiniteItems.toLoad_=0;
  132. utilsSvc.cancelWaitMessage();
  133. vm.records = vm.records.concat(data);
  134. mod.numLoaded_ = vm.records.length;
  135. mod.lastStartIdx = vm.records.length;
  136. },
  137. function(error) {
  138. vm.infiniteItems.loading_ = false;
  139. vm.infiniteItems.toLoad_=0;
  140. utilsSvc.handleHttpError(error);
  141. }
  142. )
  143. }
  144. }
  145. }
  146. vm.getFlussiNonSeda = function(){
  147. FlussiNonSeda.Count({filter:vm.filter.filterText}).$promise.then(
  148. function(data){
  149. vm.records=[];
  150. vm.maxItems = data.value;
  151. vm.infiniteItems.numLoaded_ = 0;
  152. vm.infiniteItems.toLoad_ = 0;
  153. }
  154. );
  155. }
  156. vm.init = function() {
  157. vm.getFlussiNonSeda();
  158. }
  159. vm.init();
  160. })
  161. .controller("flussoNonSedaCtrl",function($scope, $mdDialog, utilsSvc,locals){
  162. $scope.item = angular.copy(locals.item);
  163. $scope.descrizione = locals.descrizione;
  164. $scope.toUpperCase=function(event) {
  165. event.key = event.key.toUpperCase();
  166. }
  167. $scope.confirmDialog = function(){
  168. if ($scope.item.tipologia==null || $scope.item.tipologia=="" ||$scope.item.nomeSupporto==null || $scope.item.nomeSupporto=="") {
  169. utilsSvc.show("I dati Tipologia e Nome Supporto Flusso sono obbligatori");
  170. return;
  171. }
  172. $mdDialog.hide($scope.item);
  173. }
  174. $scope.cancelDialog=function(){
  175. $mdDialog.cancel();
  176. }
  177. })
  178. ;