opportunity.controller.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. angular.module('odoo')
  2. .controller('OpportunitiesController', function (
  3. $scope,
  4. $ionicActionSheet,
  5. crmStagesDataFactory
  6. ) {
  7. $scope.stages = [];
  8. $scope.opportunities = [
  9. {
  10. name: 'Op. 1',
  11. stage: 'Nuevo'
  12. },
  13. {
  14. name: 'Op. 2',
  15. stage: 'Perdido'
  16. },
  17. {
  18. name: 'Op. 3',
  19. stage: 'Propuesta'
  20. },
  21. {
  22. name: 'Op. 1',
  23. stage: 'Nuevo'
  24. },
  25. {
  26. name: 'Op. 1',
  27. stage: 'Nuevo'
  28. },
  29. {
  30. name: 'Op. 1',
  31. stage: 'Nuevo'
  32. }
  33. ];
  34. $scope.title = '';
  35. $scope.loading = false;
  36. $scope.selected = -1;
  37. $scope.$on("$ionicSlides.sliderInitialized", function (event, data){
  38. $scope.slider = data.slider;
  39. });
  40. $scope.$on("$ionicSlides.slideChangeEnd", function (event, data) {
  41. $scope.stageChanged(data.slider.activeIndex);
  42. });
  43. $scope.$on("$ionicView.enter", function () {
  44. $scope.getStages();
  45. });
  46. $scope.getStages = function () {
  47. crmStagesDataFactory.sync(function (stages) {
  48. $scope.stages = stages;
  49. $scope.stageChanged(0);
  50. }, function (syncErr) {
  51. console.log(syncErr);
  52. });
  53. }
  54. /**
  55. * Change the state
  56. */
  57. $scope.changeStage = function (mode) {
  58. $scope.loading = true;
  59. if (mode) {
  60. $scope.slider.slideNext();
  61. } else {
  62. $scope.slider.slidePrev();
  63. }
  64. $scope.loading = false;
  65. }
  66. /**
  67. * Change stage name on title
  68. */
  69. $scope.stageChanged = function (index) {
  70. if (!$scope.stages.length) {
  71. return;
  72. }
  73. $scope.title = $scope.stages[index].name;
  74. if(!$scope.$$phase) {
  75. $scope.$apply();
  76. }
  77. }
  78. /**
  79. * Open the actionsheet action options
  80. */
  81. $scope.openOptions = function (index) {
  82. $scope.selected = index;
  83. $ionicActionSheet.show({
  84. titleText: 'Acciones',
  85. buttons: [
  86. {
  87. text: '<i class="icon ion-arrow-expand positive"></i> Abrir'
  88. },
  89. {
  90. text: '<i class="icon ion-forward positive"></i> Mover a'
  91. }
  92. ],
  93. destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
  94. cancel: function() {
  95. $scope.customer = {};
  96. $scope.selected = -1;
  97. },
  98. buttonClicked: function(index) {
  99. switch (index) {
  100. case 0:
  101. $scope.show();
  102. break;
  103. case 1:
  104. $scope.addContact();
  105. break;
  106. default:
  107. $scope.show();
  108. }
  109. return true;
  110. },
  111. destructiveButtonClicked: function() {
  112. $scope.delete();
  113. return true;
  114. }
  115. });
  116. }
  117. });