(function (app) {
    app
        .controller('ListarSkyviewController', function ($scope, $http, $rootScope, SweetAlert, spsservice, $uibModal, $location, $window, $route) {

            $rootScope.menuActivo();


            $rootScope.ObtenerSkyview = function () {
                spsservice.get_type('lists/getbytitle', 'Skyview', "/Items?$select=TipoInstitucion,Carrera,Curso,Encargado,NumeroConfirmados,Title,ID,FechaVisita,NumeroPersonas,Mes,Anio,Author/Title,Editor/Title&$orderby=FechaVisita desc&$expand=Author,Editor&$top=5000").then(function (rSkyview) {

                    if (rSkyview.d.results.length > 0) {

                        $rootScope.skyview = rSkyview.d.results;
                    }
                });
            } 

            $rootScope.ObtenerSkyview();

            $scope.eliminarSkyview = function (skyviewid) {
                debugger;
                SweetAlert.swal({
                        title: "¿Está seguro(a) de eliminar la visita?",
                        text: "No debe actualizar la página hasta que el proceso haya finalizado.",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#16AB39",
                        confirmButtonText: "Si, eliminar la visita!",
                        cancelButtonText: "Cancelar",
                        closeOnConfirm: true
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            spsservice.get_type('lists/getbytitle', 'Skyview', "/Items?select=ID&$filter=ID eq  " + skyviewid).then(function (resp_sup) {
                                if (resp_sup.d.results.length > 0) {
                                    spsservice.delete_data("lists/getbytitle('Skyview')/items(" + skyviewid + ")").then(function () {
                                        $rootScope.ObtenerSkyview();
                                        SweetAlert.swal("Visita eliminada.", "", "success");
                                    })
                                }
                            });
                        }
                    })
            }

            var date = new Date();
            $scope.mesActual = $rootScope.monthNames[date.getMonth()]
            debugger;




        });
}(angular.module('spsmodule')));