| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- app.controller('utentiCtrl',
- function($scope,$http,$cookies,$window, $location,$timeout, $mdDialog, $q, $routeParams, $mdBottomSheet, $mdMedia, UserManager, FunzioniOrdinanti, utilsSvc) {
- var vm=this;
-
- vm.maxItems = 0;
- vm.itemsPerPage = 100;
- vm.selectedIndex=-1;
- vm.records=[];
- vm.allUsers=[];
- vm.funzioniOrdinanti=[];
- vm.filter={
- filterText: '',
- orderField:'userId'
- }
-
-
- vm.setSelected=function(idx) {
- vm.selectedIndex = idx;
- }
-
-
- vm.columnWidths=[
- 100, //0
- 150, //1
- 120, //2
- 120, //3
- 110, //4
- 150, //5
- 120, //6
- 120, //7
- 120, //8
- 120, //9
- 120, //10
- 140, //11
- 160, //12
- 160, //13
- 160, //14
- 180, //15
- 160, //16
- 160, //17
- 160, //18
- 160, //19
- 160, //20
- 160 //21
- ];
-
- vm.getListHeight = function() {
- containerHeight = ($window.innerHeight - $('#container').position().top - $('#view').position().top);
- return {'height': containerHeight + 'px'};
- };
- $window.addEventListener('resize', onResize);
- function onResize() {
- $scope.$digest();
- }
- $scope.$on('$destroy', function() {
- $window.removeEventListener('resize', onResize);
- });
-
- vm.getColumnWidth = // }
- // this.lastStartIdx = index;
- function(idx) {
- return {
- 'width': vm.columnWidths[idx] + 'px',
- 'min-width':vm.columnWidths[idx] + 'px',
- 'margin-left':'8px',
- 'margin-right':'8px'
- };
- }
-
- vm.getMaxListWidth = function() {
- var res=0;
- for (var i=0;i<vm.columnWidths.length;i++)
- res += vm.columnWidths[i]+6+8+10;
-
- $('#container').css('width',($('#header').width()+96)+'px');
- return {'width': res+ 'px!important;'}
- }
-
- vm.setOrderField = function(field) {
- if (vm.filter.orderField!=field)
- vm.filter.orderField = field;
- else
- vm.filter.orderField = "-" +field;
-
- vm.getUtenti();
- }
- vm.nuovoUtente = function(ev) {
- UserManager.New({}).$promise.then(
- function(data) {
- vm.records.push(data);
- vm.editUtente(vm.records.length-1,ev);
- }
- );
- }
-
- vm.editUtente = function(idx, ev) {
- vm.selectedIndex = idx;
- $mdDialog.show({
- targetEvent:ev,
- templateUrl: 'templates/utente.html',
- controller: 'utenteCtrl',
- locals: {utente:vm.records[idx], funzioniOrdinanti: vm.funzioniOrdinanti, utenti:vm.allUsers},
- multiple: true
- }).then(function(res){
- vm.records[idx] = res;
- UserManager.save({},res).$promise.then(
- function(res){
- vm.records[idx] = res;
- utilsSvc.showMessage('Salvataggio modifiche effettuato');
- vm.getUtenti();
- },
- function(err){
- utilsSvc.handleHttpError(err);
- }
- );
- },
- function() {
- if (vm.records[idx].id==null)
- vm.records.splice(idx,1);
- });
- }
- vm.eliminaUtente=function(utente,ev){
- utilsSvc.showConfirm('Conferma',"Confermi l'eliminazione dell'utente?")
- .then(function(res){
- UserManager.Delete({id:utente.id})
- .$promise.then(function(res){
- vm.getUtenti();
- utilsSvc.showMessage('Cancellazione effettuata');
- },
- function(err) {
- utilsSvc.handleHttpError(err);
- vm.getUtenti();
- }
- )
- });
- }
-
- vm.bloccaUtente = function(utente) {
- utente.bloccoUtente=true;
- vm.salvaUtente(utente);
- }
-
- vm.sbloccaUtente = function(utente) {
- utente.bloccoUtente=false;
- vm.salvaUtente(utente);
- }
-
- vm.salvaUtente=function(utente) {
- UserManager.save({},utente).$promise.then(
- function(res){
- utilsSvc.showMessage('Salvataggio modifiche effettuato');
- vm.getUtenti();
- },
- function(err){
- utilsSvcFunzioniOrdinanti.handleHttpError(err);
- }
- );
- }
-
- vm.infiniteItems = {
- numLoaded_: 0,
- toLoad_: 0,
- loading_:false,
- lastStartIdx:-1,
- listPromise:null,
- canceler: $q.defer(),
- // Required.
- getItemAtIndex: function(index) {
- if (vm.maxItems==0 || index>vm.maxItems)
- return null;
- if (!vm.infiniteItems.loading_)
- if (index > vm.records.length) {
- this.fetchMoreItems_(index);
- return null;
- }
- return vm.records [index];
- },
- // Required.
- // For infinite scroll behavior, we always return a slightly
- // higher
- // number than the previously loaded items.
- getLength: function() {
- return vm.maxItems;// FunzioniOrdinanti.List().$promise.then(
- // function(data){
- // vm.funzioniOrdinanti=data;
- // },
- // function(err){
- // utilsSvc.handleHttpError(err);
- // });
-
- },
- fetchMoreItems_: function(index) {
- if (this.toLoad_ < index) {
- this.toLoad_ += vm.itemsPerPage;
- utilsSvc.showWaitMessage('Ricerca in corso...');
- vm.infiniteItems.loading_ = true;
- 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;
-
- var mod=this;
- this.listPromise.then(
- function(data){
- vm.infiniteItems.loading_ = false;
- vm.infiniteItems.toLoad_=0;
- utilsSvc.cancelWaitMessage();
- vm.records = vm.records.concat(data);
- mod.numLoaded_ = vm.records.length;
- mod.lastStartIdx = vm.records.length;
- },
- function(error) {
- vm.infiniteItems.loading_ = false;
- vm.infiniteItems.toLoad_=0;
- utilsSvc.handleHttpError(error);
- }
- )
- }
- }
- }
-
- vm.getUtenti = function(){
- UserManager.Count({filter: vm.filter.filterText}).$promise.then(
- function(data){
- vm.records=[];
- vm.maxItems = data.value;
- vm.infiniteItems.numLoaded_ = 0;
- vm.infiniteItems.toLoad_ = 0;
-
- },
- function(err){
- utilsSvc.handleHttpError(err);
- }
- );
- }
-
- vm.getAllUtenti = function(){
- UserManager.List({start: 0,size:99999,filter: '', orderField:'userId'}).$promise
- .then(function(data){
- vm.allUsers = data;
- })
- }
-
- vm.init = function() {
- vm.getUtenti();
- vm.getAllUtenti();
-
- FunzioniOrdinanti.List().$promise.then(
- function(data){
- vm.funzioniOrdinanti=data;
- },
- function(err){
- utilsSvc.handleHttpError(err);
- });
- }
-
- vm.init();
- })
- .controller("utenteCtrl",function($scope, $mdDialog, utilsSvc, locals){
-
- $scope.utente = angular.copy(locals.utente);
- $scope.funzioniOrdinanti = locals.funzioniOrdinanti;
- $scope.utenti = locals.utenti;
- if ($scope.utente.importoLimiteFirma==null)
- $scope.importoLimiteFirma = "0,00";
- else
- $scope.importoLimiteFirma = $scope.utente.importoLimiteFirma.formatAsCurrency();
-
-
- $scope.checkDigit=function(event, len){
- if (event.key=="Backspace" || event.key=="ArrowLeft" || event.key=="ArrowRight" || event.key=="Tab")
- return;
- if ("0123456789,.".indexOf(event.key)==-1 || event.target.value.length>=len)
- event.preventDefault();
- }
-
- $scope.checkImporto = function($event) {
- var importo = $scope.importoLimiteFirma.toCurrency();
- if (importo==null) {
- utilsSvc.showMessage('Importo non valido');
- $scope.importoLimiteFirma = 0;
- return;
- } else {
- $scope.importoLimiteFirma = importo.formatAsCurrency();
- }
-
- $scope.exitField($event);
- }
-
- $scope.confirmDialog = function(){
- if (!$scope.form.$valid)
- utilsSvc.showMessage("Verificare i dati inseriti")
- else {
- if ($scope.datiValidi()) {
- $scope.utente.importoLimiteFirma=$scope.importoLimiteFirma.toCurrency();
- $mdDialog.hide($scope.utente);
- }
- }
- }
-
- $scope.cancelDialog=function(){
- $mdDialog.cancel();
- }
-
- $scope.datiValidi=function(){
- // verifica che l'utente sia univoco
- for (var i=0;i<$scope.utenti.length;i++) {
- if ($scope.utente.id!=$scope.utenti[i].id)
- if ($scope.utente.userId==$scope.utenti[i].userId && $scope.utente.profiloLocale==$scope.utenti[i].profiloLocale) {
- utilsSvc.show('Utente già presente ');
- return false;
- }
- }
-
- if ($scope.utente.abilitazioneBonifici || $scope.utente.abilitazioneAea || $scope.utente.abilitazioneRid) {
- if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="VI") {
- utilsSvc.show("L'abilitazione alle tipologie è impostabile solo i profili utente Operatore/Responsabile e Visualizzatore");
- return false;
- }
- }
-
- if ($scope.utente.visualizzazioneGlobaleDisposizioni) {
- if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="VI") {
- utilsSvc.show("L'abilitazione alla visualizzazione di tutte le disposizioni è impostabile solo i profili utente Operatore/Responsabile e Visualizzatore");
- return false;
- }
- }
-
- if ($scope.utente.abilitaAccessoAnagrafica) {
- if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="TO" && $scope.utente.profiloLocale!="TR" && $scope.utente.profiloLocale!="VI") {
- utilsSvc.show("L'accesso alla gestione anagrafica è impostabile solo i profili Utente Operatore/Responsabile, di Tesoreria e Visualizzatore");
- return false;
- }
- }
-
- if ($scope.utente.abilitaForzaturaSospeso) {
- if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR" && $scope.utente.profiloLocale!="TO" && $scope.utente.profiloLocale!="TR") {
- utilsSvc.show("L'accesso alla forzatura sospeso è impostabile solo i profili Utente Operatore/Responsabile e di Tesoreria");
- return false;
- }
- }
-
- if ($scope.utente.abilitaApprovazioneMassiva) {
- if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR") {
- utilsSvc.show("L'approvazione massiva delle disposizioni è impostabile solo per il profilo 'Utente Responsabile");
- return false;
- }
- }
- if ($scope.utente.bloccoModificaDisposizioni) {
- if ($scope.utente.profiloLocale!="UO" && $scope.utente.profiloLocale!="UR") {
- utilsSvc.show("L'abilitazione al blocco della modifica disposizioni è impostabile solo i profili Utente Operatore/Responsabile");
- return false;
- }
- }
-
- return true;
- }
-
- })
- ;
|