controllers.js
1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
angular.module('confjuvapp.controllers', [])
.controller('ProposalCtrl', function($scope, $ionicModal, $http, $ionicPopup) {
// FIXME: This list should come from the server
$scope.proposalList = [
{
title: 'Diminuir os juros do FIES'
},
{
title: 'Desmilitarizar a polícia'
}
];
// Login modal
// Initiate the modal
$ionicModal.fromTemplateUrl('html/_login.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
// Function to open the modal
$scope.openModal = function() {
$scope.modal.show();
};
// Function to close the modal
$scope.closeModal = function() {
$scope.modal.hide();
};
// Cleanup the modal when we're done with it!
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
// Function to login
$scope.Login = function(data) {
if (!data || !data.login || !data.password) {
return;
}
var req = {
method: 'POST',
url: ConfJuvAppUtils.pathTo('login'),
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
data: jQuery.param(data)
}
$http(req)
.success(function(data, status, headers, config) {
$scope.closeModal();
$ionicPopup.alert({ title: 'Login', template: 'Login efetuado com sucesso!' });
ConfJuvAppUtils.loggedIn = true;
})
.error(function(data, status, headers, config) {
$scope.closeModal();
var popup = $ionicPopup.alert({ title: 'Login', template: 'Erro ao efetuar login, por favor tente novamente.' });
ConfJuvAppUtils.loggedIn = false;
popup.then(function() {
$scope.openModal();
});
});
};
}); // Ends controller