/// /// /// /// var DSR; (function (DSR) { var SaveCaseModel = /** @class */ (function () { function SaveCaseModel() { this.Files = new Array(); } return SaveCaseModel; }()); DSR.SaveCaseModel = SaveCaseModel; var TPFile = /** @class */ (function () { function TPFile(file, fileName) { this.File = file; this.FileName = fileName; } return TPFile; }()); DSR.TPFile = TPFile; //todo: consultar como vamos a manejar idiomas rtl var DSRForm = /** @class */ (function () { function DSRForm() { } DSRForm.Init = function () { DSRForm.SetDefaultDom(); DSRForm.ShowGroupingControl("#txtProviderId", false); DSRForm.ShowGroupingControl("#txtOtherRelation", false); $(".next-button").click(function () { var $currentStep = $(this).parents(".step"); var continueNext = true; $currentStep.find(".required").each(function () { if ($(this).val() === "") { $(this).addClass("error-new-design"); continueNext = false; } else { $(this).removeClass("error-new-design"); } }); //Validate contact info var controlContactInfo = $("#txtEmailAddress"); var controlContainerContactInfo = $(controlContactInfo).parents(".form-group"); if (controlContainerContactInfo && !$(controlContainerContactInfo).hasClass("tp-hide")) { if ($("#txtEmailAddress").val() === "" && $("#txtIfNoEmail").val() === "") { $("#txtEmailAddress").addClass("error-new-design"); $("#txtIfNoEmail").addClass("error-new-design"); $("#RequiredContactInfo").removeClass("tp-hide"); continueNext = false; } } if (continueNext) { $currentStep.removeClass("active"); $currentStep.next(".step").addClass("active"); } }); $("#txtEmailAddress").keydown(function () { $("#RequiredContactInfo").addClass("tp-hide"); $("#txtEmailAddress").removeClass("error-new-design"); $("#txtIfNoEmail").removeClass("error-new-design"); }); $("#txtIfNoEmail").keydown(function () { $("#RequiredContactInfo").addClass("tp-hide"); $("#txtEmailAddress").removeClass("error-new-design"); $("#txtIfNoEmail").removeClass("error-new-design"); }); $(".previous-button").click(function () { var $currentStep = $(this).parents(".step"); $currentStep.removeClass("active"); $currentStep.prev(".step").addClass("active"); }); $(".cancel-button").click(function () { //$(".step.active").removeClass("active"); //$(".step:first").addClass("active"); window.location.href = window.location.href; }); $("#chkFormFilledOn").change(function () { TP.Commons.ShowControl("#form-filled", $(this).is(":checked")); if ($(this).is(":checked")) { $(".step").first().addClass("active"); } else { $(".step").removeClass("active"); } }); $('body').on('change', 'input[type=file]', function () { var FileSize = $(this)[0].files[0].size / 1024 / 1024; // in MB if (FileSize > DSRForm.MaximumSizePerFileAllowed) { TP.Commons.AlertMessageError('Error', "Max size reached. The maximum allowed size is:" + DSRForm.MaximumSizePerFileAllowed.toString() + " MB."); $(this).parents(".form-group").find(".remove-icon").trigger("click"); return; } if (TP.Commons.ValidateExtension($(this), $("#ValidExtensions").val().split("|")) !== true) { $(this).parents(".form-group").find(".remove-icon").trigger("click"); return; } if (DSRForm.GetTotalInputFilesInDom() < DSRForm.PosibleUploadFiles) { var changedIndex = $(this).attr("data-cont"); if ($("[data-cont=" + (Number(changedIndex) + 1) + "]").length <= 0) { DSRForm.InsertNewAttachment(); } } var fileName = $(this).val().split('\\').pop(); $(this).next('.custom-file-label').addClass("selected").html(fileName); }); $("body").on("click", ".remove-icon", function () { var totalInDom = DSRForm.GetTotalInputFilesInDom(); var selected = $(this).next().find("input[type=file]").attr("data-cont"); if (totalInDom == (Number(selected) + 1)) { DSRForm.EmptyFileControl($(this).next().find("input[type=file]")); } else { DSRForm.RemoveFileControlFromDom("#Attachments" + selected); if (TP.Commons.FileInputHasFiles("Attachments" + (DSRForm.GetTotalInputFilesInDom() - 1).toString()) === true) { DSRForm.InsertNewAttachment(); } } }); //$("#sltLocatedContinent").change(function () { // let selectedCompany = $(this).val(); // let idCompanies = selectedCompany ? $(this).attr("data-idgroupcompany") : ""; // DSRForm.EmptySelect("sltLocatedCountry"); // DSRForm.EmptySelect("sltType"); // DSRForm.ShowGroupingControl("#sltRelationWithTPGroup", false); // $("#sltRelationWithTPGroup").val(""); // $("#sltRelationWithTPGroup").trigger("change"); // TP.Branches.FillSelectsFromBranches(idCompanies, selectedCompany, "sltLocatedCountry", "idBranch", "description", [new TP.AttributeValue("data-valid", "parameters")]); //}); //$("#sltLocatedCountry").change(function () { // let parameters: any = $(this).find(":selected").attr("data-valid"); // parameters = TP.Commons.IsNullOrEmpty(parameters) === true ? "" : parameters.split("|"); // let isValid: boolean = false; // let parameter = ""; // $(parameters).each(function () { // if (this.indexOf("DSR_TY") > -1) { // isValid = true; // parameter = this; // return false; // } // }); // DSRForm.EmptySelect("sltType"); // if (!isValid) { // DSRForm.ShowGroupingControl("#sltRelationWithTPGroup", false); // $("#sltRelationWithTPGroup").val(""); // $("#sltRelationWithTPGroup").trigger("change"); // TP.Commons.AlertMessageInfo('', "ATTENTION! We do not support all countries via this online tool and TP Group companies do not have sites in every global location. If you do not see the TP Group company in the list of continents/countries below, please contact your local HR instead.​"); // } else { // DSRForm.ShowGroupingControl("#sltRelationWithTPGroup", true); // TP.Branches.FillSelectsFromBranches($("#IDTYPETREE").val(), parameter, "sltType", "idBranch", "description", [new TP.AttributeValue("data-valid", "parameters")]); // } //}); $("#sltRelationWithTPGroup").change(function () { if ($(this).val() == "DSR_SU01" || $(this).val() == "DSR_SU02") { DSRForm.ShowGroupingControl("#txtProviderId", true); DSRForm.ShowGroupingControl("#txtOtherRelation", false); $("#location-help").html('Please indicate, with the highest detail possible, the precise location of your work in Teleperformance Group'); $("label[for='sltTPGroupCompany']").html('Select a Teleperformance Group Company you work/worked for' + '*'); } else { $("#location-help").html('Please indicate, with the highest detail possible, the location of your relation with Teleperformance Group'); $("label[for='sltTPGroupCompany']").html('Select a Teleperformance Group Company your data is related to' + '*'); if ($(this).val() == "DSR_SU06") { DSRForm.ShowGroupingControl("#txtProviderId", false); DSRForm.ShowGroupingControl("#txtOtherRelation", true); } else { DSRForm.ShowGroupingControl("#txtProviderId", false); DSRForm.ShowGroupingControl("#txtOtherRelation", false); } } //if ($(this).val() != "") { // DSRForm.ShowCompleteForm(true); //} else { // DSRForm.SetDefaultDom(); //} }); $("#sltTPGroupCompany").change(function () { var selectedCompany = $(this).val(); var idCompanies = selectedCompany ? $(this).attr("data-idgroupcompany") : ""; DSRForm.EmptySelect("sltContinent"); DSRForm.EmptySelect("sltCountry"); DSRForm.EmptySelect("sltState"); DSRForm.EmptySelect("sltCity"); TP.Branches.FillSelectsFromBranches(idCompanies, selectedCompany, "sltContinent", "idBranch", "description"); }); $("#sltContinent").change(function () { var selectedContinent = $(this).val(); var idCompanies = selectedContinent ? $(this).attr("data-idgroupcompany") : ""; DSRForm.EmptySelect("sltCountry"); DSRForm.EmptySelect("sltState"); DSRForm.EmptySelect("sltCity"); TP.Branches.FillSelectsFromBranches(idCompanies, selectedContinent, "sltCountry", "idBranch", "description", [new TP.AttributeValue("data-valid", "parameters")]); }); $("#sltCountry").change(function () { var selectedCountry = $(this).val(); var idCompanies = selectedCountry ? $(this).attr("data-idgroupcompany") : ""; var idToFill = (selectedCountry == "GL3_010_07") === true ? "sltState" : "sltCity"; DSRForm.EmptySelect("sltState"); DSRForm.EmptySelect("sltCity"); (selectedCountry === "GL3_010_07") ? DSRForm.ShowGroupingControl("#sltState", true) : DSRForm.ShowCompleteForm(true); TP.Branches.FillSelectsFromBranches(idCompanies, selectedCountry, idToFill, "idBranch", "description", [new TP.AttributeValue("data-valid", "parameters")]); DSRForm.SetTypeSelect(); }); $("#sltState").change(function () { var selectedState = $(this).val(); var idCompanies = selectedState ? $(this).attr("data-idgroupcompany") : ""; DSRForm.EmptySelect("sltCity"); TP.Branches.FillSelectsFromBranches(idCompanies, selectedState, "sltCity", "idBranch", "description"); DSRForm.SetTypeSelect(); }); $("#sltCity").change(function () { DSRForm.SetTypeSelect(); }); $("#SendButton").click(function () { TP.Commons.LoadingStart(); var reader = new Array(); var saveModel = DSRForm.SetModel(); var totalLoads = 0; var totalFilesAdded = DSRForm.GetTotalFilesInDom(); if (totalFilesAdded == 0) { DSRForm.SaveCase(saveModel); } else { var _loop_1 = function (i) { if (TP.Commons.FileInputHasFiles("Attachments" + i) === true) { reader[i] = new FileReader(); reader[i].addEventListener("load", function () { saveModel.Files.push(new TPFile(reader[i].result, $("[for='Attachments" + i + "']").html())); totalLoads++; if (totalFilesAdded == totalLoads) { DSRForm.SaveCase(saveModel); } }, false); reader[i].addEventListener("error", function (error) { TP.Commons.LoadingStop(); console.log('Error: ', error); }); reader[i].readAsDataURL(document.getElementById("Attachments" + i).files[0]); } }; for (var i = 0; i < totalFilesAdded; i++) { _loop_1(i); } } }); TP.Commons.LoadingStop(); }; DSRForm.SetTypeSelect = function () { var parameter = ""; var isValid = false; var parameters = $("#sltCity").find(":selected").attr("data-valid"); if (TP.Commons.IsNullOrEmpty(parameters) === true) { if ($("#sltCountry").val() === "GL3_010_07") { parameters = $("#sltState").find(":selected").attr("data-valid"); if (TP.Commons.IsNullOrEmpty(parameters) === true) { parameters = $("#sltCountry").find(":selected").attr("data-valid"); } } else { parameters = $("#sltCountry").find(":selected").attr("data-valid"); } } parameters = TP.Commons.IsNullOrEmpty(parameters) === true ? "" : parameters.split("|"); $(parameters).each(function () { if (this.indexOf("DSR_TY") > -1) { isValid = true; parameter = this; return false; } }); DSRForm.EmptySelect("sltType"); if (!isValid) { DSRForm.SetDefaultDom(); TP.Commons.AlertMessageInfo('', "ATTENTION! We do not support all countries via this online tool and TP Group companies do not have sites in every global location. If you do not see the TP Group company in the list of continents/countries below, please contact your local HR instead.​"); } else { DSRForm.ShowCompleteForm(true); TP.Branches.FillSelectsFromBranches($("#IDTYPETREE").val(), parameter, "sltType", "idBranch", "description", [new TP.AttributeValue("data-valid", "parameters")]); } }; DSRForm.SetModel = function () { var saveModel = new DSR.SaveCaseModel(); saveModel.FirstName = DSRForm.GetValueFromControlId("txtFirstName"); saveModel.LastName = DSRForm.GetValueFromControlId("txtLastName"); saveModel.RelationWithTPGroup = DSRForm.GetValueFromControlId("sltRelationWithTPGroup"); saveModel.RelationWithTPGroupText = DSRForm.GetTextFromControlId("sltRelationWithTPGroup"); saveModel.ProviderId = DSRForm.GetValueFromControlId("txtProviderId"); saveModel.TPGroupCompany = DSRForm.GetValueFromControlId("sltTPGroupCompany"); saveModel.Continent = DSRForm.GetValueFromControlId("sltContinent"); saveModel.Country = DSRForm.GetValueFromControlId("sltCountry"); saveModel.State = DSRForm.GetValueFromControlId("sltState"); saveModel.City = DSRForm.GetValueFromControlId("sltCity"); saveModel.SiteLocation = DSRForm.GetValueFromControlId("txtSiteLocation"); saveModel.SiteLocationText = DSRForm.GetTextLocation(); saveModel.EmailAddress = DSRForm.GetValueFromControlId("txtEmailAddress"); saveModel.IfNoEmail = DSRForm.GetValueFromControlId("txtIfNoEmail"); saveModel.Type = DSRForm.GetValueFromControlId("sltType"); saveModel.Description = DSRForm.GetValueFromControlId("txtDescription").replace(/\r|\n/g, "\r\n"); saveModel.OtherRelation = DSRForm.GetValueFromControlId("txtOtherRelation"); saveModel.Language = DSRForm.GetValueFromControlId("CurrentLanguageBranchId"); saveModel.LanguageCode = DSRForm.GetValueFromControlId("CurrentLanguage"); saveModel.LanguageText = $("#LanguageDropDownListButton").text(); //saveModel.InternalLocation = DSRForm.GetValueFromControlId("sltLocatedCountry"); //saveModel.InternalLocationText = DSRForm.GetTextFromControlId("sltLocatedCountry"); saveModel.IsFormFilled = $("#chkFormFilledOn").is(":checked"); saveModel.NameEmployee = DSRForm.GetValueFromControlId("txtNameOfEmployeeFillingForm"); saveModel.EmailEmployee = DSRForm.GetValueFromControlId("txtEmailOfEmployeeFillingForm"); saveModel.DateOriginalDSRRequest = $("#txtDateOfOriginalDataAccessRightsRequest").attr("data-date"); return saveModel; }; //private static GetIdLocation() { // var city = DSRForm.GetValueFromControlId("sltCity"); // var state = DSRForm.GetValueFromControlId("sltCity"); // var country = DSRForm.GetValueFromControlId("sltCountry"); // if (city != "") { // return city; // } else if (state != "") { // return state; // } else { // return country; // } //} DSRForm.GetTextLocation = function () { var text = ""; text += DSRForm.GetTextFromControlId("sltTPGroupCompany"); text += "/" + DSRForm.GetTextFromControlId("sltContinent"); text += "/" + DSRForm.GetTextFromControlId("sltCountry"); text += DSRForm.GetTextFromControlId("sltState") == "" ? "" : "/" + DSRForm.GetTextFromControlId("sltState"); text += DSRForm.GetTextFromControlId("sltCity") == "" ? "" : "/" + DSRForm.GetTextFromControlId("sltCity"); text += DSRForm.GetTextFromControlId("txtSiteLocation") == "" ? "" : "/" + DSRForm.GetTextFromControlId("txtSiteLocation"); return text; }; //todo organizar estos metodos para poder ponerlos generales //la ideae s que no usen dompurify DSRForm.GetTextFromControl = function (control) { if ($(control).get(0).tagName.toLowerCase() == "select" && DOMPurify.sanitize($(control).val()) != "") return DOMPurify.sanitize($(control).find("option:selected").text() == undefined ? "" : $(control).find("option:selected").text()); else return DSRForm.GetValueFromcontrol(control); }; DSRForm.GetTextFromControlId = function (controlId) { return DSRForm.GetTextFromControl($("#" + controlId)); }; DSRForm.GetValueFromcontrol = function (control) { return DOMPurify.sanitize($(control).val() == undefined ? "" : $(control).val()); }; DSRForm.GetValueFromControlId = function (controlId) { return DSRForm.GetValueFromcontrol($("#" + controlId)); }; DSRForm.SetDefaultDom = function () { //DSRForm.ShowGroupingControl("#txtOtherRelation", false); //DSRForm.ShowGroupingControl("#txtProviderId", false); //DSRForm.EmptySelect("sltContinent"); //DSRForm.EmptySelect("sltCountry"); DSRForm.ShowGroupingControl("#sltState", false); DSRForm.EmptySelect("sltState"); DSRForm.EmptySelect("sltCity"); DSRForm.ShowCompleteForm(false); DSRForm.RemoveAllFileInputsFromDom(); $(".step").removeClass("active"); if ($("#IsBehalfOf").val() == "True") { $("#chkFormFilledOn").prop("checked", false); } else { $(".step").first().addClass("active"); } }; DSRForm.ShowCompleteForm = function (show) { ////DSRForm.ShowGroupingControl("#sltTPGroupCompany", show); //DSRForm.ShowControl("#location-help", show); //DSRForm.ShowGroupingControl("#sltContinent", show); //DSRForm.ShowGroupingControl("#sltCountry", show); DSRForm.ShowGroupingControl("#sltCity", show); DSRForm.ShowGroupingControl("#txtSiteLocation", show); DSRForm.ShowGroupingControl("#txtEmailAddress", show); DSRForm.ShowGroupingControl("#txtIfNoEmail", show); DSRForm.ShowGroupingControl("#txtDescription", show); DSRForm.ShowGroupingControl("#sltType", show); DSRForm.ShowGroupingControl("input[type=file]", show); DSRForm.ShowGroupingControl("#SendButton", show); }; DSRForm.RemoveAllFileInputsFromDom = function () { $("input[type=file]:not(#Attachments0)").remove(); $("[for='Attachments0']").html('Select file'); }; DSRForm.ShowControl = function (selectorControl, show) { show === true ? $(selectorControl).removeClass("tp-hide") : $(selectorControl).addClass("tp-hide"); }; DSRForm.ShowGroupingControl = function (selectorControl, show, groupingClass) { var control = $(selectorControl); var controlContainer = $(control).parents("." + (groupingClass ? groupingClass : "form-group")); DSRForm.ShowControl(controlContainer, show); }; DSRForm.EmptyInputControlSelector = function (controlSelector) { var control = $(controlSelector); DSRForm.EmptyInputControl(control); }; DSRForm.EmptyInputControl = function (control) { $(control).val(""); }; DSRForm.RemoveControlFromDom = function (control) { $(control).parents(".form-group").remove(); }; DSRForm.RemoveFileControlFromDom = function (control) { DSRForm.RemoveControlFromDom(control); DSRForm.RecalculateContForFiles("form"); }; DSRForm.RecalculateContForFiles = function (container) { $(container).find("input[type=file]").each(function (ind, element) { if (ind == 0) { $(this).parents(".form-group").find(">label").html("Please attach applicable files"); } $(this).attr("data-cont", ind); $(this).attr("id", "Attachments" + ind); $(this).next().attr("for", "Attachments" + ind); }); }; DSRForm.EmptyFileControl = function (control) { DSRForm.EmptyInputControl(control); $(control).next().html('Select file'); }; DSRForm.EmptySelect = function (idSelect) { var control = $("#" + idSelect); $(control).html(""); $(control).append(""); }; DSRForm.EmptyForm = function () { $("select, input[type='text'], input[type='email'], textarea, input[type='file']").val(""); }; DSRForm.SaveCase = function (saveModel) { if (!DSRForm.FormValidation()) { TP.Commons.LoadingStop(); return false; } TP.Commons.LoadingStart(); TP.Commons.AjaxServicePromisePost(TP.Commons.GetUrlService("SaveCase"), { SaveCaseModel: saveModel }, null, TP.Commons.antiforgeryToken) .done(function (result) { TP.Commons.AlertMessageSuccess('', "According to the regulation, we will contact you within the next 30 days. Your Case ID is:" + result.JsonData); $("#message-success").html('According to the regulation, we will contact you within the next 30 days. Your Case ID is: ' + "" + result.JsonData + ""); DSRForm.EmptyForm(); DSRForm.SetDefaultDom(); $("#message-success").show(); TP.Commons.LoadingStop(); return; }) .fail(function (error) { TP.Commons.LoadingStop(); TP.Commons.AlertMessageError('Error', "Error saving case."); return; }); }; DSRForm.FormValidation = function () { var toR = true; $(".required:visible").each(function () { if (DSRForm.GetValueFromcontrol(this) == "") { TP.Commons.ValidationB4Generator(this, "error", 'This field is mandatory.'); toR = false; } else { TP.Commons.ValidationB4RemoveAll(this); } }); $('input[type="email"]:visible').each(function () { if (DSRForm.GetValueFromcontrol(this) != "") { if (!TP.Commons.fnValidateEmail(DSRForm.GetValueFromcontrol(this))) { TP.Commons.ValidationB4Generator(this, "error", "This field must be a valid email."); toR = false; } else { TP.Commons.ValidationB4RemoveAll(this); } } else { if (DSRForm.GetValueFromControlId("txtIfNoEmail") == "") { TP.Commons.ValidationB4Generator($("#txtIfNoEmail"), "error", "You must supply an email or an alternative contact information"); toR = false; } else { TP.Commons.ValidationB4RemoveAll($("#txtIfNoEmail")); } } }); return toR; }; DSRForm.GetTotalInputFilesInDom = function () { return $("input[type=file]").length; }; DSRForm.GetTotalFilesInDom = function () { var cont = 0; $("input[type=file]").each(function () { if (TP.Commons.FileInputHasFiles($(this).attr("id"))) cont++; }); return cont; }; DSRForm.InsertNewAttachment = function () { var html = DSRForm.GenerateNewAttachmentHtml("Attachments" + (DSRForm.GetTotalInputFilesInDom()), true, ''); $(html).insertBefore($("#SendButton").parents(".form-group")); }; DSRForm.GenerateNewAttachmentHtml = function (id, showLabel, labelMessage) { var html = ""; html += '
'; html += ' '; html += '
'; html += ' '; html += '
'; html += ' '; html += ' '; html += '
'; html += '
'; html += '
'; return html; }; DSRForm.PosibleUploadFiles = 5; DSRForm.MaximumSizePerFileAllowed = 20; return DSRForm; }()); DSR.DSRForm = DSRForm; })(DSR || (DSR = {})); //# sourceMappingURL=DSRForm.js.map