angular.module('odoo') .controller('LeadsController', function ( $scope, $ionicModal, $ionicActionSheet, $ionicPopup, leads ) { $scope.leads = []; $scope.lead = {}; $ionicModal.fromTemplateUrl('templates/sales/lead.html', { scope: $scope, animation: 'slide-in-up' }).then(function(modal) { $scope.leadModal = modal; }); $scope.$on('$ionicView.enter', function () { $scope.fill(); }); $scope.$on('$destroy', function() { $scope.leadModal.remove(); }); $scope.$on('modal.hidden', function() { $scope.lead = {}; }); $scope.fill = function () { leads.read(function (leads) { console.log(leads); $scope.leads = leads; }, function (error) { console.log(error); }); } $scope.show = function () { $scope.leadModal.show(); } $scope.save = function () { } $scope.delete = function () { $ionicPopup.confirm({ title: 'Confirmar', template: 'Estás seguro que quieres eliminar esta iniciativa?' }).then(function (confirmation) { if(confirmation) { console.log(confirmation); } }); } $scope.openOptions = function (index) { if (index == -1) { $scope.lead = {}; } else { $scope.lead = $scope.leads[index]; } $ionicActionSheet.show({ titleText: 'Acciones', buttons: [ { text: ' Abrir' }, { text: ' Convertir a oportunidad' } ], destructiveText: ' Eliminar', cancel: function() { $scope.lead = {}; $log.info('ActionSheet canceled'); }, buttonClicked: function(index) { switch (index) { case 0: $scope.show(); break; case 1: console.log('1'); break; default: $scope.show(); } return true; }, destructiveButtonClicked: function() { $scope.delete(); return true; } }); } });