var appRating = angular.module("calificacionApp", ['ui.bootstrap']); appRating.controller("calificacionController", function ($scope, $http, $timeout, $uibModal, $rootScope) { var urlBase = window.ServicesConfig.getApiUrl("public", "rating"); var urlNews = urlBase; var userData; //ANALYTICS dataLayer.push({ 'PageType': 'Homepage', }); function validate() { if ($rootScope.scoree == undefined || $scope.userRating.typeId == undefined || $scope.userRating.id == undefined || $scope.userRating.product == undefined || $scope.userRating.comments == undefined) { return false; } else { return true; } } $(document).ready(function () { $('#alertM').hide(); $('#modal-validar').bootstrapValidator({ // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later feedbackIcons: { valid: 'glyphicon glyphicon-ok', invalid: 'glyphicon glyphicon-remove', validating: 'glyphicon glyphicon-refresh' }, fields: { tipoId: { required: true, validators: { notEmpty: { message: 'Tipo de identificación requerido' } } }, nid: { //required: true, validators: { notEmpty: { message: 'Numero de identificación requerido' }, integer: { message: 'Solo se permiten numeros.' } } }, tipoSeguro: { //required: true, validators: { notEmpty: { message: 'Tipo de producto requerido' } } }, comentario: { //required: true, validators: { notEmpty: { message: 'Comentario requerido' } } } } }); }); $scope.init = function () { $('#alertM').hide(); $('#btnCerrar').hide(); $scope.btnValorarDisabled = true; $scope.userRating = ""; //$scope.getScore(); }; $scope.showErrorMsg = function (json) { console.log(json); }; $scope.getScore = function () { $http({ method: "GET", url: urlNews, headers: { "accept": "application/json;odata=verbose" }, }).then(function mySucces(response) { $scope.getScoreSuccess(response.data); }, function myError(response) { console.log(response); $scope.showErrorMsg(response.data); }); }; $scope.getScoreSuccess = function (json) { if (json && json[0].ratingAverage && json[0].ratingUsersCount) { $timeout(function () { $scope.average = json[0].ratingAverage; $scope.usersCount = json[0].ratingUsersCount; }); } }; $scope.sendScore = function () { $http({ method: "POST", data: userData, url: urlNews, headers: { "accept": "application/json;odata=verbose" }, }).then(function mySucces(response) { $('#divCampos').hide(); $('#btnCerrar').show(); document.getElementById("alertM").innerHTML = "¡Gracias!".bold() + "" + " Su valoración se registró con éxito." + "" + "
"; sendquealtrics(); console.log(); }, function myError(response) { console.log(response); $scope.showErrorMsg(response.data); //document.getElementById("alertM").className = "alert alert-danger alert-dismissable fade in"; //document.getElementById("alertM").innerHTML = "¡Error!".bold() + "" + " Ha ocurrido un Error al calificar intentelo mas tarde." + "" + ""; document.getElementById("alertM").className = "alert alert-danger alert-dismissable fade in"; document.getElementById("alertM").innerHTML = "¡Error! ".bold() + "al calificar," + " por favor intentelo mas tarde."; }); }; function sendquealtrics() { var quealtrics = "https://sura.az1.qualtrics.com/jfe/form/SV_cOSYqH13oXh1lpr?" + "Experiencia=" + $rootScope.scoree + "&TipoDocumento=" + $scope.userRating.typeId + "&Documento=" + $scope.userRating.id + "&TipoComentario=" + $scope.userRating.product + "&Comentario=" + $scope.userRating.comments; var link = quealtrics var iframe = document.createElement('iframe'); iframe.frameBorder=0; iframe.width="0px"; iframe.height="0px"; iframe.id="randomid"; iframe.setAttribute("src", link); document.getElementById("queal").appendChild(iframe); } $scope.sendRating = function () { if (validate()) { //document.getElementById("alertM").className = "alert alert-success alert-dismissable fade in"; //document.getElementById("alertM").innerHTML = "¡Gracias!".bold() + "" + " Su valoración se registró con éxito." + "" + ""; userData = { score: $rootScope.scoree, comments: $scope.userRating.comments, userName: "USER NAME RATING", product: $scope.userRating.product, serviceId: $scope.userRating.id, async: false } $scope.sendScore(); //ANALYTICS dataLayer.push({ 'nombrepageview': 'calificacionexitosa', 'event': 'pageviewvirtual', }); //sendquealtrics(); } else { document.getElementById("alertM").className = "alert alert-danger alert-dismissable fade in"; document.getElementById("alertM").innerHTML = "Todos los campos".bold() + " son obligatorios"; } $('#alertM').show(); }; $scope.hideModal = function () { $('.modal').hide(); $('.modal-backdrop').hide(); $scope.getScore() } function hideThx() { $('.modal').hide(); $('.modal-backdrop').hide(); $scope.getScore() } $scope.showModal = function (score) { if (score) { //ANALYTICS dataLayer.push({ 'nombrepageview': 'calificacionsura', 'event': 'pageviewvirtual', }); $('.modal-backdrop').show() $rootScope.scoree = score; $uibModal.open({ templateUrl: '/html/widgets/modal-validar-calificacion.html', size: 'md' }); } }; $scope.$watch('score', function () { if ($scope.score > 0) { $scope.btnValorarDisabled = false; } }); $scope.init(); });