const LANGUAGE_TEST_NO_LANG = 'no_language'; const LANGUAGE_TEST_COMMON_NAME = 'no_tests'; const ENGLISH_TEST_IELTS_NAME = 'pass_ielts'; const ENGLISH_TEST_CELPIP_NAME = 'pass_celpip'; const FRENCH_TEST_TEF_NAME = 'pass_tef'; const FRENCH_TEST_TCF_NAME = 'pass_tcf'; const LANGUAGES_ITEMS_LIST = ["english", "french"]; const ENGLISH_TEST_IELTS_AVAILABLE_VALUES = { reading: ["8-9", "7-7.5", "6.5", "6", "5-5.5", "4-4.5", "3.5"], writing: ["7.5-9", "7", "6.5", "6", "5.5", "5", "4"], listening: ["8.5-9", "8", "7.5", "6-7", "5.5", "5", "4.5"], speaking: ["8.5-9", "8", "7.5", "6-7", "5.5", "5", "4.5"] }; const ENGLISH_TEST_CELPIP_AVAILABLE_VALUES = { reading: ["4", "5", "6", "7", "8", "9", "10-12"], writing: ["4", "5", "6", "7", "8", "9", "10-12"], listening: ["4", "5", "6", "7", "8", "9", "10-12"], speaking: ["4", "5", "6", "7", "8", "9", "10-12"] }; const FRENCH_TEST_TEF_AVAILABLE_VALUES = { reading: ["566-699", "533-565", "500-532", "450-499", "400-499", "350-399", "300-349"], writing: ["566-699", "533-565", "500-532", "450-499", "400-499", "350-399", "300-349"], listening: ["566-699", "533-565", "500-532", "450-499", "400-499", "350-399", "300-349"], speaking: ["566-699", "533-565", "500-532", "450-499", "400-499", "350-399", "300-349"] }; const FRENCH_TEST_TCF_AVAILABLE_VALUES = { reading: ["549-699", "524-548", "499-523", "453-498", "406-452", "375-405", "342-374"], writing: ["16-20", "14-15", "12-13", "10-11", "7-9", "6", "4-5"], listening: ["549-699", "523-548", "503-522", "458-502", "398-457", "369-397", "331-368"], speaking: ["16-20", "14-15", "12-13", "10-11", "7-9", "6", "4-5"], }; const ENGLISH_TEST_IELTS_CLB_ANALOG_VALUES = { clb4: [3.5, 4.0, 4.5, 4.0], clb5: [4.0, 5.0, 5.0, 5.0], clb6: [5.0, 5.5, 5.5, 5.5], clb7: [6.0, 6.0, 6.0, 6.0], clb8: [6.5, 6.5, 7.5, 6.5], clb9: [7.0, 7.0, 8.0, 7.0], clb10: [8.0, 7.5, 8.5, 7.5] }; const ENGLISH_TEST_CELPIP_CLB_ANALOG_VALUES = { clb4: [4, 4, 4, 4], clb5: [5, 5, 5, 5], clb6: [6, 6, 6, 6], clb7: [7, 7, 7, 7], clb8: [8, 8, 8, 8], clb9: [9, 9, 9, 9], clb10: [10, 10, 10, 10] }; const FRENCH_TEST_TEF_CLB_ANALOG_VALUES = { clb4: [121, 181, 145, 181], clb5: [151, 226, 181, 226], clb6: [181, 271, 217, 271], clb7: [207, 310, 249, 310], clb8: [233, 349, 280, 349], clb9: [248, 371, 298, 371], clb10: [263, 393, 316, 393] }; const FRENCH_TEST_TCF_CLB_ANALOG_VALUES = { clb4: [342, 4, 331, 4], clb5: [375, 6, 369, 6], clb6: [406, 7, 398, 7], clb7: [453, 10, 458, 10], clb8: [499, 12, 503, 12], clb9: [524, 14, 523, 14], clb10: [549, 16, 549, 16] }; const ENGLISH_TEST_IELTS_RANGE_VALUES = { minValue: 0, maxValue: 9, step: 0.5 }; const ENGLISH_TEST_CELPIP_RANGE_VALUES = { minValue: 0, maxValue: 12, step: 1 }; const FRENCH_TEST_TEF_RANGE_VALUES = { minValue: 0, maxValue: 415, step: 1 }; const FRENCH_TEST_TCF_RANGE_VALUES = { minValue: 0, maxValue: 699, step: 1 }; function WizardScore() { Wizard.call(this); this.nocs_manager = null; this.nocs_manager_spouse = null; this.job_offer_nocs_manager = null; this.job_offer_nocs_manager_spouse = null; // generate steps array this.steps_containers_array = this.GetStepContainersArray(); this.steps_containers_array = this.steps_containers_array.concat("user_contact_info", "user_terms_data_accuracy"); } WizardScore.prototype = Object.create(Wizard.prototype); WizardScore.prototype.constructor = WizardScore; WizardScore.prototype.SerializeAdditionalFields = function() { var result = Wizard.prototype.SerializeAdditionalFields.call(this); result = this.AddSerializedValue(result, this.serializeNocsFields(this.nocs_manager, "user_nocs")); result = this.AddSerializedValue(result, this.serializeNocsFields(this.nocs_manager_spouse, "user_nocs_spouse")); result = this.AddSerializedValue(result, this.serializeJobOfferFields(this.job_offer_nocs_manager)); result = this.AddSerializedValue(result, this.serializeJobOfferFields(this.job_offer_nocs_manager_spouse)); return result; } WizardScore.prototype.fillUserAgeControl = function(select_box_id) { var user_age_select = $("#" + select_box_id); if (user_age_select.length > 0) { const MIN_USER_AGE_NUMBER = 18; const MAX_USER_AGE_NUMBER = 100; this.AddSelectOptions(user_age_select, "Weniger als {0} Jahre".format(18), 17); for (var i = MIN_USER_AGE_NUMBER; i <= MAX_USER_AGE_NUMBER; i++) { this.AddSelectOptions(user_age_select, AgeToString(i), i); } } } WizardScore.prototype.GetStepContainersArray = function() { return []; } WizardScore.prototype.createNocManagers = function(isSpouse) { var object = this; result = new NocsManager(false); result.AddItem(); result.OnChangeNocs(function(sender) { object.InitializeInterface(); }); } WizardScore.prototype.initializeAgeControls = function() { this.fillUserAgeControl("user_age"); this.fillUserAgeControl("user_age_spouse"); } WizardScore.prototype.initializeNocsManagers = function() { this.nocs_manager = this.createNocManagers(false); this.nocs_manager_spouse = this.createNocManagers(true); } WizardScore.prototype.getWorkProfessionStartYear = function() { return new Date().getFullYear(); } WizardScore.prototype.getWorkProfessionEndYear = function() { const PROFESSION_YEARS_MAX_COUNT = 10; return (this.getWorkProfessionStartYear() - PROFESSION_YEARS_MAX_COUNT); } WizardScore.prototype.addWorkProfessionWhenYear = function(control, start_year, end_year, isSpouse) { for (var i = start_year; i >= end_year; i--) { var option_prefix = isSpouse ? "Beendet die Arbeit in " : "Beendet die Arbeit in "; this.AddSelectOptions(control, option_prefix + i + " Jahr", i); } } WizardScore.prototype.IsAjaxSubmitting = function() { return this.autoinfo_mode; } WizardScore.prototype.onSubmitFormToServerAjax = function(json_answer, save_data, show_success_message, success_callback) { $("#ajax_results").html(json_answer.results); Wizard.prototype.onSubmitFormToServerAjax.call(this, json_answer, save_data, show_success_message, success_callback); } WizardScore.prototype.fillWorkProfessionWhenPrototype = function(control, isSpouse) { if ($(control).length > 0) { var start_year = this.getWorkProfessionStartYear(); var end_year = this.getWorkProfessionEndYear(); var option_text = isSpouse ? "Momentan in Arbeit " : "Arbeiten Sie derzeit "; this.AddSelectOptions(control, option_text, 0); this.addWorkProfessionWhenYear(control, start_year, end_year, isSpouse) } } WizardScore.prototype.createJobOfferNocsManager = function(isSpouse) { const controlSelector = (isSpouse) ? "user_job_offer_profession_spouse" : "user_job_offer_profession"; if ($(controlSelector).length > 0) { var object = this; var on_change_job_offer_nocs = function (sender){ object.InitializeInterface(); }; // nocs manager for client var result = new NocsManager(isSpouse, "user_job_offer_profession"); result.clear_job_on_key_press = true; result.AddItem(); result.OnChangeNocs(on_change_job_offer_nocs); return result; } return null; } WizardScore.prototype.initializeJobOfferNocsManagers = function() { this.job_offer_nocs_manager = this.createJobOfferNocsManager(false); this.job_offer_nocs_manager_spouse = this.createJobOfferNocsManager(true); } WizardScore.prototype.initializeWorkProfessionPrototypes = function() { this.fillWorkProfessionWhenPrototype("#user_work_profession_when", false); this.fillWorkProfessionWhenPrototype("#user_work_profession_when_spouse", true); } WizardScore.prototype.shouldSerializeJobOfferManager = function(nocs_manager) { if (nocs_manager) { var result = IsButtonGroupCheckBoxOn("#has_job_offer_canada"); if (nocs_manager.is_spouse) { result = this.hasSpouse(); result &= IsButtonGroupCheckBoxOn("#has_job_offer_canada_spouse"); } result &= (nocs_manager.items_list.length > 0); return result; } return false; } WizardScore.prototype.serializeJobOfferFields = function(nocs_manager) { if (this.shouldSerializeJobOfferManager(nocs_manager)) { var offer_noc_id = nocs_manager.items_list[0].noc_id; var offer_job_id = nocs_manager.items_list[0].job_id; var spouse_prefix = (nocs_manager.is_spouse) ? "_spouse" : ""; return "user_job_offer_canada_noc_id" + spouse_prefix + "=" + offer_noc_id + "&user_job_offer_canada_job_id" + spouse_prefix + "=" + offer_job_id; } return ""; } WizardScore.prototype.shouldSerializeNocsManager = function(nocs_manager) { if (nocs_manager) { var result = IsButtonGroupCheckBoxOn("#has_work_experience"); if (nocs_manager.is_spouse) { result = this.hasSpouse(); result &= IsButtonGroupCheckBoxOn("#has_work_experience_spouse"); } return result; } return false; } WizardScore.prototype.serializeNocsFields = function(nocs_manager, title) { if (this.shouldSerializeNocsManager(nocs_manager)) return nocs_manager.SerializeNocsFields(title); return ""; } WizardScore.prototype.hasSpouse = function() { return IsButtonGroupCheckBoxOn("#user_has_spouse_group"); } WizardScore.prototype.getLanguageTest = function(elementPrefix) { return $("#" + elementPrefix + "_test option:selected").attr("data-name"); } WizardScore.prototype.isWithoutKnowledgeLanguageTest = function(elementPrefix) { return (this.getLanguageTest(elementPrefix) == LANGUAGE_TEST_NO_LANG); } WizardScore.prototype.isCommonLanguageTest = function(elementPrefix) { return (this.getLanguageTest(elementPrefix) == LANGUAGE_TEST_COMMON_NAME); } WizardScore.prototype.isIELTSEnglishTest = function(elementPrefix) { return (this.getLanguageTest(elementPrefix) == ENGLISH_TEST_IELTS_NAME); } WizardScore.prototype.isCELPIPEnglishTest = function(elementPrefix) { return (this.getLanguageTest(elementPrefix) == ENGLISH_TEST_CELPIP_NAME); } WizardScore.prototype.isTEFFrenchTest = function(elementPrefix) { return (this.getLanguageTest(elementPrefix) == FRENCH_TEST_TEF_NAME); } WizardScore.prototype.isTCFFrenchTest = function(elementPrefix) { return (this.getLanguageTest(elementPrefix) == FRENCH_TEST_TCF_NAME); } WizardScore.prototype.isExactLanguageTest = function(elementPrefix) { let result = (this.getLanguageTest(elementPrefix) != ""); result = result && (isDefined(this.getLanguageTest(elementPrefix))); result = result && (!this.isCommonLanguageTest(elementPrefix)); result = result && (!this.isWithoutKnowledgeLanguageTest(elementPrefix)); return result; } WizardScore.prototype.changeLanguageEnabledState = function(is_disabled, languageName, isSpouse) { let elementName = this.generateLanguageTestPrefix(languageName, isSpouse); $(`#${elementName}_common`).attr("disabled", is_disabled && (!this.isCommonLanguageTest(elementName))); $(`.${elementName}_exact_item`).attr("disabled", is_disabled && (!this.isExactLanguageTest(elementName))); } WizardScore.prototype.changeLanguagesEnabledState = function(is_disabled) { for (let i = 0; i < LANGUAGES_ITEMS_LIST.length; i++) { this.changeLanguageEnabledState(is_disabled, LANGUAGES_ITEMS_LIST[i], false); this.changeLanguageEnabledState(is_disabled, LANGUAGES_ITEMS_LIST[i], true); } } WizardScore.prototype.ChangeInputsEnabledState = function(is_disabled) { Wizard.prototype.ChangeInputsEnabledState.call(this, is_disabled); this.changeLanguagesEnabledState(is_disabled); $(".spouse_step").attr("disabled", is_disabled && (!this.hasSpouse())); } WizardScore.prototype.analyzeLanguageStepVisibility = function(step, languageName, isSpouse) { let elementName = this.generateLanguageTestPrefix(languageName, isSpouse); // console.log(elementName); let result = true; if (step == elementName + "_common_info") result &= (this.isCommonLanguageTest(elementName)); if (step == elementName + "_exact_info") result &= (this.isExactLanguageTest(elementName)); return result; } WizardScore.prototype.analyzeLanguagesStepVisibility = function(step) { var result = true; for (let i = 0; i < LANGUAGES_ITEMS_LIST.length; i++) { result = result && (this.analyzeLanguageStepVisibility(step, LANGUAGES_ITEMS_LIST[i], false)); result = result && (this.analyzeLanguageStepVisibility(step, LANGUAGES_ITEMS_LIST[i], true)); } return result; } WizardScore.prototype.IsStepVisible = function(step) { let result = Wizard.prototype.IsStepVisible.call(this, step); result = result && (this.analyzeLanguagesStepVisibility(step)); if ($("#" + step).hasClass("spouse_step")) result = result && (this.hasSpouse()); return result; } WizardScore.prototype.InitializeInterface = function() { Wizard.prototype.InitializeInterface.call(this); $(".spouse_step_block").changeVisibility(this.hasSpouse()); } WizardScore.prototype.agreedWithResultsAccuracy = function() { return ($("#user_terms_data_accuracy_accept").is(":checked")); } WizardScore.prototype.changeUserTermsData = function() { $("#user_terms_data_accuracy_accept_warning").changeVisibility(!this.agreedWithResultsAccuracy()); } WizardScore.prototype.generateLanguageTestPrefix = function(language, isSpouse) { var spousePrefix = (isSpouse) ? "_spouse" : ""; return `user_${language}_language${spousePrefix}`; } WizardScore.prototype.generateLanguageTestName = function(language, isSpouse) { return this.generateLanguageTestPrefix(language, isSpouse) + "_test"; } WizardScore.prototype.loadLanguageFromJSON = function(json, languageName, isSpouse) { var elementName = this.generateLanguageTestName(languageName, isSpouse); var elementPrefix = this.generateLanguageTestPrefix(languageName, isSpouse); if (json[elementName]) SetSelectBoxValue("#" + elementName, json[elementName]); if ($("#" + elementName).length > 0) { this.onChangeLanguageTestParameters("#" + elementName); this.loadLanguageTestParametersFromJSON(json, elementPrefix + "_exact", this.isExactLanguageTest(elementPrefix)); } } WizardScore.prototype.loadLanguagesFromJSON = function(json) { for (let i = 0; i < LANGUAGES_ITEMS_LIST.length; i++) { this.loadLanguageFromJSON(json, LANGUAGES_ITEMS_LIST[i], false); this.loadLanguageFromJSON(json, LANGUAGES_ITEMS_LIST[i], true); } } WizardScore.prototype.LoadControlsFromJSON = function(json) { Wizard.prototype.LoadControlsFromJSON.call(this, json); this.loadLanguagesFromJSON(json); } WizardScore.prototype.AnalyzeSendDataAvailability = function(save_data) { let result = Wizard.prototype.AnalyzeSendDataAvailability.call(this, save_data); if (result) { result = result && (this.agreedWithResultsAccuracy()); this.changeUserTermsData(); } return result; } WizardScore.prototype.LoadParameters = function() { this.autoinfo_mode = ($("#auto_info").val() == "1"); } WizardScore.prototype.getLanguageTestValueFromTitle = function(itemTitle) { let result = itemTitle; const separatorPos = result.indexOf("-"); if (separatorPos >= 0) result = result.substring(separatorPos + 1, result.length); return result; } WizardScore.prototype.updateInputMinMaxValues = function(itemPrefix, propertyName, minMaxArray) { let controlName = "#" + itemPrefix + "_exact_" + propertyName; $(controlName).attr('step', minMaxArray.step); $(controlName).attr('min', minMaxArray.minValue); $(controlName).attr('max', minMaxArray.maxValue); } WizardScore.prototype.fillLanguageTestItemsByPointsObject = function(itemPrefix, minMaxArray) { this.updateInputMinMaxValues(itemPrefix, "reading", minMaxArray); this.updateInputMinMaxValues(itemPrefix, "writing", minMaxArray); this.updateInputMinMaxValues(itemPrefix, "listening", minMaxArray); this.updateInputMinMaxValues(itemPrefix, "speaking", minMaxArray); /* for(var propertyName in pointsObject) { var itemsHTML = ""; for (let i = 0; i < pointsObject[propertyName].length; i++) { let itemValue = this.getLanguageTestValueFromTitle(pointsObject[propertyName][i]); itemsHTML += ``; } $("#" + itemPrefix + "_exact_" + propertyName).html(itemsHTML); } */ } WizardScore.prototype.setLanguageTestExactInfoParameter = function(json, itemPrefix, parameterName) { let propertyName = itemPrefix + "_" + parameterName; $("#" + propertyName).val(json[propertyName]); // SetSelectBoxValue("#" + propertyName, json[propertyName]); } WizardScore.prototype.loadLanguageTestParametersFromJSON = function(json, itemPrefix, isExactLangugeText) { if (isExactLangugeText) { this.setLanguageTestExactInfoParameter(json, itemPrefix, "reading"); this.setLanguageTestExactInfoParameter(json, itemPrefix, "writing"); this.setLanguageTestExactInfoParameter(json, itemPrefix, "listening"); this.setLanguageTestExactInfoParameter(json, itemPrefix, "speaking"); } } WizardScore.prototype.onChangeEnglishTestParameters = function(langPrefix) { if (this.isIELTSEnglishTest(langPrefix)) this.fillLanguageTestItemsByPointsObject(langPrefix, ENGLISH_TEST_IELTS_RANGE_VALUES); else if (this.isCELPIPEnglishTest(langPrefix)) this.fillLanguageTestItemsByPointsObject(langPrefix, ENGLISH_TEST_CELPIP_RANGE_VALUES); this.InitializeInterface(); } WizardScore.prototype.onChangeFrenchTestParameters = function(langPrefix) { if (this.isTEFFrenchTest(langPrefix)) this.fillLanguageTestItemsByPointsObject(langPrefix, FRENCH_TEST_TEF_RANGE_VALUES); else if (this.isTCFFrenchTest(langPrefix)) this.fillLanguageTestItemsByPointsObject(langPrefix, FRENCH_TEST_TCF_RANGE_VALUES); this.InitializeInterface(); } WizardScore.prototype.onChangeLanguageTestParameters = function(element) { var language = $(element).attr("data-language"); var langPrefix = $(element).attr("data-lang-prefix"); if (language == "english") this.onChangeEnglishTestParameters(langPrefix); else if (language == "french") this.onChangeFrenchTestParameters(langPrefix); this.InitializeInterface(); } WizardScore.prototype.shouldAddLanguageToProfile = function() { return false; } WizardScore.prototype.shouldLoadPropertyFromJSON = function(json, propertyName) { return (json[propertyName] !== "null"); } WizardScore.prototype.InitializeInternalObjects = function() { this.initializeAgeControls(); this.initializeWorkProfessionPrototypes(); this.initializeNocsManagers(); this.initializeJobOfferNocsManagers(); Wizard.prototype.InitializeInternalObjects.call(this); }