const STEP_FINISHED = 1000; function ResumeWizard($json_content) { this.nocs_manager = null; this.autoshow_mode = false; this.save_validating = false; this.first_unfilled_control = null; ResumeWizard.steps_containers_array = [ "user_work_experience_info", "is_native_language_block", "english_level_block", "pages_count_block", "has_sent_resume_block", "sent_resume_info_block", "plan_sent_resume_info_block", "has_photo_block", "has_birthdate_block", "has_gender_block", "has_children_count_block", "has_job_skip_experience_block", "has_job_achievement_block", "has_key_skills_block", "has_volunteer_exp_block", "has_personal_pronoun_block", "has_personal_interest_block", "has_dismissal_reason_block", "is_public_analysis_block", "user_contact_info"]; this.Initialize($json_content); } ResumeWizard.prototype.InitializeNocsManagers = function() { var object = this; var on_change_nocs = function (sender){ object.InitializeInterface(); }; // nocs manager for client this.nocs_manager = new NocsManager(false); this.nocs_manager.can_auto_accept_job = true; this.nocs_manager.clear_job_on_key_press = true; this.nocs_manager.AddItem(); this.nocs_manager.OnChangeNocs(on_change_nocs); } ResumeWizard.prototype.AddSelectOptions = function(select_control, option_text, option_value) { var option = document.createElement("option"); option.text = option_text; option.value = option_value; $(select_control)[0].appendChild(option); } ResumeWizard.prototype.UpdateVisibility = function(control, is_visible) { if (control) { if (is_visible) $(control).show(); else $(control).hide(); } } ResumeWizard.prototype.DoShowContainer = function(step) { this.UpdateVisibility("#" + step, this.IsStepVisible(step)); } ResumeWizard.prototype.DoHideContainer = function(step) { if (this.autoshow_mode) $("#" + step).hide(); else this.UpdateVisibility("#" + step, this.IsStepVisible(step)); } ResumeWizard.prototype.ChangeControlBackgroundColor = function(selected, control) { $(control).removeClass("error-control-value"); $(control).removeClass("filled-control-value"); $(control).removeClass("unknown-control-value"); if (selected) $(control).addClass('filled-control-value'); else { if (this.save_validating) { $(control).addClass('error-control-value'); } else $(control).addClass('unknown-control-value'); } } ResumeWizard.prototype.ChangeInputControlStyle = function(current_step) { var object = this; $("select").each(function() { object.ChangeControlBackgroundColor(IsSelectBoxFilled(this), this); }); $(".btn-group-member").each(function() { object.ChangeControlBackgroundColor(IsButtonGroupSelected($(this).parent()), this); }); $("span.radio-label").each(function() { var is_filled = null; var parent = $(this).parent(); $(parent).children().each(function(index, child){ if (IsRadioBox(child)) { is_filled = IsRadioBoxFilled(child); return; } }); object.ChangeControlBackgroundColor(is_filled, this); }); $("textarea, input[type=text], input[type=tel], input[type=email]").each(function() { var is_filled = (this.value != ""); var element_id = $(this).attr('id') if ((object.save_validating) && (element_id == "user_email")) { is_filled = is_filled && AnalyzeEmailControl("#user_email", false); } object.ChangeControlBackgroundColor(is_filled, this); }); } ResumeWizard.prototype.WasResumeSent = function() { return (IsButtonGroupCheckBoxOn("#has_sent_resume_group")); } ResumeWizard.prototype.IsStepVisible = function(step) { var result = true; if (step == "sent_resume_info_block") result &= (this.WasResumeSent()); if (step == "plan_sent_resume_info_block") result &= (!this.WasResumeSent()); return result; } ResumeWizard.prototype.IsSaveAvailable = function() { var current_step = this.GetCurrentStepIndex(); return (current_step == STEP_FINISHED); } ResumeWizard.prototype.IsStepElementFilled = function(step, element) { // check is input/select really filled var result = true; if (element.tagName.toLowerCase() == "select") { result &= (IsSelectBoxFilled(element)); } if (element.tagName.toLowerCase() == "textarea") { result &= IsTextBoxFilled(element); } if (element.tagName.toLowerCase() == "input") { result &= IsInputFilled(element); var element_id = $(element).attr('id') if ((this.save_validating) && (element_id == "user_email")) { result = result && AnalyzeEmailControl("#user_email", true); } } if (IsButtonGroup(element)) { result &= IsButtonGroupSelected(element); } return result; } ResumeWizard.prototype.IsVirtualContainer = function(element) { return ($(element).hasClass("virtual-container")); } ResumeWizard.prototype.EnumerateStepElementsParent = function(step, element, check_parent) { var result = true; var object = this; var is_virtual_container = false; if (check_parent) is_virtual_container = this.IsVirtualContainer(element); var is_protype = ($(element).hasClass("prototype")); if (!is_protype) { // enumerate all nesting divs of given step $(element).children().each(function (child_div_index, child_div) { var is_hidden = $(child_div).hasClass("hidden-container"); var is_child_virtual_container = object.IsVirtualContainer(child_div); if (!is_hidden) { if (is_virtual_container) { result &= object.EnumerateStepElementsParent(step, child_div, true); } else if (is_child_virtual_container) { result &= object.EnumerateStepElementsParent(step, child_div, false); } else { result &= object.EnumerateStepElements(step, child_div); } if (!result) return; } }); } return result; } ResumeWizard.prototype.EnumerateStepElements = function(step, element) { var result = true; var object = this; $(element).children().each(function (index, child) { var dom_element = $(child).get(0); result = result && (object.IsStepElementFilled(step, dom_element)); if (!result) { if (object.first_unfilled_control == null) object.first_unfilled_control = dom_element; return; } }); return result; } ResumeWizard.prototype.IsStepFilled = function(step) { if (this.IsStepVisible(step)) { var children_containers_selector = "#" + step; return this.EnumerateStepElementsParent(step, children_containers_selector, true); } return true; } ResumeWizard.prototype.GetCurrentStepIndex = function() { this.first_unfilled_control = null; for (var i = 0; i < ResumeWizard.steps_containers_array.length; i++) { if (!this.IsStepFilled(ResumeWizard.steps_containers_array[i])) return i; } return STEP_FINISHED; } ResumeWizard.prototype.InitializeInterface = function() { var current_step = this.GetCurrentStepIndex(); var is_save_visible = (current_step == STEP_FINISHED); this.save_validating = false; this.ChangeInputControlStyle(current_step); if (this.autoshow_mode) this.UpdateVisibility($("#save_form"), is_save_visible); for (var i = 0; i < ResumeWizard.steps_containers_array.length; i++) { if (i <= current_step) { this.DoShowContainer(ResumeWizard.steps_containers_array[i]); } else { this.DoHideContainer(ResumeWizard.steps_containers_array[i]); } } } ResumeWizard.prototype.SerializeNocsFields = function(nocs_manager, title) { return nocs_manager.SerializeNocsFields(title); } ResumeWizard.prototype.AddSerializedValue = function(result, value) { if ((result != "") && (value != "")) { result += "&"; } result += value; return result; } ResumeWizard.prototype.SerializeAdditionalFields = function() { var result = ""; result = this.AddSerializedValue(result, this.SerializeNocsFields(this.nocs_manager, "user_nocs")); return result; } ResumeWizard.prototype.CheckUserNocsCommon = function(nocs_manager) { var result = true; has_work = nocs_manager.HasAnyFilledNoc(); if (has_work === false) { var message_str = "Leider müssen Sie einen Beruf aus der Dropdown-Liste auswählen, die bei der Eingabe angezeigt wird.\n\n"; message_str += "Wenn keine geeigneten Optionen verfügbar sind, versuchen Sie, die Berufsbezeichnung umzuformulieren oder ein Synonym einzugeben.\n"; alert(message_str); $("#has_resume").parent()[0].scrollIntoView({ behavior: 'smooth'}); result = false; } return result; } ResumeWizard.prototype.HasResumeFile = function() { var result = (Assigned($("#resume-file-name").html())); result = result && ($("#resume-file-name").is(":visible")); return result; } ResumeWizard.prototype.ShowErrorAndScrollToControl = function(errorText, scrollControlSelector) { alert(errorText); if ($(scrollControlSelector).length > 0) $(scrollControlSelector)[0].scrollIntoView({ behavior: 'smooth'}); } ResumeWizard.prototype.CheckResumeFileExisting = function() { var result = this.HasResumeFile(); if (!result) this.ShowErrorAndScrollToControl("Sie müssen eine Lebenslaufdatei für die weitere Analyse beifügen\n\n", "#file_resume_block"); return result; } ResumeWizard.prototype.IsResumeFileFormatSupported = function(resumeFileExt) { let result = (resumeFileExt == "docx"); result = result || (resumeFileExt == "pdf"); return result; } ResumeWizard.prototype.CheckResumeFileFormat = function() { let resumeFileName = $("#file_resume_name").val(); let resumeFileExt = resumeFileName.split('.').pop().toLowerCase(); let result = this.IsResumeFileFormatSupported(resumeFileExt); if (!result) this.ShowErrorAndScrollToControl("Das angegebene Dateiformat für den Lebenslauf ist veraltet und wird nicht mehr unterstützt. Um eine bessere Kompatibilität mit kanadischen Lebenslaufformaten zu erreichen, löschen Sie bitte die vorherige Datei und fügen Sie sie im .docx- oder .pdf-Format hinzu\n", "#file_resume_block"); return result; } ResumeWizard.prototype.CheckResumeFile = function() { let result = this.CheckResumeFileExisting(); result = result && (this.CheckResumeFileFormat()); return result; } ResumeWizard.prototype.CheckUserNocs = function() { return this.CheckUserNocsCommon(this.nocs_manager); } ResumeWizard.prototype.CheckSaveAvailability = function(save_data) { this.save_validating = true; this.ChangeInputControlStyle(); var result = this.IsSaveAvailable(); if (this.first_unfilled_control != null) { var parent = $(this.first_unfilled_control).parent(); $(parent)[0].scrollIntoView({ behavior: 'smooth'}); } if (result) result &= this.CheckUserNocs(); if (result) result &= this.CheckResumeFile(); this.save_validating = false; return result; } ResumeWizard.prototype.ChangeInputsEnabledState = function(is_disabled) { $(".prototype-item").attr("disabled", is_disabled); $("#plan_change_for_vacancy").attr("disabled", is_disabled && (this.WasResumeSent())); $("#was_interview").attr("disabled", is_disabled && (!this.WasResumeSent())); $("#vacancies_count").attr("disabled", is_disabled && (!this.WasResumeSent())); $("#was_changed_for_vacancy").attr("disabled", is_disabled && (!this.WasResumeSent())); $("#file_resume_name").attr("disabled", is_disabled && (document.getElementById('file_resume_name').value == "")); $("#file_resume_size").attr("disabled", is_disabled && (document.getElementById('file_resume_size').value == "")); $("#file_resume_data").attr("disabled", is_disabled && (document.getElementById('file_resume_data').value == "")); } ResumeWizard.prototype.SendProfileToServer = function(save_data) { if (this.CheckSaveAvailability(save_data)) { this.SendProfileToServerInternal(save_data); } } ResumeWizard.prototype.SubmitForm = function() { this.SendProfileToServer(true); } ResumeWizard.prototype.CalculateResults = function() { this.SendProfileToServer(false); } ResumeWizard.prototype.LoadControlsFromJSON = function(json) { SetButtonGroupCheckBoxValue("#has_resume", true); for (var propertyName in json) { var jquery_name = "#" + propertyName; if (IsCheckBox(jquery_name)) { if (json[propertyName] == "true") $(jquery_name).attr('checked', 'checked'); } else if (IsInputBox(jquery_name)) $(jquery_name).val(json[propertyName]); else if (IsSelectBox(jquery_name)) SetSelectBoxValue(jquery_name, json[propertyName]); } // button check boxes SetButtonGroupValue("#pages_count_group", json["pages_count"]); SetButtonGroupValue("#pages_count_group", json["pages_count"]); SetButtonGroupCheckBoxValue("#is_native_language_group", json["is_native_language"]); SetButtonGroupCheckBoxValue("#has_photo_group", json["has_photo"]); SetButtonGroupCheckBoxValue("#has_gender_group", json["has_gender"]); SetButtonGroupCheckBoxValue("#has_birthdate_group", json["has_birthdate"]); SetButtonGroupCheckBoxValue("#has_children_count_group", json["has_children_count"]); SetButtonGroupCheckBoxValue("#has_job_skip_experience_group", json["has_job_skip_experience"]); SetButtonGroupCheckBoxValue("#has_job_achievement_group", json["has_job_achievement"]); SetButtonGroupCheckBoxValue("#has_key_skills_group", json["has_key_skills"]); SetButtonGroupCheckBoxValue("#has_volunteer_exp_group", json["has_volunteer_exp"]); SetButtonGroupCheckBoxValue("#has_personal_pronoun_group", json["has_personal_pronoun"]); SetButtonGroupCheckBoxValue("#has_personal_interest_group", json["has_personal_interest"]); SetButtonGroupCheckBoxValue("#has_dismissal_reason_group", json["has_dismissal_reason"]); SetButtonGroupCheckBoxValue("#is_public_analysis_group", json["is_public_analysis"]); // check resume was sent var was_sent = (json["vacancies_count"] > 0); SetButtonGroupCheckBoxValue("#has_sent_resume_group", was_sent); if (was_sent) { SetButtonGroupValue("#vacancies_count_group", json["vacancies_count"]); SetButtonGroupCheckBoxValue("#was_interview_group", json["was_interview"]); SetButtonGroupCheckBoxValue("#was_changed_for_vacancy_group", json["was_changed_for_vacancy"]); } else { SetButtonGroupCheckBoxValue("#plan_change_for_vacancy_group", json["plan_change_for_vacancy"]); } } ResumeWizard.prototype.LoadNocsControlsFromJSON = function(json) { var has_nocs = false; if (json["user_nocs"]) { nocs_array = json["user_nocs"]; has_nocs = (nocs_array.length > 0); if (has_nocs) { for (var i = 0; i < nocs_array.length; i++) { var current_item = this.nocs_manager.current_item; current_item.SetInputValue("", nocs_array[i].job_title); current_item.ShowWorkExperience(nocs_array[i].job_title, nocs_array[i].job_id, nocs_array[i].noc_id); } } } } ResumeWizard.prototype.LoadResumeFileFromJSON = function(json) { var file_resume_name = json["file_resume_name"]; $("#resume-file-name").html(file_resume_name); if (Assigned(file_resume_name)) $("#resume-file-info").show(); if (json["file_is_admin"]) { var file_resume_url = json["file_resume_url"]; var file_resume_admin_name = json["file_resume_admin_name"]; if (json["file_resume_admin_name"]) { $("#resume-file-url").html(file_resume_admin_name); $("#resume-file-url").attr("href", file_resume_url); $("#resume-file-url-container").show(); } $("#resume-file-upload-container").hide(); } } ResumeWizard.prototype.LoadControlsFromJSONContent = function(json_content) { if (json_content) { var json = JSON.parse(json_content); this.LoadControlsFromJSON(json); this.LoadNocsControlsFromJSON(json); this.LoadResumeFileFromJSON(json); this.InitializeResumeExisting(); } } ResumeWizard.prototype.LoadParameters = function() { this.autoshow_mode = (ReadCurrentURLParam("auto_show") == "1"); } ResumeWizard.prototype.InitializeInternalObjects = function() { this.InitializeDragAndDropObjects(); this.InitializeNocsManagers(); } ResumeWizard.prototype.SendProfileToServerInternal = function(save_data) { // prototype items var form = $("#ResumeProfile"); var additional_data_fields = this.SerializeAdditionalFields(); this.ChangeInputsEnabledState(true); var post_url = form.attr("action"); var request_method = form.attr("method"); var form_data = form.serialize(); if (additional_data_fields != "") form_data += "&" + additional_data_fields; this.ChangeInputsEnabledState(false); SubmitSerializedDataToServer(post_url, request_method, form_data); } ResumeWizard.prototype.InitializeResumeExisting = function() { var is_resume_block_visible = IsButtonGroupCheckBoxOn("#has_resume"); this.UpdateVisibility("#resume_block_no_message", !is_resume_block_visible); this.UpdateVisibility("#resume_block_yes_message", is_resume_block_visible); } ResumeWizard.prototype.IsSupportedDragTarget = function(event) { var result = (event.target === $('#resume-file-drag-box').get(0)); result = result || (event.target === $('#resume-file-drag-box_p').get(0)); return result; } ResumeWizard.prototype.ProcessDragEvent = function(event) { if (this.IsSupportedDragTarget(event)) { event.preventDefault(); event.stopPropagation(); return true; } return false; } ResumeWizard.prototype.DeleteResumeAttachedFile = function() { document.getElementById('file_resume_name').value = ""; document.getElementById('file_resume_size').value = ""; document.getElementById('file_resume_data').value = ""; $("#resume-upload").val(""); $("#resume-file-name").html(""); $("#resume-file-info").hide(); } ResumeWizard.prototype.GenerateResumeFileDisplayName = function(file_name, file_size) { prefix = "Bytes" file_size_str = file_size; if (file_size_str > 1024) { file_size_str = (file_size_str / 1024).toFixed(2); prefix = "KB"; } if (file_size_str > 1024) { file_size_str = (file_size_str / 1024).toFixed(2); prefix = "MB"; } return file_name + ", " + file_size_str + " " + prefix; } ResumeWizard.prototype.UploadResumeFile = function(file) { // max file size is 10 Mb const MAX_FILE_SIZE = 10 * 1024 * 1024; if (file.size == 0) { alert("Datei kann nicht leer sein"); } else if (file.size > MAX_FILE_SIZE) { alert("Die Dateigröße darf 10 MB nicht überschreiten."); } else { document.getElementById('file_resume_name').value = file.name; document.getElementById('file_resume_size').value = file.size; $("#resume-file-info").show(); $("#resume-file-name").html(this.GenerateResumeFileDisplayName(file.name, file.size)); reader = new FileReader(); reader.onload = function(event) { document.getElementById('file_resume_data').value = event.target.result; } reader.readAsDataURL(file); } } ResumeWizard.prototype.SelectResumeFile = function() { var file = $("#resume-upload").get(0).files[0]; console.log(file); this.UploadResumeFile(file); } ResumeWizard.prototype.InitializeDragAndDropObjects = function() { var object = this; $(document).on('drag dragstart', function(e) { object.ProcessDragEvent(e); }); $(document).on('dragover dragenter', function(e) { if (object.ProcessDragEvent(e)) $('#resume-file-drag-box').addClass('is-dragover'); }); $(document).on('dragleave dragend', function(e) { if (object.ProcessDragEvent(e)) { $('#resume-file-drag-box').removeClass('is-dragover'); } }); $(document).on('drop', function(e) { if (object.ProcessDragEvent(e)) { $('#resume-file-drag-box').removeClass('is-dragover'); var droppedFiles = e.originalEvent.dataTransfer.files; let droppedFileExt = droppedFiles[0].name.split('.').pop().toLowerCase(); if (object.IsResumeFileFormatSupported(droppedFileExt)) object.UploadResumeFile(droppedFiles[0]); else object.ShowErrorAndScrollToControl("Sie versuchen, einen Lebenslauf in einem nicht unterstützten Dateiformat hinzuzufügen. Für eine detailliertere Lebenslaufanalyse fügen Sie bitte Ihren Lebenslauf im .docx- oder .pdf-Format hinzu\n", "#file_resume_block"); } }); } ResumeWizard.prototype.Initialize = function(json_content) { this.LoadParameters(); this.InitializeInternalObjects(); this.LoadControlsFromJSONContent(json_content); this.InitializeInterface(); }