lead.controller.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. angular.module('odoo')
  2. .controller('LeadsController', function (
  3. $scope,
  4. $ionicModal,
  5. $ionicActionSheet,
  6. $ionicPopup,
  7. leads
  8. ) {
  9. $scope.leads = [];
  10. $scope.lead = {};
  11. $ionicModal.fromTemplateUrl('templates/sales/lead.html', {
  12. scope: $scope,
  13. animation: 'slide-in-up'
  14. }).then(function(modal) {
  15. $scope.leadModal = modal;
  16. });
  17. $scope.$on('$ionicView.enter', function () {
  18. $scope.fill();
  19. });
  20. $scope.$on('$destroy', function() {
  21. $scope.leadModal.remove();
  22. });
  23. $scope.$on('modal.hidden', function() {
  24. $scope.lead = {};
  25. });
  26. $scope.fill = function () {
  27. leads.read(function (leads) {
  28. console.log(leads);
  29. $scope.leads = leads;
  30. }, function (error) {
  31. console.log(error);
  32. });
  33. }
  34. $scope.show = function () {
  35. $scope.leadModal.show();
  36. }
  37. $scope.save = function () {
  38. }
  39. $scope.delete = function () {
  40. $ionicPopup.confirm({
  41. title: 'Confirmar',
  42. template: 'Estás seguro que quieres eliminar esta iniciativa?'
  43. }).then(function (confirmation) {
  44. if(confirmation) {
  45. console.log(confirmation);
  46. }
  47. });
  48. }
  49. $scope.openOptions = function (index) {
  50. if (index == -1) {
  51. $scope.lead = {};
  52. } else {
  53. $scope.lead = $scope.leads[index];
  54. }
  55. $ionicActionSheet.show({
  56. titleText: 'Acciones',
  57. buttons: [
  58. {
  59. text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
  60. },
  61. {
  62. text: '<i class="icon ion-wand positive"></i> Convertir a oportunidad'
  63. }
  64. ],
  65. destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
  66. cancel: function() {
  67. $scope.lead = {};
  68. $log.info('ActionSheet canceled');
  69. },
  70. buttonClicked: function(index) {
  71. switch (index) {
  72. case 0:
  73. $scope.show();
  74. break;
  75. case 1:
  76. console.log('1');
  77. break;
  78. default:
  79. $scope.show();
  80. }
  81. return true;
  82. },
  83. destructiveButtonClicked: function() {
  84. $scope.delete();
  85. return true;
  86. }
  87. });
  88. }
  89. });