function NocsManager(is_spouse, prefix_name = "user_work_profession")
{
this.items_list = [];
this.current_item = null;
this.is_spouse = is_spouse;
this.prefix_name = prefix_name;
this.show_noc_before_title = false;
this.can_auto_accept_job = false;
this.clear_job_on_key_press = false;
// html prototype
this.html_prototype = $(this.GetNocsElementName("#" + this.GetPrefixedElementName("prototype"))).outerHTML();
}
NocsManager.prototype.GetPrefixedElementName = function (element)
{
var result = this.prefix_name;
if (element != "")
result += "_" + element;
return result;
}
NocsManager.prototype.GetNocsElementName = function (element)
{
result = element;
if (this.is_spouse === true)
result += "_spouse";
return result;
}
NocsManager.prototype.HasNocs = function()
{
return (this.items_list.length > 0);
}
NocsManager.prototype.AddItem = function()
{
var object = this;
this.current_item = new NOCSearcher(this.html_prototype, this.is_spouse, this.prefix_name);
this.current_item.can_auto_accept_job = this.can_auto_accept_job;
this.current_item.show_noc_before_title = this.show_noc_before_title;
// console.log(this.current_item.show_noc_before_title);
this.current_item.clear_job_on_key_press = this.clear_job_on_key_press;
this.items_list.push(this.current_item);
var on_change = function (item)
{
if (object.on_change_callback)
object.on_change_callback(item);
};
this.current_item.OnChange(on_change);
// on remove event
this.current_item.OnRemove(function(item)
{
var array_idx = object.items_list.indexOf(item);
if (array_idx >= 0)
object.items_list.splice(array_idx, 1);
if (object.on_change_callback)
object.on_change_callback(item);
});
this.current_item.OnApplyProfession(function(sender, noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id)
{
if (object.on_apply_profession)
object.on_apply_profession(object.current_item, noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id);
});
if (this.on_change_callback)
this.on_change_callback(this.current_item);
}
NocsManager.prototype.SerializeNocsFields = function(title)
{
var result = {};
result[title] = [];
for (i = 0; i < this.items_list.length; i++)
{
var object_info = {};
if (this.IsNocReallyFilled(this.items_list[i]))
{
object_info.work_experience = VarAsInt(this.items_list[i].GetInputValue("length")) +
VarAsInt(this.items_list[i].GetInputValue("length_monthes"));
object_info.noc_id = this.items_list[i].noc_id;
object_info.job_id = this.items_list[i].job_id;
object_info.noc_code = this.items_list[i].noc_code;
object_info.work_finished_year = this.items_list[i].GetInputValue("when");
object_info.province_id = 0;
if (IsButtonGroupCheckBoxOn(this.items_list[i].location_check_box))
object_info.province_id = this.items_list[i].GetInputValue("province");
object_info.work_time_id = this.items_list[i].GetInputRadioValue("worktime");
object_info.work_type_id = this.items_list[i].GetInputRadioValue("worktype");
result[title][i] = object_info;
}
}
if (result[title].length > 0)
return $.param(result);
return "";
}
NocsManager.prototype.OnChangeNocs = function(on_change_callback)
{
this.on_change_callback = on_change_callback;
}
NocsManager.prototype.OnApplyProfession = function(callback)
{
this.on_apply_profession = callback;
}
NocsManager.prototype.IsNocReallyFilled = function(noc_item)
{
if (noc_item)
{
var job_id = noc_item.job_id;
return (job_id > 0);
}
return false;
}
NocsManager.prototype.HasAnyFilledNoc = function()
{
var result = false;
for (i = 0; i < this.items_list.length; i++) {
result = result || (this.IsNocReallyFilled(this.items_list[i]));
}
return result;
}
NocsManager.prototype.IsFilled = function()
{
var result = this.HasNocs();
return result;
}