@anthonymg94 wrote:
app.controller('programaCtrl', function( $scope, $state, $stateParams, $timeout, $rootScope, $cordovaCalendar) {
var programa = $stateParams.programa;
$scope.programa = programa;var item = { title: programa.titulo, location: programa.ubicacion, startDate: new Date(programa.fecha_inicio), endDate: new Date(programa.fecha_fin) }; console.log(item); var checkEvent = function(){ $cordovaCalendar.findEvent(item) .then(function (result) { console.log('kkjk'+result); if (result.length.toString() == '0') { $scope.programa.calendario = 'Agregar al calendario +'; } else { $scope.programa.calendario = 'Remover del calendario -'; } }, function (error) { alert('Ocurrio un problema al obtener los datos del calendario, por favor vuelve a intentar: ' + JSON.stringify(error)); }); } $scope.addEvento = function() { if($scope.programa.calendario === 'Agregar al calendario +'){ $cordovaCalendar.createEvent(item) .then(function (result) { checkEvent(); },function (error) { alert('Ocurrio un problema al agregar al calendario, por favor vuelve a intentar: ' + JSON.stringify(error)); }); }else{ $cordovaCalendar.deleteEvent(item) .then(function (result) { checkEvent(); }, function (error) { alert('Ocurrio un problema al borrar en el calendario, por favor vuelve a intentar: ' + JSON.stringify(error)); }); } } checkEvent();
})
Posts: 1
Participants: 1