sedaRemunerationCtrl.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. app.controller('sedaRemunerationCtrl',
  2. function ($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, $mdBottomSheet, utilsSvc, userService, Remuneration) {
  3. var vm=this;
  4. vm.maxItems = 0;
  5. vm.maxDetailItems = 0;
  6. vm.itemsPerPage = 500;
  7. vm.records=[];
  8. vm.detailrecords=[];
  9. vm.currentDetailId = 0;
  10. vm.codiciSia=[];
  11. vm.codiceSiaSelezionato='';
  12. vm.selectedIndex = -1;
  13. vm.selectedDetailIndex = 0;
  14. vm.columnWidths=[
  15. 70, //0
  16. 50, //1
  17. 80, //2
  18. 220, //3
  19. 180, //4
  20. 90, //5
  21. 100, //6
  22. 100, //7
  23. 100, //8
  24. 80, //9
  25. 100, //10
  26. 100, //11
  27. 100, //12
  28. 120, //13
  29. 100, //14
  30. 90, //15
  31. 90, //16
  32. 90, //17.
  33. 90, //18
  34. 150, //19
  35. 150, //20
  36. 90, //21
  37. 120, //22
  38. 120, //23
  39. 90,
  40. 320
  41. ];
  42. vm.getListHeight = function() {
  43. containerHeight = $('#details').position().top - $('#container').position().top-8;
  44. return {'height': containerHeight + 'px'};
  45. };
  46. vm.getGridItemHeight = function() {
  47. return utilsSvc.getGridHeight();
  48. }
  49. vm.getGridWithButtonItemHeight = function() {
  50. return utilsSvc.getGridWithButtonHeight();
  51. }
  52. vm.getDetailListHeight = function() {
  53. detailsContainerHeight = window.innerHeight - document.getElementById('vertical-container-details').getBoundingClientRect().top-50;
  54. return {'height': detailsContainerHeight + 'px'};
  55. };
  56. $window.addEventListener('resize', onResize);
  57. function onResize() {
  58. $scope.$digest();
  59. }
  60. $scope.$on('$destroy', function() {
  61. $window.removeEventListener('resize', onResize);
  62. });
  63. vm.largeScreen =function(){
  64. return utilsSvc.largeScreen();
  65. }
  66. vm.getColumnWidth = function(idx) {
  67. return {
  68. 'width': vm.columnWidths[idx] + 'px',
  69. 'min-width':vm.columnWidths[idx] + 'px',
  70. //'padding-left':'6px',
  71. //'padding-right':'6px',
  72. 'margin-left':'8px',
  73. 'margin-right':'8px'
  74. };
  75. }
  76. vm.getMaxListWidth = function() {
  77. var res=0;
  78. for (var i=0;i<vm.columnWidths.length;i++)
  79. res += vm.columnWidths[i]+6+8+10;
  80. return {'width': res + 'px'}
  81. }
  82. vm.getStatusColor = function(statusCode) {
  83. var color;
  84. if (statusCode==0)
  85. color = 'red';
  86. else if (statusCode==1)
  87. color = 'green';
  88. else
  89. color = 'yellow';
  90. return {'color': color};
  91. }
  92. vm.decodeTipoDettaglio = function(tipo){
  93. if (tipo=='CMF')
  94. return 'Solo mandati rilasciati presso il beneficiario';
  95. if (tipo=='DMF')
  96. return 'Solo mandati rilasciati presso PSP (Banca) del pagatore';
  97. if (tipo=='ALL')
  98. return 'Tutti i mandati';
  99. }
  100. vm.decodeTipoRichiesta = function(tipo){
  101. if (tipo=='ALL')
  102. return 'Tutti i Mandati attivi nel periodo di riferimento';
  103. if (tipo=='CHG')
  104. return 'Mandati attivati nel periodo di riferimento e mandati revocati o disattivati nel periodo di riferimento precedente';
  105. }
  106. vm.getCodiciSia = function() {
  107. Remuneration.CodiciSia().$promise.then(function(data){
  108. vm.codiciSia = data;
  109. })
  110. }
  111. vm.setOrderField = function(field) {
  112. if (vm.filter.orderField!=field)
  113. vm.filter.orderField = field;
  114. else
  115. vm.filter.orderField = "-" +field;
  116. vm.getData();
  117. }
  118. vm.infiniteItems = {
  119. numLoaded_: 0,
  120. toLoad_: 0,
  121. loading_:false,
  122. lastStartIdx:-1,
  123. listPromise:null,
  124. canceler: $q.defer(),
  125. // Required.
  126. getItemAtIndex: function(index) {
  127. if (vm.maxItems==0 || index>vm.maxItems)
  128. return null;
  129. if (!vm.infiniteItems.loading_)
  130. if (index > vm.records.length) {
  131. this.fetchMoreItems_(index);
  132. return null;
  133. }
  134. return vm.records [index];
  135. },
  136. // Required.
  137. // For infinite scroll behavior, we always return a slightly
  138. // higher
  139. // number than the previously loaded items.
  140. getLength: function() {
  141. return vm.maxItems;
  142. },
  143. fetchMoreItems_: function(index) {
  144. if (this.toLoad_ < index) {
  145. this.toLoad_ += vm.itemsPerPage;
  146. utilsSvc.showWaitMessage('Ricerca in corso...');
  147. vm.infiniteItems.loading_ = true;
  148. this.listPromise = Remuneration.Header({codiceSia: vm.codiceSiaSelezionato, start: vm.records.length,size:Math.max(vm.records.length+index,vm.itemsPerPage)}).$promise;
  149. var mod=this;
  150. this.listPromise.then(
  151. function(data){
  152. vm.infiniteItems.loading_ = false;
  153. vm.infiniteItems.toLoad_=0;
  154. utilsSvc.cancelWaitMessage();
  155. vm.records = vm.records.concat(data);
  156. mod.numLoaded_ = vm.records.length;
  157. mod.lastStartIdx = vm.records.length;
  158. if (vm.records.length>0 && vm.selectedIndex==-1) {
  159. vm.selectedIndex=0;
  160. vm.getProvisioning(0, vm.records[0].idremuneration);
  161. }
  162. },
  163. function(error) {
  164. vm.infiniteItems.loading_ = false;
  165. vm.infiniteItems.toLoad_=0;
  166. utilsSvc.handleHttpError(error);
  167. }
  168. )
  169. }
  170. }
  171. }
  172. vm.infiniteDetailItems = {
  173. numLoaded_: 0,
  174. toLoad_: 0,
  175. loading_:false,
  176. lastStartIdx:-1,
  177. listPromise:null,
  178. canceler: $q.defer(),
  179. // Required.
  180. getItemAtIndex: function(index) {
  181. if (vm.maxDetailItems==0 || index>vm.maxDetailItems)
  182. return null;
  183. if (!vm.infiniteDetailItems.loading_)
  184. if (index > vm.detailrecords.length) {
  185. this.fetchMoreItems_(index);
  186. return null;
  187. }
  188. return vm.detailrecords [index];
  189. },
  190. // Required.
  191. // For infinite scroll behavior, we always return a slightly
  192. // higher
  193. // number than the previously loaded items.
  194. getLength: function() {
  195. return vm.maxDetailItems;
  196. },
  197. fetchMoreItems_: function(index) {
  198. if (this.toLoad_ < index) {
  199. this.toLoad_ += vm.itemsPerPage;
  200. utilsSvc.showWaitMessage('Ricerca in corso...');
  201. vm.infiniteDetailItems.loading_ = true;
  202. this.listPromise = Remuneration.Provisioning({id: vm.currentDetailId,start: vm.detailrecords.length,size:Math.max(vm.detailrecords.length+index,vm.itemsPerPage)}).$promise;
  203. var moddetail=this;
  204. this.listPromise.then(
  205. function(data){
  206. vm.infiniteDetailItems.loading_ = false;
  207. vm.infiniteDetailItems.toLoad_=0;
  208. utilsSvc.cancelWaitMessage();
  209. vm.detailrecords = vm.detailrecords.concat(data);
  210. moddetail.numLoaded_ = vm.detailrecords.length;
  211. moddetail.lastStartIdx = vm.detailrecords.length;
  212. },
  213. function(error) {
  214. vm.infiniteDetailItems.loading_ = false;
  215. vm.infiniteDetailItems.toLoad_=0;
  216. utilsSvc.handleHttpError(error);
  217. }
  218. )
  219. }
  220. }
  221. }
  222. vm.getData = function(){
  223. Remuneration.HeaderCount({codiceSia: vm.codiceSiaSelezionato}).$promise.then(
  224. function(data){
  225. vm.records=[];
  226. vm.maxItems = data.value;
  227. vm.infiniteItems.numLoaded_ = 0;
  228. vm.infiniteItems.toLoad_ = 0;
  229. }
  230. );
  231. }
  232. vm.getProvisioning = function(idx, idremuneration) {
  233. vm.selectedIndex = idx;
  234. vm.currentDetailId = idremuneration;
  235. Remuneration.ProvisioningCount({id: idremuneration}).$promise.then(
  236. function(data){
  237. vm.detailrecords=[];
  238. vm.maxDetailItems = data.value;
  239. vm.infiniteDetailItems.numLoaded_ = 0;
  240. vm.infiniteDetailItems.toLoad_ = 0;
  241. }
  242. );
  243. }
  244. vm.richiestaDettaglioTuttiTrimestri = function(idx, event) {
  245. $mdDialog.show({
  246. targetEvent:event,
  247. templateUrl: 'templates/richiestaDettaglioMandatiSeda.html',
  248. controller: 'opzioniDettaglioCtrl',
  249. locals: {
  250. dialogTitle:'Richiesta dettaglio mandati SEDA'
  251. },
  252. multiple: true
  253. }).then(function(opzioni){
  254. Remuneration.GeneraRichiestaDettagli({id:vm.records[idx].idremuneration, all: true, tipoDettaglio:opzioni.tipologiaDettaglio,tipoRichiesta: opzioni.tipologiaRichiesta})
  255. .$promise.then(function(data){
  256. if (data.value=="")
  257. utilsSvc.showMessage("Richiesta dettaglio mandati effettuata");
  258. else
  259. utilsSvc.showMessage("Si è verificato un errore durante l'esecuzione del comando: " + data.value);
  260. })
  261. });
  262. }
  263. vm.exportMessaggi = function(idx, event) {
  264. if (vm.records[idx].flagUtil) {
  265. utilsSvc.showConfirm('Conferma', 'I messaggi SEDA Remuneration per il rendiconto corrente sono già stati creati, vuoi eseguire una nuova esportazione?')
  266. .then(function(){
  267. vm.doExportMessaggi(idx, event);
  268. })
  269. } else
  270. vm.doExportMessaggi(idx,event);
  271. }
  272. vm.doExportMessaggi = function(idx, event) {
  273. utilsSvc.showConfirm('Conferma',"Confermi l'esportazione dei messaggi SEDA Remuneration per il rendiconto corrente?")
  274. .then(function(res){
  275. Remuneration.ExportMessaggi({idremuneration:vm.records[idx].idremuneration})
  276. .$promise.then(function(data){
  277. vm.records[idx].flagUtil=true;
  278. var dt = new Date();
  279. utilsSvc.downloadFile('attachment/csv',data.response,'ExportRemunerationSeda_' + dt.getFullYear()+dt.getMonth().padZero(2)+dt.getDay().padZero(2)+'_'
  280. +dt.getHours().padZero(2)+ dt.getMinutes().padZero(2)
  281. +'.csv');
  282. }
  283. ).catch(function(err){
  284. if (err.status == 404)
  285. utilsSvc.showForever('Messuna delega estratta');
  286. else
  287. utilsSvc.handleHttpError(err);
  288. });
  289. })
  290. }
  291. vm.ricalcolaQuadratura = function(event) {
  292. if (vm.records.length>0 && vm.detailrecords.length>0) {
  293. utilsSvc.showConfirm('Conferma',"Confermi il ricalcolo della quadratura mandati attivi per tutti i trimestri presenti?")
  294. .then(function(res){
  295. utilsSvc.showForever('Richiesta in corso...');
  296. Remuneration.QuadraRemuneration({id:vm.records[vm.selectedIndex].idremuneration})
  297. .$promise.then(function(data){
  298. if (data.value=="0")
  299. utilsSvc.showMessage("Ricalcolo quadratura effettuato.");
  300. else
  301. utilsSvc.showMessage("Si è verificato un errore durante il ricalcolo: " +data.value);
  302. vm.getData();
  303. });
  304. })
  305. }
  306. }
  307. vm.ricalcolaQuadraturaDettaglio = function(event) {
  308. if (vm.records.length>0 && vm.detailrecords.length>0) {
  309. utilsSvc.showConfirm('Conferma',"Confermi il ricalcolo della quadratura mandati attivi per il rendiconto corrente?")
  310. .then(function(res){
  311. utilsSvc.showForever('Richiesta in corso...');
  312. Remuneration.QuadraDetail({id:vm.records[vm.selectedIndex].idremuneration, idDettaglio:vm.detailrecords[vm.selectedDetailIndex].idprevisioning})
  313. .$promise.then(function(data){
  314. if (data.value=="0")
  315. utilsSvc.showMessage("Ricalcolo quadratura effettuato.");
  316. else
  317. utilsSvc.showMessage("Si è verificato un errore durante il ricalcolo: " +data.value);
  318. vm.getData();
  319. });
  320. })
  321. }
  322. }
  323. vm.richiestaDettaglioMandati = function(idx, event) {
  324. Remuneration.DetailCount({id: vm.detailrecords[idx].idprevisioning})
  325. .$promise.then(function(data){
  326. if (data.value==0)
  327. utilsSvc.showMessage('Non è presente il dettaglio dei mandati ');
  328. else {
  329. $mdDialog.show({
  330. targetEvent:event,
  331. templateUrl: 'templates/dettaglioMandati.html',
  332. controller: 'dettaglioMandatiCtrl',
  333. locals: {
  334. dialogTitle:'Dettaglio mandati',
  335. maxItems: data.value,
  336. id: vm.detailrecords[idx].idprevisioning
  337. },
  338. multiple: true
  339. }).then(function(opzioni){
  340. });
  341. }
  342. })
  343. }
  344. vm.stampaRendiconto = function(idx, event) {
  345. utilsSvc.showForever('Generazione report in corso...');
  346. Remuneration.PrintPrevisioning({id: vm.detailrecords[idx].idremuneration})
  347. .$promise.then(function(data){
  348. utilsSvc.downloadFile('application/pdf',data.response,'sedaRemuneration.pdf');
  349. utilsSvc.cancelMessage();
  350. }).catch(function(err){
  351. if (err.status==404) {
  352. utilsSvc.cancelMessage();
  353. utilsSvc.showMessage('Nessun rendiconto estratto');
  354. } else
  355. utilsSvc.handleHttpError(err);
  356. }); ;
  357. }
  358. vm.richiestaDettaglioTrimestre = function(idx, event) {
  359. $mdDialog.show({
  360. targetEvent:event,
  361. templateUrl: 'templates/richiestaDettaglioMandatiSeda.html',
  362. controller: 'opzioniDettaglioCtrl',
  363. locals: {
  364. dialogTitle:'Richiesta dettaglio mandati SEDA'
  365. },
  366. multiple: true
  367. }).then(function(opzioni){
  368. Remuneration.GeneraRichiestaDettagliTrimestre({id:vm.records[vm.selectedIndex].idremuneration, idDettaglio: vm.detailrecords[idx].idprevisioning, all: true, tipoDettaglio:opzioni.tipologiaDettaglio,tipoRichiesta: opzioni.tipologiaRichiesta})
  369. .$promise.then(function(data){
  370. if (data.value=="")
  371. utilsSvc.showMessage("Richiesta dettaglio mandati effettuata");
  372. else
  373. utilsSvc.showMessage("Si è verificato un errore durante l'esecuzione del comando: " + data.value);
  374. })
  375. });
  376. }
  377. vm.mostraComandi = function(index, event){
  378. vm.getProvisioning(index, vm.records[index].idremuneration);
  379. vm.selectedIndex = index;
  380. $mdBottomSheet.show({
  381. templateUrl: 'templates/bottom-sheet-template.html',
  382. controller: 'comandiRemunerationCtrl',
  383. idx: index,
  384. targetEvent: event
  385. }).then(function(selectedCommand) {
  386. vm.executeCommand(selectedCommand.cmdIndex, selectedCommand.recordIdx, event);
  387. },
  388. function(){}
  389. );
  390. }
  391. vm.mostraComandiDettaglio = function(index, event){
  392. vm.selectedDetailIndex = index;
  393. $mdBottomSheet.show({
  394. templateUrl: 'templates/bottom-sheet-template.html',
  395. controller: 'comandiDettaglioCtrl',
  396. idx: index,
  397. targetEvent: event
  398. }).then(function(selectedCommand) {
  399. vm.executeDetailCommand(selectedCommand.cmdIndex, selectedCommand.recordIdx, event);
  400. },
  401. function(){}
  402. );
  403. }
  404. vm.init = function() {
  405. vm.getCodiciSia();
  406. vm.getData();
  407. }
  408. vm.executeDetailCommand = function(cmdIndex, idx, event) {
  409. switch(cmdIndex){
  410. case 0: vm.richiestaDettaglioTrimestre(idx, event); break;
  411. case 1: vm.richiestaDettaglioMandati(idx, event); break;
  412. case 2: vm.stampaRendiconto(idx, event); break;
  413. case 3: vm.ricalcolaQuadraturaDettaglio(event); break;
  414. }
  415. }
  416. vm.executeCommand = function(cmdIndex, idx, event) {
  417. switch(cmdIndex){
  418. case 0: vm.richiestaDettaglioTuttiTrimestri(idx, event); break;
  419. case 1: vm.exportMessaggi(idx, event); break;
  420. case 2: vm.ricalcolaQuadratura(event); break;
  421. }
  422. }
  423. vm.init();
  424. }
  425. )
  426. .controller('opzioniDettaglioCtrl',
  427. function ($scope,$mdDialog,$timeout,utilsSvc, locals) {
  428. $scope.dialogTitle = locals.dialogTitle;
  429. $scope.opzioni= {
  430. tipologiaDettaglio: 'ALL',
  431. tipologiaRichiesta: 'ALL'
  432. }
  433. $scope.confirmDialog = function() {
  434. $mdDialog.hide($scope.opzioni);
  435. }
  436. $scope.cancelDialog = function() {
  437. $mdDialog.cancel();
  438. }
  439. })
  440. .controller('comandiRemunerationCtrl', function($scope, $mdBottomSheet, idx) {
  441. $scope.title = 'Comandi remuneration';
  442. $scope.items = [
  443. { id:0, name: "Dettaglio trimestri", icon: 'fa-search', visible: true },
  444. { id:1, name: "Export messaggi", icon: 'fa-file-excel-o',visible: true },
  445. { id:2, name: "Ricalc. quadratura", icon: 'fa-cogs', visible: true }
  446. ];
  447. $scope.listItemClick = function($index, $event) {
  448. var clickedItem = $scope.items[$index];
  449. var result = {cmdIndex: $index, recordIdx: idx, event:$event}
  450. $mdBottomSheet.hide(result);
  451. };
  452. $scope.dismissBottomSheet = function() {
  453. $mdBottomSheet.cancel();
  454. }
  455. })
  456. .controller('comandiDettaglioCtrl', function($scope, $mdBottomSheet, idx) {
  457. $scope.title = 'Comandi';
  458. $scope.items = [
  459. { id:0, name: "Dettaglio trimestre", icon: 'fa-arrows-alt', visible: true },
  460. { id:1, name: "Dettaglio mandati", icon: 'fa-file-o',visible: true },
  461. { id:2, name: "Stampa rendiconto", icon: 'fa-print', visible: true },
  462. { id:3, name: "Ricalc. quadratura", icon: 'fa-cogs', visible: true }
  463. ];
  464. $scope.listItemClick = function($index, $event) {
  465. var clickedItem = $scope.items[$index];
  466. var result = {cmdIndex: $index, recordIdx: idx, event:$event}
  467. $mdBottomSheet.hide(result);
  468. };
  469. $scope.dismissBottomSheet = function() {
  470. $mdBottomSheet.cancel();
  471. }
  472. })
  473. .controller('dettaglioMandatiCtrl', function($scope, $window, $mdDialog, $q, utilsSvc, Remuneration, locals) {
  474. $scope.dialogTitle = locals.dialogTitle;
  475. $scope.maxItems = locals.maxItems;
  476. $scope.maxDetailItems = 0;
  477. $scope.itemsPerPage = 500;
  478. $scope.id = locals.id;
  479. $scope.records=[];
  480. $scope.orderField = "idprevisioning";
  481. $scope.confirmDialog = function() {
  482. $mdDialog.hide();
  483. }
  484. $scope.columnWidths=[
  485. 90, //0
  486. 90, //1
  487. 90, //2
  488. 120, //3
  489. 120, //4
  490. 110, //5this.listPromise
  491. 90, //6
  492. 90, //7
  493. 80
  494. ];
  495. $scope.setOrderField = function(field) {
  496. if ($scope.orderField!=field)
  497. $scope.orderField = field;
  498. else
  499. $scope.orderField = "-" +field;
  500. $scope.records=[];
  501. $scope.infiniteItems.numLoaded_ = 0;
  502. $scope.infiniteItems.toLoad_ = 0;
  503. }
  504. $scope.getListHeight = function() {
  505. return {'height': '260px'};
  506. // containerHeight = ($window.innerHeight - $('#container').position().top - $('#view').position().top);
  507. // return {'height': containerHeight + 'px'};
  508. };
  509. $window.addEventListener('resize', onResize);
  510. function onResize() {
  511. $scope.$digest();
  512. }
  513. $scope.$on('$destroy', function() {
  514. $window.removeEventListener('resize', onResize);
  515. });
  516. $scope.getColumnWidth = // }
  517. function(idx) {
  518. return {
  519. 'width': $scope.columnWidths[idx] + 'px',
  520. 'min-width':$scope.columnWidths[idx] + 'px',
  521. 'margin-left':'8px',
  522. 'margin-right':'8px'
  523. };
  524. }
  525. $scope.getMaxListWidth = function() {
  526. var res=0;
  527. for (var i=0;i<$scope.columnWidths.length;i++)
  528. res += $scope.columnWidths[i]+6+8+10;
  529. $('#container').css('width',($('#header').width()+10)+'px');
  530. return {'width': res+ 'px!important;'}
  531. }
  532. $scope.print = function() {
  533. utilsSvc.showForever('Generazione in corso...');
  534. Remuneration.PrintDetails({id:$scope.id}).$promise.then(function(data){
  535. utilsSvc.downloadFile('application/pdf',data.response,'RemunerazioneSedaDettagli.pdf');
  536. utilsSvc.cancelMessage();
  537. },function(err){
  538. utilsSvc.cancelMessage();
  539. if(err.status==404)
  540. utilsSvc.showMessage('Nessun rendiconto estratto');
  541. else
  542. utilsSvc.handleHttpError(err);
  543. })
  544. }
  545. $scope.infiniteItems = {
  546. numLoaded_: 0,
  547. toLoad_: 0,
  548. loading_:false,
  549. lastStartIdx:-1,
  550. listPromise:null,
  551. canceler: $q.defer(),
  552. // Required.
  553. getItemAtIndex: function(index) {
  554. if ($scope.maxItems==0 || index>$scope.maxItems)
  555. return null;
  556. if (index > $scope.records.length) {
  557. this.fetchMoreItems_(index);
  558. return null;
  559. }
  560. return $scope.records [index];
  561. },
  562. // Required.
  563. // For infinite scroll behavior, we always return a slightly
  564. // higher
  565. // number than the previously loaded items.
  566. getLength: function() {
  567. return $scope.maxItems;
  568. },
  569. fetchMoreItems_: function(index) {
  570. if (this.toLoad_ < index) {
  571. this.toLoad_ += $scope.itemsPerPage;
  572. utilsSvc.showWaitMessage('Ricerca in corso...');
  573. this.listPromise = Remuneration.Detail({id:$scope.id, start: $scope.records.length,size:Math.max($scope.records.length+index,$scope.itemsPerPage),orderBy:$scope.orderField}).$promise;
  574. var mod=this;
  575. this.listPromise.then(
  576. function(data){
  577. utilsSvc.cancelWaitMessage();
  578. $scope.records = $scope.records.concat(data);
  579. mod.numLoaded_ = $scope.records.length;
  580. mod.lastStartIdx = $scope.records.length;
  581. },
  582. function(error) {
  583. utilsSvc.handleHttpError(error);
  584. }
  585. )
  586. }
  587. }
  588. }
  589. })
  590. ;