const STEP_FINISHED = 1000;
function ChancesWizard($json_content)
{
// console.log($json_content);
this.autoshow_mode = false;
this.nocs_manager = null;
this.nocs_manager_spouse = null;
this.relatives_manager = null;
this.save_validating = false;
this.first_unfilled_control = null;
this.has_opened_programs_or_scores = false;
this.job_offer_nocs_manager = null;
this.job_offer_nocs_manager_spouse = null;
ChancesWizard.steps_containers_array = ["user_reason_info",
"user_base_info", "user_language_info",
"user_has_work_experience_info", "user_work_experience_info",
"user_has_school_canada_info", "user_school_canada_info",
"user_has_canada_job_offer_info", "user_job_offer_canada_info",
"user_partner_info",
"user_base_info_spouse", "user_language_info_spouse",
"user_has_work_experience_info_spouse", "user_work_experience_info_spouse",
"user_has_school_canada_info_spouse", "user_school_canada_info_spouse",
"user_has_canada_job_offer_info_spouse", "user_job_offer_canada_info_spouse",
"user_has_children_info", "user_children_info",
"user_has_relatives_info", "user_relatives_info",
"user_finance_info", "user_additional_info",
"user_has_comment_info", "user_comment_info", "user_interest_info", "user_interest_info_other_countries",
"user_interest_info_visa", "user_contact_block_info",
"user_contact_info"];
this.Initialize($json_content);
}
ChancesWizard.prototype.CreateJobOfferNocsManager = function(is_spouse)
{
var object = this;
var on_change_job_offer_nocs = function (sender){
object.InitializeInterface();
};
// nocs manager for client
var result = new NocsManager(is_spouse, "user_job_offer_profession");
result.clear_job_on_key_press = true;
result.AddItem();
result.OnChangeNocs(on_change_job_offer_nocs);
return result;
}
ChancesWizard.prototype.InitializeJobOfferNocsManagers = function()
{
this.job_offer_nocs_manager = this.CreateJobOfferNocsManager(false);
this.job_offer_nocs_manager_spouse = this.CreateJobOfferNocsManager(true);
}
ChancesWizard.prototype.ShouldSerializeJobOfferManager = function(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;
}
ChancesWizard.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 "";
}
ChancesWizard.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.AddItem();
this.nocs_manager.OnChangeNocs(on_change_nocs);
// nocs manager for client spouse
this.nocs_manager_spouse = new NocsManager(true);
this.nocs_manager_spouse.AddItem();
this.nocs_manager_spouse.OnChangeNocs(on_change_nocs);
}
ChancesWizard.prototype.InitializeRelativesManager = function()
{
var object = this;
var on_change_relatives = function (sender){
object.InitializeInterface();
};
this.relatives_manager = new PrototypeManager("#user_relatives_info_parent", "#user_relatives_info_prototype",
"#user_relatives_remove_item");
this.relatives_manager.AddItem();
this.relatives_manager.OnAdd(on_change_relatives);
this.relatives_manager.OnRemove(on_change_relatives);
}
ChancesWizard.prototype.IsSpouseStep = function(step_name)
{
return (step_name.indexOf("_spouse") >= 0);
}
ChancesWizard.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);
}
ChancesWizard.prototype.FillUserAgeControl = function(select_box_id)
{
const MIN_USER_AGE_NUMBER = 20;
const MAX_USER_AGE_NUMBER = 100;
var user_age_select = $("#" + select_box_id);
if (user_age_select)
{
this.AddSelectOptions(user_age_select, "Dưới 20 tuổi", 19);
for (var i = MIN_USER_AGE_NUMBER; i <= MAX_USER_AGE_NUMBER; i++) {
this.AddSelectOptions(user_age_select, AgeToString(i), i);
}
}
}
ChancesWizard.prototype.GetWorkProfessionStartYear = function()
{
return new Date().getFullYear();
}
ChancesWizard.prototype.GetWorkProfessionEndYear = function()
{
const PROFESSION_YEARS_MAX_COUNT = 10;
return (this.GetWorkProfessionStartYear() - PROFESSION_YEARS_MAX_COUNT);
}
ChancesWizard.prototype.AddWorkProfessionWhenYear = function(control, start_year, end_year, is_spouse)
{
for (var i = start_year; i >= end_year; i--)
{
var option_prefix = is_spouse ? "Ngừng làm việc trong " : "Ngừng làm việc trong ";
this.AddSelectOptions(control, option_prefix + i + " năm", i);
}
}
ChancesWizard.prototype.FillWorkProfessionWhenPrototype = function(control, is_spouse)
{
var start_year = this.GetWorkProfessionStartYear();
var end_year = this.GetWorkProfessionEndYear();
var option_text = is_spouse ? "Hiện đang làm việc " : "Hiện đang làm việc ";
this.AddSelectOptions(control, option_text, 0);
this.AddWorkProfessionWhenYear(control, start_year, end_year, is_spouse)
}
ChancesWizard.prototype.HasSpouse = function()
{
return (IsButtonGroupCheckBoxOn("#has_partner") === true);
}
ChancesWizard.prototype.GetUserReason = function()
{
return GetSelectBoxValue("#user_reason");
}
ChancesWizard.prototype.GetChildrenCount = function()
{
return (this.GetChildren13Count() + this.GetChildren21Count());
}
ChancesWizard.prototype.GetChildren13Count = function()
{
if (IsButtonGroupCheckBoxOn("#has_children") === true)
return (VarAsInt(GetButtonGroupValue("#children_count13")));
return 0;
}
ChancesWizard.prototype.GetChildren21Count = function()
{
if (IsButtonGroupCheckBoxOn("#has_children") === true)
return (VarAsInt(GetButtonGroupValue("#children_count21")));
return 0;
}
ChancesWizard.prototype.HasChildren = function()
{
return (this.GetChildrenCount() > 0);
}
ChancesWizard.prototype.IsLanguageSchoolReason = function()
{
var reason = this.GetUserReason();
return (reason == "language");
}
ChancesWizard.prototype.IsChildrenAtHomeVisisble = function()
{
return ((this.IsLanguageSchoolReason()) &&
(this.HasChildren()));
}
ChancesWizard.prototype.UpdateVisibility = function(control, is_visible)
{
if (control)
{
if (is_visible)
$(control).show();
else
$(control).hide();
}
}
ChancesWizard.prototype.ShouldShowLanguagePassTests = function($language_control)
{
var value = GetSelectBoxValue($language_control);
var result = (value != "");
result = result && (value != "17");
result = result && (value != "24");
result = result && (value != "25");
result = result && (value != "32");
return result;
}
ChancesWizard.prototype.InitializeReasonInterface = function()
{
this.UpdateVisibility($("#additional_info_parents"), this.IsLanguageSchoolReason());
this.UpdateVisibility($("#additional_info_children"), this.IsChildrenAtHomeVisisble());
this.UpdateVisibility($("#pass_tef_block"), this.ShouldShowLanguagePassTests("#user_french"));
this.UpdateVisibility($("#pass_ielts_block"), this.ShouldShowLanguagePassTests("#user_english"));
this.UpdateVisibility($("#has_diplom_evaluation_block"), (GetSelectBoxValue("#user_education") != ""));
this.UpdateVisibility($("#pass_tef_block_spouse"), this.ShouldShowLanguagePassTests("#user_french_spouse"));
this.UpdateVisibility($("#pass_ielts_block_spouse"), this.ShouldShowLanguagePassTests("#user_english_spouse"));
this.UpdateVisibility($("#has_diplom_evaluation_block_spouse"), this.HasSpouse() && (GetSelectBoxValue("#user_education_spouse") != ""));
}
ChancesWizard.prototype.DoShowContainer = function(step)
{
this.UpdateVisibility("#" + step, this.IsStepVisible(step));
}
ChancesWizard.prototype.DoHideContainer = function(step)
{
if (this.autoshow_mode)
$("#" + step).hide();
else
this.UpdateVisibility("#" + step, this.IsStepVisible(step));
}
ChancesWizard.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)
{
if (!$(control).hasClass("can-be-empty"))
$(control).addClass('error-control-value');
}
else
$(control).addClass('unknown-control-value');
}
}
ChancesWizard.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);
});
}
ChancesWizard.prototype.IsStepVisible = function(step)
{
var result = true;
if (this.IsSpouseStep(step))
result &= (this.HasSpouse());
if (step == "user_relatives_info")
result &= (IsButtonGroupCheckBoxOn("#has_relatives"));
if (step == "user_work_experience_info")
result &= (IsButtonGroupCheckBoxOn("#has_work_experience"));
if (step == "user_work_experience_info_spouse")
result &= (IsButtonGroupCheckBoxOn("#has_work_experience_spouse"));
if (step == "user_children_info")
result &= (IsButtonGroupCheckBoxOn("#has_children"));
if (step == "user_comment_info")
result &= (IsButtonGroupCheckBoxOn("#has_comment"));
if (step == "user_school_canada_info")
result &= (IsButtonGroupCheckBoxOn("#has_school_canada"));
if (step == "user_school_canada_info_spouse")
result &= (IsButtonGroupCheckBoxOn("#has_school_canada_spouse"));
if (step == "user_job_offer_canada_info")
result &= (IsButtonGroupCheckBoxOn("#has_job_offer_canada"));
if (step == "user_interest_info_other_countries")
result &= ($("#user_interest_other_countries").is(":checked"));
if (step == "user_job_offer_canada_info_spouse")
result &= (IsButtonGroupCheckBoxOn("#has_job_offer_canada_spouse"));
return result;
}
ChancesWizard.prototype.IsSaveAvailable = function()
{
var current_step = this.GetCurrentStepIndex();
var result = (current_step == STEP_FINISHED);
return result;
}
ChancesWizard.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);
}
if ($(element).hasClass("items-container"))
{
if ($(element).is(":visible")) {
result = result && (this.EnumerateStepElements(step, element));
}
}
if ($(element).hasClass("can-be-empty"))
result = true;
return result;
}
ChancesWizard.prototype.IsVirtualContainer = function(element)
{
return ($(element).hasClass("virtual-container"));
}
ChancesWizard.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;
}
ChancesWizard.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;
}
ChancesWizard.prototype.IsStepFilled = function(step)
{
if (this.IsStepVisible(step))
{
var children_containers_selector = "#" + step;
return this.EnumerateStepElementsParent(step, children_containers_selector, true);
}
return true;
}
ChancesWizard.prototype.GetCurrentStepIndex = function()
{
this.first_unfilled_control = null;
for (var i = 0; i < ChancesWizard.steps_containers_array.length; i++)
{
if (!this.IsStepFilled(ChancesWizard.steps_containers_array[i]))
return i;
}
return STEP_FINISHED;
}
ChancesWizard.prototype.SpouseChildrenText = function(text_own, text_spouse_only, text_children_only,
text_children_spouse)
{
if (this.GetChildren13Count() > 0)
{
if (this.HasSpouse())
return text_children_spouse;
else
return text_children_only;
}
else if (this.HasSpouse())
return text_spouse_only;
return text_own;
}
ChancesWizard.prototype.UpdateSpouseInterface = function()
{
// relatives label
var temp_html = this.HasSpouse() ? "Bạn hoặc vợ/chồng của bạn có người thân nào ở Canada không?" : "Bạn có người thân nào ở Canada không?";
$("#has_relatives_label").html(temp_html);
// relatives relationship label
temp_html = this.HasSpouse() ? "Quan hệ họ hàng với bạn hoặc vợ/chồng của bạn:" : "Quan hệ họ hàng:";
temp_html = "" + temp_html + "";
$("[name='user_relatives_relationship_label']").each(function(){
$(this).html(temp_html);
});
// children
temp_html = this.HasSpouse() ? "Bạn hoặc vợ/chồng của bạn có con dưới 22 tuổi không?" : "Bạn có con dưới 22 tuổi không?";
$("#has_children_label").html(temp_html);
// criminal records
$("#criminal_record_label").html(this.SpouseChildrenText("Bạn có tiền án", "Bạn hoặc vợ/chồng của bạn có tiền án tiền sự “,” Bạn hoặc con bạn có tiền án tiền sự", "Bạn hoặc vợ/chồng của bạn, hoặc con cái của bạn có tiền án"));
// illness
$("#illnes_label").html(this.SpouseChildrenText("Bạn có một tình trạng y tế nghiêm trọng hoặc khuyết tật", "Bạn hoặc vợ/chồng của bạn có tình trạng y tế nghiêm trọng hoặc khuyết tật", "Bạn hoặc con bạn có tình trạng y tế nghiêm trọng hoặc khuyết tật", "Bạn hoặc vợ/chồng của bạn, hoặc con cái của bạn có tình trạng y tế nghiêm trọng hoặc khuyết tật"));
// deportation
$("#deportation_label").html(this.SpouseChildrenText("Bạn đã bị trục xuất khỏi các quốc gia khác", "Bạn hoặc vợ/chồng của bạn đã bị trục xuất khỏi các quốc gia khác", "Bạn hoặc con cái của bạn đã bị trục xuất khỏi các quốc gia khác", "Bạn hoặc vợ/chồng hoặc con cái của bạn đã bị trục xuất khỏi các quốc gia khác"));
}
ChancesWizard.prototype.UpdateLanguageTestVisibility = function(language_select_id, language_pass_test_id)
{
var language_value = GetSelectBoxValue(language_select_id);
if ((language_value == "24") || (language_value == "32"))
$(language_pass_test_id).show();
else
$(language_pass_test_id).hide();
}
ChancesWizard.prototype.UpdateLanguageInterface = function()
{
this.UpdateLanguageTestVisibility("#user_english", "#pass_english_test");
this.UpdateLanguageTestVisibility("#user_french", "#pass_french_test");
}
ChancesWizard.prototype.InitializeInterface = function()
{
var current_step = this.GetCurrentStepIndex();
var is_save_visible = (current_step == STEP_FINISHED);
this.save_validating = false;
this.InitializeReasonInterface();
this.ChangeInputControlStyle(current_step);
if (this.autoshow_mode)
this.UpdateVisibility($("#save_form"), is_save_visible);
for (var i = 0; i < ChancesWizard.steps_containers_array.length; i++)
{
if (i <= current_step) {
this.DoShowContainer(ChancesWizard.steps_containers_array[i]);
}
else {
this.DoHideContainer(ChancesWizard.steps_containers_array[i]);
}
}
}
ChancesWizard.prototype.AddRelativesEntry = function()
{
this.relatives_manager.AddItem();
}
ChancesWizard.prototype.AddWorkEntry = function()
{
this.nocs_manager.AddItem();
}
ChancesWizard.prototype.AddSpouseWorkEntry = function()
{
this.nocs_manager_spouse.AddItem();
}
ChancesWizard.prototype.SerializeRelativesFields = function()
{
if (IsButtonGroupCheckBoxOn("#has_relatives"))
{
var user_relatives = {};
user_relatives.user_relatives = [];
for (i = 0; i < this.relatives_manager.items_list.length; i++)
{
var object_info = {};
object_info.relationship = this.relatives_manager.items_list[i].GetInputValue("user_relatives_relationship");
if (object_info.relationship != "")
{
object_info.status = this.relatives_manager.items_list[i].GetInputValue("user_relatives_status");
object_info.length = this.relatives_manager.items_list[i].GetInputValue("user_relatives_length");
object_info.province_id = this.relatives_manager.items_list[i].GetInputValue("user_relatives_province");
user_relatives.user_relatives[i] = object_info;
}
}
if (user_relatives.user_relatives.length > 0)
return $.param(user_relatives);
}
return "";
}
ChancesWizard.prototype.ShouldSerializeNocsManager = function(nocs_manager)
{
var result = IsButtonGroupCheckBoxOn("#has_work_experience");
if (nocs_manager.is_spouse)
{
result = this.HasSpouse();
result &= IsButtonGroupCheckBoxOn("#has_work_experience_spouse");
}
return result;
}
ChancesWizard.prototype.SerializeNocsFields = function(nocs_manager, title)
{
if (this.ShouldSerializeNocsManager(nocs_manager))
return nocs_manager.SerializeNocsFields(title);
return "";
}
ChancesWizard.prototype.AddSerializedValue = function(result, value)
{
if ((result != "") &&
(value != ""))
{
result += "&";
}
result += value;
return result;
}
ChancesWizard.prototype.SerializeAdditionalFields = function()
{
var result = "";
result = this.AddSerializedValue(result, this.SerializeRelativesFields());
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;
}
ChancesWizard.prototype.CheckUserNocsCommon = function(check_box_selector, nocs_manager)
{
var result = true;
if (IsButtonGroupCheckBoxOn(check_box_selector))
{
has_work = nocs_manager.HasAnyFilledNoc();
if (has_work === false)
{
var message_str = "Xin lỗi, bạn cần chọn một nghề nghiệp từ danh sách thả xuống được hiển thị khi bạn nhập.\n\n";
message_str += "Nếu không có lựa chọn nào, vui lòng, hãy cố gắng diễn đạt lại nghề nghiệp hoặc nhập một từ đồng nghĩa với nó.\n";
alert(message_str);
$(check_box_selector).parent()[0].scrollIntoView({ behavior: 'smooth'});
result = false;
}
}
return result;
}
ChancesWizard.prototype.CheckUserNocs = function()
{
return this.CheckUserNocsCommon("#has_work_experience", this.nocs_manager);
}
ChancesWizard.prototype.CheckUserNocsSpouse = function()
{
if (this.HasSpouse())
return this.CheckUserNocsCommon("#has_work_experience_spouse", this.nocs_manager_spouse);
return true;
}
ChancesWizard.prototype.CheckUserWorkExperience = function(save_data)
{
var result = IsButtonGroupCheckBoxOn("#has_work_experience");
if (result === false)
{
var object = this;
$('#works-modal-warning').on('hidden.bs.modal', function (e)
{
$('#works-modal-warning').addClass("fade");
if ($('#works-modal-warning').hasClass("modal-result-yes"))
{
SetButtonGroupCheckBoxValue("#has_work_experience", true);
if (object.nocs_manager.items_list.length > 0)
{
var selector = object.nocs_manager.items_list[0].input_box;
$(selector)[0].focus({preventScroll: true});
}
$("#has_work_experience").parent()[0].scrollIntoView({ behavior: 'smooth'});
}
else
{
if (object.CheckUserOpenedProgramsOrScores(save_data))
object.SendProfileToServerInternal(save_data);
}
});
$('#works-modal-warning').on('shown.bs.modal', function (e)
{
$('#works-modal-warning').removeClass("modal-result-yes");
$('#works-modal-warning').removeClass("fade");
});
$('#works-modal-dlg-button-close').on('click', function (e) {
$('#works-modal-warning').addClass("modal-result-yes");
$('#works-modal-warning').modal('hide');
});
$('#works-modal-warning').modal('show');
}
return result;
}
ChancesWizard.prototype.CheckUserOpenedProgramsOrScores = function(save_data)
{
var result = (!this.has_opened_programs_or_scores);
if (this.has_opened_programs_or_scores)
{
var object = this;
$('#programs-modal-warning').on('hidden.bs.modal', function (e)
{
$('#programs-modal-warning').addClass("fade");
if ($('#programs-modal-warning').hasClass("modal-result-yes"))
{
object.SendProfileToServerInternal(save_data);
}
});
$('#programs-modal-warning').on('shown.bs.modal', function (e)
{
$('#programs-modal-warning').removeClass("modal-result-yes");
$('#programs-modal-warning').removeClass("fade");
});
$('#programs-modal-dlg-button-close').on('click', function (e) {
$('#programs-modal-warning').addClass("modal-result-yes");
$('#programs-modal-warning').modal('hide');
});
$('#programs-modal-warning').modal('show');
}
return result;
}
ChancesWizard.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'});
// console.log(this.first_unfilled_control);
}
if (result)
result &= this.CheckUserNocs();
if (result)
result &= this.CheckUserNocsSpouse();
if (result)
result &= this.CheckUserWorkExperience(save_data);
if (result)
result &= this.CheckUserOpenedProgramsOrScores(save_data);
this.save_validating = false;
return result;
}
ChancesWizard.prototype.ChangeInputsEnabledState = function(is_disabled)
{
$(".prototype-item").attr("disabled", is_disabled);
$("#user_comment_text").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_comment")));
$("#user_children_count13").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_children")));
$("#user_children_count21").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_children")));
$("#user_school_canada").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_school_canada")));
$("#user_school_canada_province").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_school_canada")));
$("#user_school_canada_spouse").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_school_canada_spouse")));
$("#user_school_canada_province_spouse").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_school_canada_spouse")));
$("#user_job_offer_canada_province").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_job_offer_canada")));
$("#user_job_offer_canada_province_spouse").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_job_offer_canada_spouse")));
$("#pass_tef").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#pass_tef_group")));
$("#pass_ielts").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#pass_ielts_group")));
$("#has_diplom_evaluation").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_diplom_evaluation_group")));
$("#pass_tef_spouse").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#pass_tef_group_spouse")));
$("#pass_ielts_spouse").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#pass_ielts_group_spouse")));
$("#has_diplom_evaluation_spouse").attr("disabled", is_disabled && (IsButtonGroupCheckBoxOff("#has_diplom_evaluation_group_spouse")));
}
ChancesWizard.prototype.SendProfileToServer = function(save_data)
{
if (this.CheckSaveAvailability(save_data)) {
this.SendProfileToServerInternal(save_data);
}
}
ChancesWizard.prototype.SubmitForm = function()
{
this.SendProfileToServer(true);
}
ChancesWizard.prototype.CalculateResults = function()
{
this.SendProfileToServer(false);
}
ChancesWizard.prototype.LoadCanadaSchoolFromJSON = function(json, is_spouse)
{
var suffix = (is_spouse) ? "_spouse" : "";
var has_school_canada = (json["user_school_canada_province" + suffix] > 0);
SetButtonGroupCheckBoxValue("#has_school_canada" + suffix, has_school_canada);
if (!has_school_canada)
{
SetSelectBoxValue("#user_school_canada" + suffix, "");
}
}
ChancesWizard.prototype.LoadChildrenFromJSON = function(json)
{
var has_children = ((json["user_children_count13"] + json["user_children_count21"]) > 0);
SetButtonGroupCheckBoxValue("#has_children", has_children);
if (has_children)
{
SetButtonGroupValue("#children_count13", json["user_children_count13"]);
SetButtonGroupValue("#children_count21", json["user_children_count21"]);
}
}
ChancesWizard.prototype.LoadControlsFromJSON = function(json)
{
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]);
}
SetButtonGroupCheckBoxValue("#has_partner", json["user_has_spouse"]);
SetButtonGroupCheckBoxValue("#has_comment", (json["user_comment_text"] != ""));
SetButtonGroupCheckBoxValue("#has_job_offer_canada", (json["user_job_offer_canada_province"] > 0));
SetButtonGroupCheckBoxValue("#has_job_offer_canada_spouse", (json["user_job_offer_canada_province_spouse"] > 0));
SetButtonGroupCheckBoxValue("#pass_tef_group", json["pass_tef"]);
SetButtonGroupCheckBoxValue("#pass_ielts_group", json["pass_ielts"]);
SetButtonGroupCheckBoxValue("#has_diplom_evaluation_group", json["has_diplom_evaluation"]);
SetButtonGroupCheckBoxValue("#pass_tef_group_spouse", json["pass_tef_spouse"]);
SetButtonGroupCheckBoxValue("#pass_ielts_group_spouse", json["pass_ielts_spouse"]);
SetButtonGroupCheckBoxValue("#has_diplom_evaluation_group_spouse", json["has_diplom_evaluation_spouse"]);
this.has_opened_programs_or_scores = (json["has_opened_programs_or_scores"] == "true");
$("#user_comment_text").val(json["user_comment_text"]);
$("#user_interest_other_countries_list").val(json["user_interest_other_countries_list"]);
this.LoadChildrenFromJSON(json);
this.LoadCanadaSchoolFromJSON(json, false);
this.LoadCanadaSchoolFromJSON(json, true);
}
ChancesWizard.prototype.LoadRelativesControlsFromJSON = function(json)
{
var has_relatives = false;
if (json["user_relatives"])
{
relatives_array = json["user_relatives"];
has_relatives = (relatives_array.length > 0);
if (has_relatives)
{
for (var i = 0; i < relatives_array.length; i++)
{
var current_item = this.relatives_manager.current_item;
current_item.SetInputValue("user_relatives_status", relatives_array[i].status);
current_item.SetInputValue("user_relatives_length", relatives_array[i].length);
current_item.SetInputValue("user_relatives_province", relatives_array[i].province_id);
current_item.SetInputValue("user_relatives_relationship", relatives_array[i].relationship);
if (i != (relatives_array.length - 1))
this.relatives_manager.AddItem();
}
}
}
SetButtonGroupCheckBoxValue("#has_relatives", has_relatives);
}
ChancesWizard.prototype.SetWorkProfessionWhenValue = function(current_item, finished_year, is_spouse)
{
var year_exists = false;
var select_box_name = "#" + current_item.GetNocsElementIndexedPrefixedName("when");
$(select_box_name).children().each(function(child_index, child)
{
if (child.value == finished_year)
{
year_exists = true;
return;
}
});
if (!year_exists)
this.AddWorkProfessionWhenYear($(select_box_name)[0], this.GetWorkProfessionEndYear() - 1, finished_year, is_spouse);
current_item.SetInputValue("when", finished_year);
}
ChancesWizard.prototype.LoadNocsControlsFromJSON = function(json, is_spouse)
{
var has_nocs = false;
var nocs_suffix = (is_spouse) ? "_spouse" : "";
var nocs_manager = (is_spouse) ? this.nocs_manager_spouse : this.nocs_manager;
if (json["user_nocs" + nocs_suffix])
{
nocs_array = json["user_nocs" + nocs_suffix];
has_nocs = (nocs_array.length > 0);
if (has_nocs)
{
for (var i = 0; i < nocs_array.length; i++)
{
var current_item = nocs_manager.current_item;
current_item.SetInputValue("", nocs_array[i].job_title);
this.SetWorkProfessionWhenValue(current_item, nocs_array[i].work_finished_year, is_spouse);
current_item.ShowWorkExperience(nocs_array[i].job_title, nocs_array[i].job_id, nocs_array[i].noc_id);
current_item.ShowNocVideoFiles(nocs_array[i].job_id, nocs_array[i].noc_id, nocs_array[i].video_files, false);
var work_experience_monthes = (nocs_array[i].work_experience % MONTHES_PER_YEAR);
var work_experience_years = nocs_array[i].work_experience - work_experience_monthes;
current_item.SetInputValue("length", work_experience_years);
current_item.SetInputValue("length_monthes", work_experience_monthes);
$(current_item.duration_select).trigger("onchange");
SetRadioBoxCheckedByNameValue(current_item.GetNocsElementIndexedPrefixedName("worktime"), nocs_array[i].work_time_id);
SetRadioBoxCheckedByNameValue(current_item.GetNocsElementIndexedPrefixedName("worktype"), nocs_array[i].work_type_id);
// is at Canada
var at_canada = (nocs_array[i].province_id > 0);
SetButtonGroupCheckBoxValue(current_item.location_check_box, at_canada);
if (at_canada) {
current_item.SetInputValue("province", nocs_array[i].province_id);
}
if (i != (nocs_array.length - 1))
nocs_manager.AddItem();
}
}
}
SetButtonGroupCheckBoxValue("#has_work_experience" + nocs_suffix, has_nocs);
}
ChancesWizard.prototype.LoadJobOfferControlsFromJSON = function(json, is_spouse)
{
var nocs_suffix = (is_spouse) ? "_spouse" : "";
var nocs_manager = (is_spouse) ? this.job_offer_nocs_manager_spouse : this.job_offer_nocs_manager;
if (json["user_job_offer_canada_job_title" + nocs_suffix])
{
var offer_job_title = json["user_job_offer_canada_job_title" + nocs_suffix];
var current_item = nocs_manager.current_item;
current_item.SetInputValue("", offer_job_title);
current_item.ShowWorkExperience(offer_job_title, json["user_job_offer_canada_job_id" + nocs_suffix],
json["user_job_offer_canada_noc_id" + nocs_suffix]);
}
}
ChancesWizard.prototype.LoadControlsFromJSONContent = function(json_content)
{
if (json_content)
{
var json = JSON.parse(json_content);
this.LoadControlsFromJSON(json);
this.LoadRelativesControlsFromJSON(json);
this.LoadNocsControlsFromJSON(json, false);
this.LoadNocsControlsFromJSON(json, true);
this.LoadJobOfferControlsFromJSON(json, false);
this.LoadJobOfferControlsFromJSON(json, true);
}
}
ChancesWizard.prototype.LoadParameters = function()
{
this.autoshow_mode = (ReadCurrentURLParam("auto_show") == "1");
}
ChancesWizard.prototype.InitializeInternalObjects = function()
{
this.FillUserAgeControl("user_age");
this.FillUserAgeControl("user_age_spouse");
this.FillWorkProfessionWhenPrototype("#user_work_profession_when", false);
this.FillWorkProfessionWhenPrototype("#user_work_profession_when_spouse", true);
this.InitializeNocsManagers();
this.InitializeJobOfferNocsManagers();
this.InitializeRelativesManager();
}
ChancesWizard.prototype.PrepareForm = function()
{
// Do nothing
}
ChancesWizard.prototype.DoOnLoading = function()
{
// Do nothing
}
ChancesWizard.prototype.SendProfileToServerInternal = function(save_data)
{
// prototype items
var form = $("#ChancesProfile");
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);
CompleteRegistration();
setTimeout(function() {
SubmitSerializedDataToServer(post_url, request_method, form_data);
}, 1500);
/*$.ajax({
url: post_url,
type: request_method,
data: form_data
}).done(function(response)
{
// replace document html using Ajax
var newDoc = document.open("text/html", "replace");
newDoc.write(response);
newDoc.close();
window.scrollTo(0, 0);
});
*/
}
ChancesWizard.prototype.Initialize = function(json_content)
{
this.LoadParameters();
this.InitializeInternalObjects();
this.PrepareForm();
this.LoadControlsFromJSONContent(json_content);
this.InitializeInterface();
this.UpdateSpouseInterface();
this.UpdateLanguageInterface();
}