|
@@ -6,6 +6,7 @@ angular.module('odoo')
|
|
.controller('OpportunitiesController', function (
|
|
.controller('OpportunitiesController', function (
|
|
$scope,
|
|
$scope,
|
|
$ionicPopup,
|
|
$ionicPopup,
|
|
|
|
+ $ionicModal,
|
|
$ionicFilterBar,
|
|
$ionicFilterBar,
|
|
$ionicActionSheet,
|
|
$ionicActionSheet,
|
|
deviceFactory,
|
|
deviceFactory,
|
|
@@ -13,10 +14,13 @@ angular.module('odoo')
|
|
opportunitiesDataFactory
|
|
opportunitiesDataFactory
|
|
) {
|
|
) {
|
|
|
|
|
|
|
|
+ // =======================================================================================================
|
|
$scope.loading = false;
|
|
$scope.loading = false;
|
|
$scope.selectedIndex = -1;
|
|
$scope.selectedIndex = -1;
|
|
$scope.search = null;
|
|
$scope.search = null;
|
|
$scope.stages = [];
|
|
$scope.stages = [];
|
|
|
|
+ $scope.stagesToMove = [];
|
|
|
|
+ $scope.opportunity = {};
|
|
$scope.opportunities = [];
|
|
$scope.opportunities = [];
|
|
$scope.groupedOpportunities = [];
|
|
$scope.groupedOpportunities = [];
|
|
$scope.stage = {
|
|
$scope.stage = {
|
|
@@ -24,26 +28,35 @@ angular.module('odoo')
|
|
current: null,
|
|
current: null,
|
|
next: null
|
|
next: null
|
|
};
|
|
};
|
|
- $scope.stageToMove = {};
|
|
|
|
|
|
+ // =======================================================================================================
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- $scope.$on("$ionicSlides.sliderInitialized", function (event, data) {
|
|
|
|
|
|
+ $ionicModal.fromTemplateUrl('templates/sales/opportunity.html', {
|
|
|
|
+ scope: $scope
|
|
|
|
+ }).then(function (modal) {
|
|
|
|
+ $scope.modal = modal;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ $scope.$on('$ionicSlides.sliderInitialized', function (event, data) {
|
|
$scope.slider = data.slider;
|
|
$scope.slider = data.slider;
|
|
});
|
|
});
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- $scope.$on("$ionicSlides.slideChangeStart", function (event, data) {
|
|
|
|
|
|
+ $scope.$on('$ionicSlides.slideChangeStart', function (event, data) {
|
|
$scope.loading = true;
|
|
$scope.loading = true;
|
|
});
|
|
});
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- $scope.$on("$ionicSlides.slideChangeEnd", function (event, data) {
|
|
|
|
|
|
+ $scope.$on('$ionicSlides.slideChangeEnd', function (event, data) {
|
|
$scope.loading = false;
|
|
$scope.loading = false;
|
|
$scope.stageChanged(data.slider.activeIndex);
|
|
$scope.stageChanged(data.slider.activeIndex);
|
|
});
|
|
});
|
|
@@ -51,10 +64,17 @@ angular.module('odoo')
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- $scope.$on("$ionicView.enter", function () {
|
|
|
|
|
|
+ $scope.$on('$ionicView.enter', function () {
|
|
$scope.initialize();
|
|
$scope.initialize();
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ $scope.$on('$destroy', function () {
|
|
|
|
+ $scope.modal.remove();
|
|
|
|
+ });
|
|
|
|
+
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@@ -129,6 +149,26 @@ angular.module('odoo')
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ $scope.filterStages = function () {
|
|
|
|
+ $scope.stagesToMove = $scope.stages.filter(function (item) {
|
|
|
|
+ return item.id != $scope.stage.current.id;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ $scope.toogleNew = function () {
|
|
|
|
+ if ($scope.stages.length > 0) {
|
|
|
|
+ $scope.opportunity.stage_id = $scope.stages[0].remote_id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $scope.modal.show();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@@ -141,6 +181,58 @@ angular.module('odoo')
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ $scope.save = function () {
|
|
|
|
+ opportunitiesDataFactory.save($scope.opportunity, function (opportunityId) {
|
|
|
|
+ $scope.modal.hide();
|
|
|
|
+
|
|
|
|
+ console.log($scope.opportunity);
|
|
|
|
+
|
|
|
|
+ if (!$scope.opportunity.id) {
|
|
|
|
+ console.log('Entra aqui');
|
|
|
|
+ $scope.opportunity.id = opportunityId;
|
|
|
|
+ $scope.opportunities.push($scope.opportunity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $scope.groupOpportunities();
|
|
|
|
+ $scope.opportunity = {};
|
|
|
|
+
|
|
|
|
+ $scope.$apply();
|
|
|
|
+
|
|
|
|
+ deviceFactory.toast('Nueva opportunidad creada');
|
|
|
|
+ }, function (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ deviceFactory.toast('No se ha podido guardar la opportunidad');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ $scope.delete = function () {
|
|
|
|
+ deviceFactory.confirm('Estás seguro que quieres eliminar ésta oportunidad?', 'Confirmar', function (index) {
|
|
|
|
+
|
|
|
|
+ if (index == 1) {
|
|
|
|
+ opportunitiesDataFactory.remove($scope.opportunity, function (affected) {
|
|
|
|
+ if (affected != 0) {
|
|
|
|
+ var index = $scope.opportunities.indexOf($scope.opportunity);
|
|
|
|
+ $scope.opportunities.splice(index, 1);
|
|
|
|
+ $scope.opportunity = {};
|
|
|
|
+
|
|
|
|
+ $scope.groupOpportunities();
|
|
|
|
+ $scope.$apply();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }, function (err) {
|
|
|
|
+ console.log(err);
|
|
|
|
+ deviceFactory.toast('No se ha podido eliminar la oportunidad');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Change the state
|
|
* Change the state
|
|
*/
|
|
*/
|
|
@@ -181,43 +273,41 @@ angular.module('odoo')
|
|
* Show availables stages to move
|
|
* Show availables stages to move
|
|
*/
|
|
*/
|
|
$scope.showStagesToMove = function () {
|
|
$scope.showStagesToMove = function () {
|
|
- $ionicPopup.show({
|
|
|
|
|
|
+ $scope.filterStages();
|
|
|
|
+
|
|
|
|
+ $scope.selectStage = $ionicPopup.show({
|
|
scope: $scope,
|
|
scope: $scope,
|
|
title: 'Mover a',
|
|
title: 'Mover a',
|
|
templateUrl: 'templates/sales/crm-stages.html',
|
|
templateUrl: 'templates/sales/crm-stages.html',
|
|
- buttons: [
|
|
|
|
- {
|
|
|
|
- text: 'Mover',
|
|
|
|
- type: 'button-positive',
|
|
|
|
- onTap: function (e) {
|
|
|
|
- // console.log(e);
|
|
|
|
- $scope.moveOpportunity();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- text: 'Cancelar',
|
|
|
|
- type: 'button-default',
|
|
|
|
- onTap: function (e) {
|
|
|
|
- // e.preventDefault();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- *
|
|
|
|
- */
|
|
|
|
- $scope.selectStageToMove = function (index) {
|
|
|
|
- $scope.stageToMove = $scope.stages[index];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Move opportunity to stage
|
|
* Move opportunity to stage
|
|
*/
|
|
*/
|
|
- $scope.moveOpportunity = function () {
|
|
|
|
- console.log($scope.stageToMove);
|
|
|
|
- deviceFactory.toast('Se movió la oportunidad a ' + $scope.stageToMove.name);
|
|
|
|
|
|
+ $scope.moveToStage = function (index) {
|
|
|
|
+ $scope.selectStage.close();
|
|
|
|
+
|
|
|
|
+ var opportunityToMove = $scope.groupedOpportunities[$scope.selectedIndex];
|
|
|
|
+ var indexToUpdate = $scope.opportunities.indexOf(opportunityToMove);
|
|
|
|
+ var stageToMove = $scope.stagesToMove[index];
|
|
|
|
+
|
|
|
|
+ $scope.selectedIndex = -1;
|
|
|
|
+ $scope.loading = true;
|
|
|
|
+
|
|
|
|
+ opportunitiesDataFactory.changeStage(opportunityToMove, stageToMove.remote_id, function (opportunityId) {
|
|
|
|
+ $scope.opportunities[indexToUpdate] = opportunityToMove;
|
|
|
|
+ $scope.groupOpportunities();
|
|
|
|
+
|
|
|
|
+ $scope.$apply();
|
|
|
|
+ $scope.loading = false;
|
|
|
|
+
|
|
|
|
+ deviceFactory.toast('Se movió la oportunidad a ' + $scope.stagesToMove[index].name);
|
|
|
|
+ }, function (err) {
|
|
|
|
+
|
|
|
|
+ $scope.loading = false;
|
|
|
|
+ deviceFactory.toast('No se ha podido mover la oportunidad');
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -227,7 +317,14 @@ angular.module('odoo')
|
|
deviceFactory.vibrate();
|
|
deviceFactory.vibrate();
|
|
|
|
|
|
$scope.selectedIndex = index;
|
|
$scope.selectedIndex = index;
|
|
- console.log($scope.opportunities[index]);
|
|
|
|
|
|
+
|
|
|
|
+ if (index == -1) {
|
|
|
|
+ $scope.opportunity = {};
|
|
|
|
+ } else {
|
|
|
|
+ $scope.opportunity = $scope.groupedOpportunities[index];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ console.log($scope.opportunity);
|
|
|
|
|
|
$ionicActionSheet.show({
|
|
$ionicActionSheet.show({
|
|
titleText: 'Acciones',
|
|
titleText: 'Acciones',
|
|
@@ -245,17 +342,16 @@ angular.module('odoo')
|
|
$scope.selectedIndex = -1;
|
|
$scope.selectedIndex = -1;
|
|
},
|
|
},
|
|
buttonClicked: function (index) {
|
|
buttonClicked: function (index) {
|
|
- $scope.selectedIndex = -1;
|
|
|
|
|
|
+
|
|
|
|
|
|
switch (index) {
|
|
switch (index) {
|
|
case 0:
|
|
case 0:
|
|
- $scope.show();
|
|
|
|
|
|
+ $scope.selectedIndex = -1;
|
|
|
|
+ $scope.toogleNew();
|
|
break;
|
|
break;
|
|
case 1:
|
|
case 1:
|
|
$scope.showStagesToMove();
|
|
$scope.showStagesToMove();
|
|
break;
|
|
break;
|
|
- default:
|
|
|
|
- $scope.show();
|
|
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
},
|
|
},
|