utentiCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. app.controller('utentiCtrl',
  2. function($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, $routeParams, $mdBottomSheet, $mdMedia, UserManager, FunzioniOrdinanti, utilsSvc) {
  3. var vm=this;
  4. vm.maxItems = 0;
  5. vm.itemsPerPage = 100;
  6. vm.selectedIndex=-1;
  7. vm.records=[];
  8. vm.allUsers=[];
  9. vm.funzioniOrdinanti=[];
  10. vm.filter={
  11. filterText: '',
  12. orderField:'userId'
  13. }
  14. vm.setSelected=function(idx) {
  15. vm.selectedIndex = idx;
  16. }
  17. vm.columnWidths=[
  18. 100, //0
  19. 150, //1
  20. 120, //2
  21. 120, //3
  22. 110, //4
  23. 150, //5
  24. 120, //6
  25. 120, //7
  26. 120, //8
  27. 120, //9
  28. 120, //10
  29. 140, //11
  30. 160, //12
  31. 160, //13
  32. 160, //14
  33. 180, //15
  34. 160, //16
  35. 160, //17
  36. 160, //18
  37. 160, //19
  38. 160, //20
  39. 160 //21
  40. ];
  41. vm.getListHeight = function() {
  42. containerHeight = ($window.innerHeight - $('#container').position().top - $('#view').position().top);
  43. return {'height': containerHeight + 'px'};
  44. };
  45. $window.addEventListener('resize', onResize);
  46. function onResize() {
  47. $scope.$digest();
  48. }
  49. $scope.$on('$destroy', function() {
  50. $window.removeEventListener('resize', onResize);
  51. });
  52. vm.getColumnWidth = // }
  53. // this.lastStartIdx = index;
  54. function(idx) {
  55. return {
  56. 'width': vm.columnWidths[idx] + 'px',
  57. 'min-width':vm.columnWidths[idx] + 'px',
  58. 'margin-left':'8px',
  59. 'margin-right':'8px'
  60. };
  61. }
  62. vm.getMaxListWidth = function() {
  63. var res=0;
  64. for (var i=0;i<vm.columnWidths.length;i++)
  65. res += vm.columnWidths[i]+6+8+10;
  66. $('#container').css('width',($('#header').width()+96)+'px');
  67. return {'width': res+ 'px!important;'}
  68. }
  69. vm.setOrderField = function(field) {
  70. if (vm.filter.orderField!=field)
  71. vm.filter.orderField = field;
  72. else
  73. vm.filter.orderField = "-" +field;
  74. vm.getUtenti();
  75. }
  76. vm.nuovoUtente = function(ev) {
  77. UserManager.New({}).$promise.then(
  78. function(data) {
  79. vm.records.push(data);
  80. vm.editUtente(vm.records.length-1,ev);
  81. }
  82. );
  83. }
  84. vm.editUtente = function(idx, ev) {
  85. vm.selectedIndex = idx;
  86. $mdDialog.show({
  87. targetEvent:ev,
  88. templateUrl: 'templates/utente.html',
  89. controller: 'utenteCtrl',
  90. locals: {utente:vm.records[idx], funzioniOrdinanti: vm.funzioniOrdinanti, utenti:vm.allUsers},
  91. multiple: true
  92. }).then(function(res){
  93. vm.records[idx] = res;
  94. UserManager.save({},res).$promise.then(
  95. function(res){
  96. vm.records[idx] = res;
  97. utilsSvc.showMessage('Salvataggio modifiche effettuato');
  98. vm.getUtenti();
  99. },
  100. function(err){
  101. utilsSvc.handleHttpError(err);
  102. }
  103. );
  104. },
  105. function() {
  106. if (vm.records[idx].id==null)
  107. vm.records.splice(idx,1);
  108. });
  109. }
  110. vm.eliminaUtente=function(utente,ev){
  111. utilsSvc.showConfirm('Conferma',"Confermi l'eliminazione dell'utente?")
  112. .then(function(res){
  113. UserManager.Delete({id:utente.id})
  114. .$promise.then(function(res){
  115. vm.getUtenti();
  116. utilsSvc.showMessage('Cancellazione effettuata');
  117. },
  118. function(err) {
  119. utilsSvc.handleHttpError(err);
  120. vm.getUtenti();
  121. }
  122. )
  123. });
  124. }
  125. vm.bloccaUtente = function(utente) {
  126. utente.bloccoUtente=true;
  127. vm.salvaUtente(utente);
  128. }
  129. vm.sbloccaUtente = function(utente) {
  130. utente.bloccoUtente=false;
  131. vm.salvaUtente(utente);
  132. }
  133. vm.salvaUtente=function(utente) {
  134. UserManager.save({},utente).$promise.then(
  135. function(res){
  136. utilsSvc.showMessage('Salvataggio modifiche effettuato');
  137. vm.getUtenti();
  138. },
  139. function(err){
  140. utilsSvcFunzioniOrdinanti.handleHttpError(err);
  141. }
  142. );
  143. }
  144. vm.infiniteItems = {
  145. numLoaded_: 0,
  146. toLoad_: 0,
  147. loading_:false,
  148. lastStartIdx:-1,
  149. listPromise:null,
  150. canceler: $q.defer(),
  151. // Required.
  152. getItemAtIndex: function(index) {
  153. if (vm.maxItems==0 || index>vm.maxItems)
  154. return null;
  155. if (!vm.infiniteItems.loading_)
  156. if (index > vm.records.length) {
  157. this.fetchMoreItems_(index);
  158. return null;
  159. }
  160. return vm.records [index];
  161. },
  162. // Required.
  163. // For infinite scroll behavior, we always return a slightly
  164. // higher
  165. // number than the previously loaded items.
  166. getLength: function() {
  167. return vm.maxItems;// FunzioniOrdinanti.List().$promise.then(
  168. // function(data){
  169. // vm.funzioniOrdinanti=data;
  170. // },
  171. // function(err){
  172. // utilsSvc.handleHttpError(err);
  173. // });
  174. },
  175. fetchMoreItems_: function(index) {
  176. if (this.toLoad_ < index) {
  177. this.toLoad_ += vm.itemsPerPage;
  178. utilsSvc.showWaitMessage('Ricerca in corso...');
  179. vm.infiniteItems.loading_ = true;
  180. this.listPromise = UserManager.List({start: vm.records.length,size:Math.max(vm.records.length+index,vm.itemsPerPage),filter: vm.filter.filterText, orderField:vm.filter.orderField}).$promise;
  181. var mod=this;
  182. this.listPromise.then(
  183. function(data){
  184. vm.infiniteItems.loading_ = false;
  185. vm.infiniteItems.toLoad_=0;
  186. utilsSvc.cancelWaitMessage();
  187. vm.records = vm.records.concat(data);
  188. mod.numLoaded_ = vm.records.length;
  189. mod.lastStartIdx = vm.records.length;
  190. },
  191. function(error) {
  192. vm.infiniteItems.loading_ = false;
  193. vm.infiniteItems.toLoad_=0;
  194. utilsSvc.handleHttpError(error);
  195. }
  196. )
  197. }
  198. }
  199. }
  200. vm.getUtenti = function(){
  201. UserManager.Count({filter: vm.filter.filterText}).$promise.then(
  202. function(data){
  203. vm.records=[];
  204. vm.maxItems = data.value;
  205. vm.infiniteItems.numLoaded_ = 0;
  206. vm.infiniteItems.toLoad_ = 0;
  207. },
  208. function(err){
  209. utilsSvc.handleHttpError(err);
  210. }
  211. );
  212. }
  213. vm.getAllUtenti = function(){
  214. UserManager.List({start: 0,size:99999,filter: '', orderField:'userId'}).$promise
  215. .then(function(data){
  216. vm.allUsers = data;
  217. })
  218. }
  219. vm.init = function() {
  220. vm.getUtenti();
  221. vm.getAllUtenti();
  222. FunzioniOrdinanti.List().$promise.then(
  223. function(data){
  224. vm.funzioniOrdinanti=data;
  225. },
  226. function(err){
  227. utilsSvc.handleHttpError(err);
  228. });
  229. }
  230. vm.init();
  231. })
  232. .controller("utenteCtrl",function($scope, $mdDialog, utilsSvc, locals){
  233. $scope.utente = angular.copy(locals.utente);
  234. $scope.funzioniOrdinanti = locals.funzioniOrdinanti;
  235. $scope.utenti = locals.utenti;
  236. if ($scope.utente.importoLimiteFirma==null)
  237. $scope.importoLimiteFirma = "0,00";
  238. else
  239. $scope.importoLimiteFirma = $scope.utente.importoLimiteFirma.formatAsCurrency();
  240. $scope.checkDigit=function(event, len){
  241. if (event.key=="Backspace" || event.key=="ArrowLeft" || event.key=="ArrowRight" || event.key=="Tab")
  242. return;
  243. if ("0123456789,.".indexOf(event.key)==-1 || event.target.value.length>=len)
  244. event.preventDefault();
  245. }
  246. $scope.checkImporto = function($event) {
  247. var importo = $scope.importoLimiteFirma.toCurrency();
  248. if (importo==null) {
  249. utilsSvc.showMessage('Importo non valido');
  250. $scope.importoLimiteFirma = 0;
  251. return;
  252. } else {
  253. $scope.importoLimiteFirma = importo.formatAsCurrency();
  254. }
  255. $scope.exitField($event);
  256. }
  257. $scope.confirmDialog = function(){
  258. if (!$scope.form.$valid)
  259. utilsSvc.showMessage("Verificare i dati inseriti")
  260. else {
  261. if ($scope.datiValidi()) {
  262. $scope.utente.importoLimiteFirma=$scope.importoLimiteFirma.toCurrency();
  263. $mdDialog.hide($scope.utente);
  264. }
  265. }
  266. }
  267. $scope.cancelDialog=function(){
  268. $mdDialog.cancel();
  269. }
  270. $scope.datiValidi=function(){
  271. // verifica che l'utente sia univoco
  272. for (var i=0;i<$scope.utenti.length;i++) {
  273. if ($scope.utente.id!=$scope.utenti[i].id)
  274. if ($scope.utente.userId==$scope.utenti[i].userId && $scope.utente.profiloLocale==$scope.utenti[i].profiloLocale) {
  275. utilsSvc.show('Utente già presente ');
  276. return false;
  277. }
  278. }
  279. if ($scope.utente.abilitazioneBonifici || $scope.utente.abilitazioneAea || $scope.utente.abilitazioneRid) {
  280. if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="VI") {
  281. utilsSvc.show("L'abilitazione alle tipologie è impostabile solo i profili utente Operatore/Responsabile e Visualizzatore");
  282. return false;
  283. }
  284. }
  285. if ($scope.utente.visualizzazioneGlobaleDisposizioni) {
  286. if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="VI") {
  287. utilsSvc.show("L'abilitazione alla visualizzazione di tutte le disposizioni è impostabile solo i profili utente Operatore/Responsabile e Visualizzatore");
  288. return false;
  289. }
  290. }
  291. if ($scope.utente.abilitaAccessoAnagrafica) {
  292. if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="TO" && $scope.utente.profiloLocale!="TR" && $scope.utente.profiloLocale!="VI") {
  293. utilsSvc.show("L'accesso alla gestione anagrafica è impostabile solo i profili Utente Operatore/Responsabile, di Tesoreria e Visualizzatore");
  294. return false;
  295. }
  296. }
  297. if ($scope.utente.abilitaForzaturaSospeso) {
  298. if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="TO" && $scope.utente.profiloLocale!="TR") {
  299. utilsSvc.show("L'accesso alla forzatura sospeso è impostabile solo i profili Utente Operatore/Responsabile e di Tesoreria");
  300. return false;
  301. }
  302. }
  303. if ($scope.utente.abilitaApprovazioneMassiva) {
  304. if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR") {
  305. utilsSvc.show("L'approvazione massiva delle disposizioni è impostabile solo per il profilo 'Utente Responsabile");
  306. return false;
  307. }
  308. }
  309. if ($scope.utente.bloccoModificaDisposizioni) {
  310. if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR") {
  311. utilsSvc.show("L'abilitazione al blocco della modifica disposizioni è impostabile solo i profili Utente Operatore/Responsabile");
  312. return false;
  313. }
  314. }
  315. return true;
  316. }
  317. })
  318. ;