lead.controller.js 2.8 KB

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