|
@@ -8,15 +8,15 @@ angular.module('odoo')
|
|
|
$ionicModal,
|
|
|
$ionicActionSheet,
|
|
|
$ionicFilterBar,
|
|
|
- $ionicPopup,
|
|
|
- $cordovaVibration,
|
|
|
leadsRemoteFactory,
|
|
|
leadsStorageFactory,
|
|
|
opportunitiesStorageFactory,
|
|
|
- sqlFactory
|
|
|
+ sqlFactory,
|
|
|
+ deviceFactory
|
|
|
) {
|
|
|
|
|
|
$scope.loading = false;
|
|
|
+ $scope.selectedIndex = -1;
|
|
|
$scope.leads = [];
|
|
|
$scope.lead = {};
|
|
|
$scope.conversion = {
|
|
@@ -38,23 +38,42 @@ angular.module('odoo')
|
|
|
$scope.leadToOpportunityModal = modal;
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
$scope.$on('$ionicView.enter', function () {
|
|
|
- $scope.fill();
|
|
|
+ $scope.fill(false);
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
$scope.$on('$destroy', function () {
|
|
|
$scope.leadModal.remove();
|
|
|
$scope.leadToOpportunityModal.remove();
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
$scope.$on('modal.hidden', function () {
|
|
|
$scope.lead = {};
|
|
|
});
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ $scope.$on('device.shaked', function () {
|
|
|
+ if (!$scope.leadModal.isShown()) {
|
|
|
+ $scope.fill(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- $scope.fill = function (refresh = false) {
|
|
|
+ $scope.fill = function (refresh) {
|
|
|
$scope.loading = !refresh;
|
|
|
|
|
|
leadsRemoteFactory.sync(function (leads) {
|
|
@@ -67,7 +86,7 @@ angular.module('odoo')
|
|
|
$scope.$broadcast('scroll.refreshComplete');
|
|
|
$scope.loading = false;
|
|
|
|
|
|
- $ionicPopup.alert({ title: 'No se pudo obtener las iniciativas' });
|
|
|
+ deviceFactory.toast('No se pudo obtener las iniciativas');
|
|
|
});
|
|
|
}, function (syncErr) {
|
|
|
$scope.getLeads(function () {
|
|
@@ -77,7 +96,7 @@ angular.module('odoo')
|
|
|
$scope.$broadcast('scroll.refreshComplete');
|
|
|
$scope.loading = false;
|
|
|
|
|
|
- $ionicPopup.alert({ title: 'No se pudo obtener las iniciativas' });
|
|
|
+ deviceFactory.toast('No se pudo obtener las iniciativas');
|
|
|
});
|
|
|
});
|
|
|
}
|
|
@@ -103,28 +122,39 @@ angular.module('odoo')
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- $scope.show = function (event) {
|
|
|
+ $scope.toogleNew = function () {
|
|
|
$scope.leadModal.show();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ */
|
|
|
+ $scope.toggleSearch = function () {
|
|
|
+ $scope.search = $ionicFilterBar.show({
|
|
|
+ items: $scope.leads,
|
|
|
+ update: function (filtered, text) {
|
|
|
+ $scope.leads = filtered;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
$scope.save = function () {
|
|
|
leadsStorageFactory.save($scope.lead, function (leadId) {
|
|
|
-
|
|
|
+
|
|
|
if (!$scope.lead.id) {
|
|
|
$scope.lead.id = leadId;
|
|
|
$scope.leads.push($scope.lead);
|
|
|
}
|
|
|
|
|
|
$scope.lead = {};
|
|
|
- $scope.loading = false;
|
|
|
+ $scope.leadModal.hide();
|
|
|
console.log('Lead saved');
|
|
|
-
|
|
|
}, function (error) {
|
|
|
- $ionicPopup.alert({ title: 'No se ha podido guardar la iniciativa', template: JSON.stringify(error) });
|
|
|
- console.log(JSON.stringify(error));
|
|
|
+ console.log(error);
|
|
|
+ deviceFactory.toast('No se ha podido guardar la iniciativa');
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -132,11 +162,8 @@ angular.module('odoo')
|
|
|
*
|
|
|
*/
|
|
|
$scope.delete = function () {
|
|
|
- $ionicPopup.confirm({
|
|
|
- title: 'Confirmar',
|
|
|
- template: 'Estás seguro que quieres eliminar esta iniciativa?'
|
|
|
- }).then(function (confirmation) {
|
|
|
- if (confirmation) {
|
|
|
+ deviceFactory.confirm('Estás seguro que quieres eliminar esta iniciativa?', 'Confirmar', function (index) {
|
|
|
+ if (index == 1) {
|
|
|
leadsStorageFactory.remove($scope.lead, function (affected) {
|
|
|
if (affected != 0) {
|
|
|
var index = $scope.leads.indexOf($scope.lead);
|
|
@@ -146,8 +173,8 @@ angular.module('odoo')
|
|
|
$scope.$apply();
|
|
|
}
|
|
|
}, function (error) {
|
|
|
- $ionicPopup.alert({ title: 'No se puedo eliminar la iniciativa', template: JSON.stringify(error) });
|
|
|
- console.log(JSON.stringify(error));
|
|
|
+ console.log(error);
|
|
|
+ deviceFactory.toast('No se ha podido eliminar la iniciativa');
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -158,31 +185,20 @@ angular.module('odoo')
|
|
|
*/
|
|
|
$scope.convertToOpportunity = function () {
|
|
|
opportunitiesStorageFactory.save($scope.lead, function (opportunityId) {
|
|
|
- $scope.leadToOpportunityModal.hide();
|
|
|
+ // $scope.leadToOpportunityModal.hide();
|
|
|
|
|
|
var index = $scope.leads.indexOf($scope.lead);
|
|
|
$scope.leads.splice(index, 1);
|
|
|
$scope.lead = {};
|
|
|
|
|
|
$scope.$apply();
|
|
|
+
|
|
|
+ deviceFactory.toast('Se convirtió la iniciativa');
|
|
|
}, function (saveErr) {
|
|
|
- $scope.leadToOpportunityModal.hide();
|
|
|
- $ionicPopup.alert({
|
|
|
- title: 'No se puedo convertir la iniciativa',
|
|
|
- template: JSON.stringify(saveErr)
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
+ console.log(saveErr);
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
- $scope.toggleSearch = function () {
|
|
|
- $scope.search = $ionicFilterBar.show({
|
|
|
- items: $scope.leads,
|
|
|
- update: function (filtered, text) {
|
|
|
- $scope.leads = filtered;
|
|
|
- }
|
|
|
+ // $scope.leadToOpportunityModal.hide();
|
|
|
+ deviceFactory.toast('No se pudo convertir la iniciativa');
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -190,7 +206,9 @@ angular.module('odoo')
|
|
|
*
|
|
|
*/
|
|
|
$scope.openOptions = function (index) {
|
|
|
- $cordovaVibration.vibrate(100);
|
|
|
+ deviceFactory.vibrate();
|
|
|
+
|
|
|
+ $scope.selectedIndex = index;
|
|
|
|
|
|
if (index == -1) {
|
|
|
$scope.lead = {};
|
|
@@ -198,7 +216,7 @@ angular.module('odoo')
|
|
|
$scope.lead = $scope.leads[index];
|
|
|
}
|
|
|
|
|
|
- console.log('Customer selected => ' + JSON.stringify($scope.lead));
|
|
|
+ console.log($scope.lead);
|
|
|
|
|
|
$ionicActionSheet.show({
|
|
|
titleText: 'Acciones',
|
|
@@ -213,22 +231,27 @@ angular.module('odoo')
|
|
|
destructiveText: '<i class="icon ion-trash-a assertive"></i> Eliminar',
|
|
|
cancel: function () {
|
|
|
$scope.lead = {};
|
|
|
- console.log('ActionSheet canceled');
|
|
|
+ $scope.selectedIndex = -1;
|
|
|
},
|
|
|
buttonClicked: function (index) {
|
|
|
+ $scope.selectedIndex = -1;
|
|
|
+
|
|
|
switch (index) {
|
|
|
case 0:
|
|
|
- $scope.show();
|
|
|
+ $scope.toogleNew();
|
|
|
break;
|
|
|
case 1:
|
|
|
- $scope.leadToOpportunityModal.show();
|
|
|
+ // $scope.leadToOpportunityModal.show();
|
|
|
+ $scope.convertToOpportunity();
|
|
|
break;
|
|
|
default:
|
|
|
- $scope.show();
|
|
|
+ $scope.toogleNew();
|
|
|
}
|
|
|
return true;
|
|
|
},
|
|
|
destructiveButtonClicked: function () {
|
|
|
+ $scope.selectedIndex = -1;
|
|
|
+
|
|
|
$scope.delete();
|
|
|
|
|
|
return true;
|