(function () { 'use strict'; angular.module('Forms') .config(function($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist([ // Allow same origin resource loads. 'self', // Allow loading from our assets domain. Notice the difference between * and **. 'https://www.servicetonic.com/**' ]); }) .directive('enterprise', function () { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attr, ctrl) { ctrl.$validators.enterprise = function (value) { //Si no es testCloud no validamos que el mail sea de empresa if(attr.enterprise !== 'testCloud'){ return true; } if(value.startsWith("admin")){ return false; } return !(value.includes('hotmail.') || value.includes('yahoo.') || value.includes('gmail.') || value.includes('outlook.') || value.includes('aol.') || value.includes('visionhelpdesk.') || value.includes('zendesk.') || value.includes('freshdesk.') || value.includes('yopmail.') || value.includes('up2udigital.') || value.includes('byom.') || value.includes('misena.') || value.includes('unh.') || value.includes('cecyteh.edu.mx')); }; } }; }) .controller('DynamicFormController', function ( $scope, $window, $http, $location, $translate, $formsLanguageSettings, vcRecaptchaService ) { var serverUrl = $formsLanguageSettings.url; var agreementPath = '/es/webinar/webinar-itsm-registro-gracias/'; var formId = 87; var reCaptchaId = null; this.formType = 'contact'; this.showGlobalErrors = false; this.globalErrors = { }; this.submitting = false; this.countries = []; this.contactMethods = []; this.services = []; this.formData = { acceptTerms: false, mail: '', nombre: '', apellidos: '', acceptCommercialInformation: '', language: $formsLanguageSettings.langId, serverDomain: $formsLanguageSettings.domain, idSeg: null }; if ($location.search().idSeg) { this.formData.idSeg = $location.search().idSeg; } this.language = $formsLanguageSettings.langId; this.locale = $formsLanguageSettings.locale; $scope.$watch(angular.bind(this, function () { return this.formData.mail; }), angular.bind(this, function (newValue) { if (newValue) { this.formData.dominio = this.formData.mail.split('@')[1].split('.')[0]; } })); function touchErroneousFields(form) { angular.forEach(form.$error, function (field) { angular.forEach(field, function (errorField) { if (errorField) { errorField.$setTouched(); } }); }); } function navigateToThanksPage() { var thanksPageUrl = serverUrl + agreementPath; $window.location.replace(thanksPageUrl); } this.onDoubleClick = function () { return false; } this.submitForm = angular.bind(this, function (form) { if (!form.$valid) { touchErroneousFields(form); return; } this.submitting = true; $http({ method: 'POST', url: '/backoffice/dynamic-forms/' + formId + '/submit', data: this.formData }) .then(angular.bind(this, function (response) { this.submitting = false; navigateToThanksPage(); }), angular.bind(this, function (error) { this.submitting = false; if (reCaptchaId) { vcRecaptchaService.reload(reCaptchaId); } if (error.status >= 400 && error.status < 500) { var data = error.data; if (data.errorCode) { this.showGlobalErrors = true; this.globalErrors.userHasDomain = data.errorCode === 'user_has_domain'; this.globalErrors.domainTaken = data.errorCode === 'domain_taken'; } touchErroneousFields(form); return; } navigateToThanksPage(); })); }); }); })();