app.controller('filtroDisposizioniCtrl', 
function ($scope,$mdDialog,locals) {
	
	$scope.filter = locals.filter;
	$scope.confirmDialog = function() {
    	if (!$scope.form.$valid)
    		return;
    	
    	
        $mdDialog.hide($scope.filter);
    }

	$scope.cancelDialog = function() {
    	$mdDialog.cancel();
    }
    
    
    $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.onlyDigit=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 dataField = $event.target;
		var fieldName = dataField.getAttribute("ng-model");
		fieldName = fieldName.substring(fieldName.indexOf(".") + 1);
		
		var importo = $scope.$eval( dataField.getAttribute("ng-model"));
		if (importo==null) {
			$event.target.value ='';
			 return;
		} else {
			$event.target.value =  importo.toCurrency().formatAsCurrency(); 
		}
			
	}

});