const ILAC_LANGUAGE_UNKNOWN = ""; const ILAC_LANGUAGE_NONE = "0"; const ILAC_LANGUAGE_A1 = "A1"; const ILAC_LANGUAGE_COURSE_PATHWAY_ID = 6; const ILAC_LEARN_FROM_SOURCE_OTHER = "other"; function ILACWizard() { Wizard.call(this); this.ilac_pathway_analyze_date = true; this.passport_fields_can_be_empty = false; this.additional_fields_can_be_empty = false; this.InitializeILACLearningDates(); this.is_ilac_passport_form = ($("#is_ilac_passport_info").val() == "1"); this.is_ilac_additional_form = ($("#is_ilac_additional_info").val() == "1"); this.steps_containers_array = ["ilac_profile_language", "ilac_program_type_block", "ilac_language_level_block", "learning_weeks_block", "language_slot_block", "language_course_block", "start_learning_date_block", "schedule_message_block", "learn_from_source_block", "user_contact_info"]; if (this.is_ilac_additional_form) this.steps_containers_array = this.GetAdditionalInfoStepsArray(); else if (this.is_ilac_passport_form) this.steps_containers_array = this.GetPassportInfoStepsArray(); } ILACWizard.prototype = Object.create(Wizard.prototype); ILACWizard.prototype.constructor = ILACWizard; ILACWizard.prototype.GetLanguageLevel = function() { let result = ILAC_LANGUAGE_UNKNOWN; if (this.isProgramTypeSelected()) result = GetSelectBoxValue("#ilac_language_level"); return result; } ILACWizard.prototype.GetLearnFromSource = function() { return GetSelectBoxValue("#learn_from_source"); } ILACWizard.prototype.GetLanguageCourse = function() { return GetSelectBoxValue("#language_course"); } ILACWizard.prototype.IsPathwayLanguageCourse = function() { return (this.GetLanguageCourse() == ILAC_LANGUAGE_COURSE_PATHWAY_ID); } ILACWizard.prototype.IsOtherLearnFromSource = function() { return (this.GetLearnFromSource() == ILAC_LEARN_FROM_SOURCE_OTHER); } ILACWizard.prototype.IsBadSchedule = function() { var result = IsButtonGroupSelected("#is_flexible_schedule_group"); result = result && (IsButtonGroupCheckBoxOff("#is_flexible_schedule_group")); return result; } ILACWizard.prototype.ElementCanBeSavedOnlyEnglish = function(element) { var result = true; if ($(element).hasClass("only-english")) { result = CheckEnglishOnlyText($(element).attr("value")); if (!result) this.error_message = "Значение должно быть задано на английском языке"; } return result; } ILACWizard.prototype.ElementCanBeSaved = function(element) { var result = Wizard.prototype.ElementCanBeSaved.call(this, element); if (this.is_ilac_additional_form) { result = result && (this.ElementCanBeSavedAdditionalInfo(element)); result = result || (this.additional_fields_can_be_empty); } if (this.is_ilac_passport_form) result = result || (this.passport_fields_can_be_empty); result = result && this.ElementCanBeSavedOnlyEnglish(element); return result; } ILACWizard.prototype.AreNecessaryFieldsAccepted = function() { var result = $("#accept_with_agent").is(':checked'); result = result && ($("#accept_with_personal_info").is(':checked')); return result; } ILACWizard.prototype.AnalyzeNecessaryAcceptedFields = function() { var result = this.AreNecessaryFieldsAccepted(); $("#necessary_field_error_message").changeVisibility(!result); return result; } ILACWizard.prototype.AnalyzeSendDataAvailability = function(save_data) { $("#necessary_field_error_message").changeVisibility(false); var result = Wizard.prototype.AnalyzeSendDataAvailability.call(this, save_data); if (this.is_ilac_additional_form) result = result && (this.AnalyzeNecessaryAcceptedFields()); return result; } ILACWizard.prototype.IsBadLanguage = function() { var language_level = this.GetLanguageLevel(); var result = (language_level == ILAC_LANGUAGE_NONE); result = result || (language_level == ILAC_LANGUAGE_A1); return result; } ILACWizard.prototype.fillLanguageCourses = function() { this.fillLanguageCoursesElement('#language_course', this.getProgramType(), true, $("#ilac_language_level")[0].selectedIndex); } ILACWizard.prototype.IsGoodLanguage = function() { var result = (this.GetLanguageLevel() != ILAC_LANGUAGE_UNKNOWN); result = result && (!this.IsBadLanguage()); return result; } ILACWizard.prototype.InitializeLearnFromSourceInterface = function() { $("#learn_from_source_other_block").changeVisibility(this.IsOtherLearnFromSource()); (this.IsOtherLearnFromSource()) ? $("#learn_from_source_other_block").removeClass("hidden-container") : $("#learn_from_source_other_block").addClass("hidden-container"); } ILACWizard.prototype.IsStepVisible = function(step) { let result = Wizard.prototype.IsStepVisible.call(this, step); if (step == "ilac_language_level_block") result = result && (this.isProgramTypeSelected()); return result; } ILACWizard.prototype.GetSelectedRequestLanguage = function() { return GetButtonGroupValue("#ilac_request_language_group"); } ILACWizard.prototype.InitializeLanguageInterface = function() { $("#ilac_bad_language_message").changeVisibility(this.IsBadLanguage()); $("#ilac_good_language_message").changeVisibility(this.IsGoodLanguage()); $("#ilac_program_type_container").changeVisibility(this.GetSelectedRequestLanguage() != ""); this.fillLanguageCourses(); } ILACWizard.prototype.InitializeFlexibleSheduleInteface = function() { $("#flexible_schedule_message").changeVisibility(this.IsBadSchedule()); } ILACWizard.prototype.getRegistationFee = function() { return VarAsInt($("#registation_fee").val()); } ILACWizard.prototype.getPriceTextbooks = function() { return VarAsInt($("#price_textbooks").val()); } ILACWizard.prototype.getPriceCurrency = function() { return this.getCurrencyForProgramType(this.getProgramType()); } ILACWizard.prototype.ChangeLearningCost = function() { var weeks_count = $("#learning_weeks option:selected").val(); var price = $("#learning_weeks option:selected").data('price'); var message = "* Обратите внимание, что чем дольше срок обучения, тем дешевле будет стоимость недели обучения!"; if (price > 0) { var total_price = price + weeks_count * this.getPriceTextbooks() + this.getRegistationFee(); message = "Общая стоимость: ${0} CAD = ${1} CAD (обучение) + ${2} CAD (учебники) + ${3} CAD (регистрационный взнос)".format(total_price, price, weeks_count * this.getPriceTextbooks(), this.getRegistationFee()); message = message.replaceAll('CAD', this.getPriceCurrency()); } $("#learning_weeks_info").html(message); this.InitializeInterface(); } ILACWizard.prototype.InitializeInterface = function() { this.InitializeLanguageInterface(); this.InitializePassportInfoInterface(); this.InitializeAdditionalInfoInterface(); this.InitializeLearnFromSourceInterface(); Wizard.prototype.InitializeInterface.call(this); this.InitializeFlexibleSheduleInteface(); } ILACWizard.prototype.IsAjaxSubmitting = function() { return false; } ILACWizard.prototype.LoadControlForLearnFromSource = function() { if (Assigned(this.GetLearnFromSource())) $("#learn_from_source_other").val(""); else if ($("#learn_from_source_other").val() != "") SetSelectBoxValue("#learn_from_source", ILAC_LEARN_FROM_SOURCE_OTHER); } ILACWizard.prototype.LoadControlsFromJSON = function(json) { Wizard.prototype.LoadControlsFromJSON.call(this, json); this.LoadControlForLearnFromSource(); this.LoadControlsFromJSONAdditionalInformation(json); this.LoadControlsFromJSONPassportInformation(json); } ILACWizard.prototype.IsBaseInfo = function() { var result = (!this.is_ilac_additional_form); result = result && (!this.is_ilac_passport_form); return result; } ILACWizard.prototype.getProgramType = function() { return GetSelectBoxValue("#ilac_program_type"); } ILACWizard.prototype.isPartTime = function() { return this.isPartTimeProgramType(this.getProgramType()); } ILACWizard.prototype.isProgramTypeSelected = function() { return (this.getProgramType() != ILAC_PROGRAM_TYPE_UNKNOWN); } ILACWizard.prototype.GetSaveButtonCaption = function() { if (this.is_ilac_additional_form) return "Подать заявку на учебу в языковой школе"; if (this.is_ilac_passport_form) return "Указать паспортные данные"; return "Подать заявку"; } ILACWizard.prototype.fillSelectElementFromURLParam = function(urlParamName, elementID) { let urlParamValue = ReadCurrentURLParam(urlParamName).toUpperCase(); if ((urlParamValue != "") && ($(`#${elementID} option[value="${urlParamValue}"]`).length > 0)) { SetSelectBoxValue(`#${elementID}`, urlParamValue); this.InitializeInterface(); } } ILACWizard.prototype.fillElementsFromURLParams = function() { this.fillSelectElementFromURLParam("program_type", "ilac_program_type"); this.changeILACProgramType(); this.fillSelectElementFromURLParam("language_level", "ilac_language_level"); this.fillSelectElementFromURLParam("weeks", "learning_weeks"); this.fillSelectElementFromURLParam("language_course", "language_course"); } ILACWizard.prototype.PrepareForm = function() { Wizard.prototype.PrepareForm.call(this); this.fillProgramTypes("#ilac_program_type", true); this.changeILACProgramType(); this.fillElementsFromURLParams(); $("#ilac_profile_base_info").changeVisibility(this.IsBaseInfo()); $("#ilac_profile_passport_info").changeVisibility(this.is_ilac_passport_form); $("#ilac_profile_additional_info").changeVisibility(this.is_ilac_additional_form); $(".save_form_label").html(this.GetSaveButtonCaption()); } ILACWizard.prototype.SerializeAdditionalFields = function() { var result = Wizard.prototype.SerializeAdditionalFields.call(this); result = this.AddSerializedValue(result, this.SerializeFilesList(["#ilac-form-passport"])); return result; } ILACWizard.prototype.ChangeLanguageCourseParameters = function() { this.DoOnChangeLanguageCourse("#start_learning_date", this.IsPathwayLanguageCourse()); } ILACWizard.prototype.changeILACProgramType = function() { this.fillSlotsListByProgramType("#language_slot", this.getProgramType()); this.fillWeeksPricesListByProgramType("#learning_weeks", this.getProgramType()); this.fillBookPricesByProgramType("#price_textbooks", this.getProgramType()); this.fillRegistrationFeesByProgramType("#registation_fee", this.getProgramType()); this.fillTimeslotsImageByProgramType("#timeslot_image_url", this.getProgramType()); this.fillCoursesImageByProgramType("#language_course_image_url", this.getProgramType()); this.ChangeLearningCost(); this.fillLanguageCourses(); this.InitializeInterface(); } const ILAC_DEFAULT_CURRENCY = "CAD"; const ILAC_PROGRAM_TYPE_UNKNOWN = ""; const ILAC_PROGRAM_TYPE_PART_TIME_4 = 5; const ILAC_PROGRAM_TYPE_PART_TIME_2_MONDAY = 6; const ILAC_PROGRAM_TYPE_PART_TIME_2_TUESDAY = 7; const ILAC_LANGUAGE_COURSES = [{value: '', 'name': 'Выберите значение из списка', min_lang_index: -1, supportsPartTime: true}, {value: '8', 'name': 'Общий немецкий', min_lang_index: -1, supportsPartTime: true}]; const ILAC_PROGRAM_TYPES_ARR = [{program_type_id: 8, name: '5 дней в неделю (full-time)'}]; const ILAC_WEEKS_PRICES_ARR = [{program_type_id: 8, prices: [{price: 200, weeks: 2, caption: '2 недели - $200 EUR / ~$220 USD'}, {price: 400, weeks: 4, caption: '4 недели - $400 EUR / ~$435 USD'}, {price: 600, weeks: 6, caption: '6 недель - $600 EUR / ~$650 USD'}, {price: 800, weeks: 8, caption: '8 недель - $800 EUR / ~$865 USD'}, {price: 1200, weeks: 12, caption: '12 недель - $1200 EUR / ~$1300 USD'}, {price: 1600, weeks: 16, caption: '16 недель - $1600 EUR / ~$1730 USD'}, {price: 2400, weeks: 24, caption: '24 недели - $2400 EUR / ~$2600 USD'} ]}]; const ILAC_PROGRAM_TYPE_SLOTS_ARR = [{program_type_id: 8, slots: [{slot_id: 18, name: 'Slot 1'} ]}]; const ILAC_TIME_SLOTS_IMAGES_ARR = [{program_type_id: 8, image_url: 'https://immigrant.today/images/2024-03-10-230759-0b3cbe4d.jpg'}]; const ILAC_COURSES_IMAGES_ARR = [{program_type_id: 8, image_url: 'https://immigrant.today/img/ilac_course_de.png'}]; const ILAC_BOOK_PRICES_ARR = [{program_type_id: 8, value: 110}]; const ILAC_PRICES_CURRENCY_ARR = [{program_type_id: 8, value: 'EUR'}]; const ILAC_REGISTRATION_FEES_ARR = [{program_type_id: 8, value: 10}]; ILACWizard.prototype.enumerateProgramTypeArray = function(array, programType, enumerateCallback) { for (let i = 0; i < array.length; i++) { if (array[i].program_type_id == programType) enumerateCallback(array[i]); } } ILACWizard.prototype.isPartTimeProgramType = function(programType) { let result = (programType == ILAC_PROGRAM_TYPE_PART_TIME_4); result = result || (programType == ILAC_PROGRAM_TYPE_PART_TIME_2_MONDAY); result = result || (programType == ILAC_PROGRAM_TYPE_PART_TIME_2_TUESDAY); return result; } ILACWizard.prototype.fillLanguageCoursesElement = function(jQuerySelector, programType, checkLanguageLevel, languageLevel) { var selectHTML = ""; var languageCourse = GetSelectBoxValue(jQuerySelector); $(jQuerySelector).find('option').remove(); for (var i = 0; i < ILAC_LANGUAGE_COURSES.length; i++) { var shouldAddItem = true; if (this.isPartTimeProgramType(programType)) shouldAddItem = shouldAddItem && (ILAC_LANGUAGE_COURSES[i].supportsPartTime); if ((checkLanguageLevel) && (ILAC_LANGUAGE_COURSES[i].min_lang_index >= 0)) { shouldAddItem = shouldAddItem && (languageLevel >= ILAC_LANGUAGE_COURSES[i].min_lang_index); } if (shouldAddItem) { var selectedItemHTML = (ILAC_LANGUAGE_COURSES[i].value == languageCourse) ? "selected" : ""; selectHTML += "\n"; } } $(jQuerySelector).html(selectHTML); } ILACWizard.prototype.fillSlotsListByProgramType = function(jQuerySelector, programType) { $(jQuerySelector).find('option').remove(); selectHTML = "\n"; this.enumerateProgramTypeArray(ILAC_PROGRAM_TYPE_SLOTS_ARR, programType, function(item) { for (let i = 0; i < item.slots.length; i++) selectHTML += "\n"; }); $(jQuerySelector).html(selectHTML); } ILACWizard.prototype.fillProgramTypes = function(jQuerySelector, autoSelectIfSingleProgram, hideIfSingleProgram) { $(jQuerySelector).find('option').remove(); let selectHTML = "\n"; for (let i = 0; i < ILAC_PROGRAM_TYPES_ARR.length; i++) { let isSelected = ((i == 0) && (ILAC_PROGRAM_TYPES_ARR.length == 1) && (autoSelectIfSingleProgram)); let isSelectedHTML = (isSelected) ? "selected" : ""; selectHTML += "\n"; } $(jQuerySelector).html(selectHTML); } ILACWizard.prototype.fillLanguageCoursesListByProgramType = function(jQuerySelector, programType) { $(jQuerySelector).find('option').remove(); selectHTML = "\n"; this.enumerateProgramTypeArray(ILAC_LANGUAGE_COURSES, programType, function(item) { selectHTML += "\n"; }); $(jQuerySelector).html(selectHTML); } ILACWizard.prototype.fillWeeksPricesListByProgramType = function(jQuerySelector, programType) { $(jQuerySelector).find('option').remove(); select_html = "\n"; this.enumerateProgramTypeArray(ILAC_WEEKS_PRICES_ARR, programType, function(item) { for (let i = 0; i < item.prices.length; i++) select_html += "\n"; }); $(jQuerySelector).html(select_html); } ILACWizard.prototype.fillTimeslotsImageByProgramType = function(jQuerySelector, programType) { this.enumerateProgramTypeArray(ILAC_TIME_SLOTS_IMAGES_ARR, programType, function(item) { $(jQuerySelector).attr("src", item.image_url); }); } ILACWizard.prototype.fillCoursesImageByProgramType = function(jQuerySelector, programType) { this.enumerateProgramTypeArray(ILAC_COURSES_IMAGES_ARR, programType, function(item) { $(jQuerySelector).attr("src", item.image_url); }); } ILACWizard.prototype.fillBookPricesByProgramType = function(jQuerySelector, programType) { this.enumerateProgramTypeArray(ILAC_BOOK_PRICES_ARR, programType, function(item) { $(jQuerySelector).val(item.value); }); } ILACWizard.prototype.fillPricesCurrencyByProgramType = function(jQuerySelector, programType) { this.enumerateProgramTypeArray(ILAC_PRICES_CURRENCY_ARR, programType, function(item) { SetSelectBoxValue(jQuerySelector, item.value); }); } ILACWizard.prototype.fillRegistrationFeesByProgramType = function(jQuerySelector, programType) { this.enumerateProgramTypeArray(ILAC_REGISTRATION_FEES_ARR, programType, function(item) { $(jQuerySelector).val(item.value); }); } ILACWizard.prototype.getCurrencyForProgramType = function(programType) { for (let i = 0; i < ILAC_PRICES_CURRENCY_ARR.length; i++) { if (ILAC_PRICES_CURRENCY_ARR[i].program_type_id == programType) return ILAC_PRICES_CURRENCY_ARR[i].value; } return ILAC_DEFAULT_CURRENCY; } ILACWizard.prototype.GetAdditionalInfoStepsArray = function() { return ["user_main_info_block", "user_passport_main_info_block", "user_address_info_block", "user_emergency_contact_info_block", "user_in_canada_info_block", "user_college_canada_info_block", "learning_device_block", "user_additional_question_block", "user_accept_block"]; } ILACWizard.prototype.GetDeviceInfo = function() { return GetSelectBoxValue("#learning_device"); } ILACWizard.prototype.ShouldAskAdditionalQuestion = function() { return (IsButtonGroupCheckBoxOn("#should_ask_additional_question_group")); } ILACWizard.prototype.InitializeAskQuestionInterface = function() { (this.ShouldAskAdditionalQuestion()) ? $("#additional_question_block").removeClass("hidden-container") : $("#additional_question_block").addClass("hidden-container"); $("#additional_question_block").changeVisibility(this.ShouldAskAdditionalQuestion()); $("#additional_question").prop("disabled", !this.ShouldAskAdditionalQuestion()); } ILACWizard.prototype.LoadControlsFromJSONAdditionalInformation = function(json) { this.user_phone = this.GetCorrectPhone(json.user_phone); } ILACWizard.prototype.GetCorrectPhone = function(phone) { phone = phone.replace("+", ""); phone = phone.trim(); return phone; } ILACWizard.prototype.IsSamePhoneAsUserPhone = function(phone) { return (this.user_phone == this.GetCorrectPhone(phone)); } ILACWizard.prototype.ElementCanBeSavedAdditionalInfo = function(element) { if (element.id == "emergency_phone") { return this.AnalyzeCondition((!this.IsSamePhoneAsUserPhone($(element).val())), "Телефон для экстренных случаев должен принадлежать другому человеку"); } return true; } ILACWizard.prototype.InitializeAdditionalInfoInterface = function() { this.additional_fields_can_be_empty = false; this.InitializeAskQuestionInterface(); } ILACWizard.prototype.GetPassportInfoStepsArray = function() { return ["user_passport_info_block"]; } ILACWizard.prototype.LoadControlsFromJSONPassportInformation = function(json) { // do nothing } ILACWizard.prototype.InitializePassportInfoInterface = function() { this.passport_fields_can_be_empty = false; } const MIN_DAYS_BETWEEN_AVAILABLE_DAY = 5; ILACWizard.prototype.InitializeILACLearningDates = function() { this.ilac_pathway_analyze_date = true; this.ilac_dates_holidays = ['2022-12-26', '2022-12-27', '2023-01-02', '2023-02-20', '2023-05-22', '2023-07-03', '2023-08-07', '2023-09-04', '2023-01-02', '2023-02-20', '2023-04-07', '2023-05-22', '2023-07-03', '2023-08-07', '2023-09-04', '2023-10-09', '2023-12-25', '2024-01-01', '2024-02-19', '2024-03-29', '2024-05-20', '2024-07-01', '2024-08-05', '2024-09-02', '2024-09-30', '2024-10-14', '2024-11-11', '2024-12-25', '2024-12-26']; this.ilac_pathway_start_dates = ['2024-01-02']; // this.ilac_pathway_start_dates = ["2022-01-03"]; // this.ilac_dates_holidays = ['2022-12-05']; } ILACWizard.prototype.InitializeDatePickerControls = function(is_pathway_callback) { var object = this; $j(".datepicker-ilac").datepicker({ dateFormat: "dd.mm.yy", changeMonth: true, changeYear: true, firstDay: 1, beforeShowDay: function(date) { return [object.IsILACLearningStartDataAvailable(date, is_pathway_callback(this)), ""]; } }); } ILACWizard.prototype.IsILACHolidayDate = function(date) { for (var i = 0; i < this.ilac_dates_holidays.length; i++) { var holiday_date_from = new Date(this.ilac_dates_holidays[i] + "T00:00:00"); var holiday_date_to = new Date(this.ilac_dates_holidays[i] + "T23:59:59"); if (InRange(date, holiday_date_from, holiday_date_to)) return true; } return false; } ILACWizard.prototype.IsILACAllPreviousHolidaysToMonday = function(date) { date = IncrementDays(date, -1); while (this.IsILACHolidayDate(date)) { date = IncrementDays(date, -1); if (date.getDay() == 0) return (!this.IsILACHolidayDate(date)); } return false; } ILACWizard.prototype.AnalyzeILACDateForPathwayCourse = function(date, is_pathway) { if (is_pathway) { var year = date.getFullYear(); var pathway_start_date = ""; for (var i = 0; i < this.ilac_pathway_start_dates.length; i++) { if (this.ilac_pathway_start_dates[i].indexOf(year) === 0) { pathway_start_date = new Date(this.ilac_pathway_start_dates[i]); break; } } // analyze pathway start date if (!Assigned(pathway_start_date)) pathway_start_date = new Date(year + "-01-01"); var result = (DaysBetween(pathway_start_date, date) >= 0); result = result && ((WeeksBetween(pathway_start_date, date) % 2) == 0); return result; } return true; } ILACWizard.prototype.IsILACLearningStartDataAvailable = function(date, is_pathway) { var result = (DaysBetween(new Date(), date) >= MIN_DAYS_BETWEEN_AVAILABLE_DAY); if (this.ilac_pathway_analyze_date) { result = result && (!this.IsILACHolidayDate(date)); if (result) { result = (date.getDay() == 1); result = result || (this.IsILACAllPreviousHolidaysToMonday(date)); // analyze ILAC Pathway course result = result && (this.AnalyzeILACDateForPathwayCourse(date, is_pathway)); } } else result = result && (date.getDay() == 1); return result; } ILACWizard.prototype.SelectFirstILACAvailableLearningStartDate = function(is_pathway) { var result = new Date(); while (!this.IsILACLearningStartDataAvailable(result, is_pathway)) result.setDate(result.getDate() + 1); return result; } ILACWizard.prototype.DoOnChangeLanguageCourse = function(date_control, is_pathway) { if (!this.IsILACLearningStartDataAvailable($j(date_control).datepicker("getDate"), is_pathway)) $j(date_control).datepicker("setDate", this.SelectFirstILACAvailableLearningStartDate(is_pathway)); this.InitializeInterface(); }