(function(){
    'use strict';

    angular.module('sisatosApp')
           .controller('loginCtrl', function($scope, $http){
            $scope.return    = false;
            $scope.processed = false;
            $scope.r = {'submitClass':false,
                        'class': '', 
                        'erroPriMsg':false, 
                        'erroSecMsg': false};
            $scope.formModel = {};
            $scope.onSubmit = function(){  
              $scope.r.submitClass = true;
              var data = {'acao': 'login',
                          'email': $scope.formModel.email,
                          'senha': $scope.formModel.senha };
              var config = {'Content-type':'application/x-www-form-urlencoded;charset=utf-8'};             
              $http.post('app/model/ajax/ajax_login.php', data, config)
                      .then(function(r){
                         $scope.return = r.data.geral;
                         $scope.processed = true;
                         $scope.r.submitClass = false;
                         $scope.r.erroPriMsg = r.data.msgPri;
                         $scope.r.erroSecMsg = r.data.msgSec;
                         $scope.r.class = r.data.class;
                         if($scope.return){
                             window.location.href='../'+path;
                         }
                       },function(data){
                         console.log("foi isso que deu: "+data);
                      });
            };
    });
})(); 

