const ILAC_LANGUAGE_UNKNOWN = ""; const ILAC_LANGUAGE_NONE = "0"; const ILAC_LANGUAGE_A1 = "A1"; const ILAC_PRICE_TEXTBOOK_PER_WEEK = 10; const ILAC_REGISTRATION_FEE = 110; const ILAC_LANGUAGE_COURSE_PATHWAY = 'University Pathway'; const ILAC_LEARN_FROM_SOURCE_OTHER = "other"; const ILAC_LANGUAGE_COURSES = [ {value: "", "name": "Выберите значение из списка", min_lang_index: -1}, {value: "General English", "name": "Общий английский", min_lang_index: -1}, {value: "IELTS Preparation", "name": "Подготовка к сдаче IELTS", min_lang_index: 3}, {value: "University Pathway", "name": "Подготовка к поступлению в канадский вуз", min_lang_index: 4}, {value: "Cambridge English", "name": "Кембриджский английский", min_lang_index: -1}, {value: "Business English", "name": "Английский для бизнеса", min_lang_index: 4} ]; 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 = ["english_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() { return GetSelectBoxValue("#english_level"); } 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); } 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() { var select_html = ""; var language_course = this.GetLanguageCourse(); $('#language_course').find('option').remove(); var selected_langage_idx = $("#english_level")[0].selectedIndex; for (var i = 0; i < ILAC_LANGUAGE_COURSES.length; i++) { var should_add_item = true; if (ILAC_LANGUAGE_COURSES[i].min_lang_index >= 0) should_add_item = should_add_item && (selected_langage_idx >= ILAC_LANGUAGE_COURSES[i].min_lang_index); if (should_add_item) { var selected_item = (ILAC_LANGUAGE_COURSES[i].value == language_course) ? "selected" : ""; select_html += "\n"; } } $('#language_course').html(select_html); } 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.InitializeLanguageInteface = function() { $("#ilac_bad_language_message").changeVisibility(this.IsBadLanguage()); $("#ilac_good_language_message").changeVisibility(this.IsGoodLanguage()); this.FillLanguageCourses(); } ILACWizard.prototype.InitializeFlexibleSheduleInteface = function() { $("#flexible_schedule_message").changeVisibility(this.IsBadSchedule()); } 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 * ILAC_PRICE_TEXTBOOK_PER_WEEK + ILAC_REGISTRATION_FEE; message = "Общая стоимость: ${0} CAD = ${1} CAD (обучение) + ${2} CAD (учебники) + ${3} (регистрационный взнос)".format(total_price, price, weeks_count * ILAC_PRICE_TEXTBOOK_PER_WEEK, ILAC_REGISTRATION_FEE); } $("#learning_weeks_info").html(message); this.InitializeInterface(); } ILACWizard.prototype.InitializeInterface = function() { this.InitializeLanguageInteface(); 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.GetSaveButtonCaption = function() { if (this.is_ilac_additional_form) return "Подать заявку на учебу в языковой школе"; if (this.is_ilac_passport_form) return "Указать паспортные данные"; return "Подать заявку"; } ILACWizard.prototype.PrepareForm = function() { Wizard.prototype.PrepareForm.call(this); $("#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.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(); }