function NOCSearcher(html_prototype, is_spouse, prefix_name = "user_work_profession") { var object = this; this.noc_id = -1; this.job_id = -1; this.noc_code = ""; this.noc_title = ""; this.user_data_id = -1; this.prefix_name = prefix_name; this.can_auto_accept_job = false; this.show_noc_before_title = false; this.relative_container_pos = false; this.clear_job_on_key_press = false; this._index = NOCSearcher.nocs_index_counter + 1; NOCSearcher.nocs_index_counter++; this.content_container = null; this.is_spouse = is_spouse; this.is_suggestion_showed = false; this.html_prototype = html_prototype; this.input_box = "#" + this.GetNocsElementIndexedPrefixedName(""); this.parent_container = "#" + this.GetNocsElementPrefixedName("parent"); this.remove_button = "#" + this.GetNocsElementIndexedPrefixedName("remove_item"); this.result_box = "#" + this.GetNocsElementIndexedPrefixedName("result_box_container"); this.suggestion_container = "#" + this.GetNocsElementIndexedPrefixedName("suggestion_box"); this.location_province = "#" + this.GetNocsElementIndexedPrefixedName("province_container"); this.location_check_box = "#" + this.GetNocsElementIndexedPrefixedName("location_place"); this.duration_select = "#" + this.GetNocsElementIndexedPrefixedName("length"); this.duration_container = "#" + this.GetNocsElementIndexedPrefixedName("length_container"); this.duration_select_monthes = "#" + this.GetNocsElementIndexedPrefixedName("length_monthes"); this.duration_monthes_container = "#" + this.GetNocsElementIndexedPrefixedName("length_monthes_container"); this.on_scroll_handler = function (){ object.LocateSuggestionContainer(); } this.InitializeControls(); } NOCSearcher.prototype.GetNocsElementName = function (element) { var result = element; if (this.is_spouse === true) result += "_spouse"; return result; } NOCSearcher.prototype.GetNocsElementPrefixedName = function (element) { return (this.GetNocsElementName(this.GetPrefixedElementName(element))); } NOCSearcher.prototype.GetPrefixedElementName = function (element) { var result = this.prefix_name; if (element != "") result += "_" + element; return result; } NOCSearcher.prototype.GetNocsElementIndexedPrefixedName = function (element) { var result = this.GetPrefixedElementName(element); result = this.GetNocsElementName(result) + this._index; return result; } NOCSearcher.prototype.ChangeContainerVisibility = function(container, visible) { if (visible) $(container).removeClass("hidden-container"); else $(container).addClass("hidden-container"); } NOCSearcher.prototype.UpdateInterface = function() { if (typeof IsButtonGroupCheckBoxOn === "function") this.ChangeContainerVisibility(this.location_province, IsButtonGroupCheckBoxOn(this.location_check_box)); } NOCSearcher.prototype.UpdateContainerParams = function(container) { var object = this; if (container.id) { container.id = container.id + this._index; } if (IsRadioBox(container)) { /* alert("Radio Box: " + container.name); */ container.name = container.name + this._index; } $(container).children().each(function (index, child) { object.UpdateContainerParams(child); }); } NOCSearcher.prototype.ShowSuggestionContainer = function(data) { if (this.is_suggestion_showed === false) { this.is_suggestion_showed = true; $(this.suggestion_container).show(); window.addEventListener('scroll', this.on_scroll_handler); } } NOCSearcher.prototype.HideSuggestionContainer = function() { if (this.is_suggestion_showed === true) { this.is_suggestion_showed = false; window.removeEventListener('scroll', this.on_scroll_handler); $(this.suggestion_container).hide(); } } NOCSearcher.prototype.LocateSuggestionContainer = function() { var object = this; var container_width = $(object.input_box).width(); $(object.suggestion_container).css("width", container_width + "px"); $(object.suggestion_container).width(container_width); var container_height = object.CalculateSuggestionHeight(); if (container_height > 0) { $(object.suggestion_container).css("top", object.CalculateSuggestionTopPosition() + "px"); $(object.suggestion_container).css("height", container_height + "px"); $(object.suggestion_container).children().each(function (ul_index, ul_child) { $(ul_child).children().each(function (il_index, il_child) { var tag_name = $(il_child).get(0).tagName; var job_id = $(il_child).attr("job_id"); var noc_id = $(il_child).attr("noc_id"); var noc_code = $(il_child).attr("noc_code"); var noc_level = $(il_child).attr("noc_level"); var noc_title = $(il_child).attr("noc_title"); var user_data_id = $(il_child).attr("user_data_id"); var noc_title_en = $(il_child).attr("noc_title_en"); // $(il_child).attr("onClick", function ()); $(il_child).bind('click', function() { object.SelectNocTitle(noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id); }); }); }); } else { object.HideSuggestionContainer(); } } NOCSearcher.prototype.ChangeDurationMonthesVisibleState = function(is_visible) { if (is_visible) $(this.duration_container).addClass("info_sub_block_quorter"); else $(this.duration_container).removeClass("info_sub_block_quorter"); this.ChangeContainerVisibility(this.duration_monthes_container, is_visible); this.DoChange(); } NOCSearcher.prototype.FillControlsProperties = function() { var object = this; $(this.input_box).autocomplete = "off"; // on remove button click if ($(this.remove_button).length > 0) { $(this.remove_button)[0].onclick = function() { object.DoRemove(); }; } if (typeof FillButtonGroupMemberHandlers === "function") FillButtonGroupMemberHandlers(); if (typeof AddButtonGroupEventListener === "function") { AddButtonGroupEventListener(this.location_check_box, function(){ object.DoChange(); }); } this.UpdateInterface(); if ($(this.duration_select).length > 0) { $(this.duration_select)[0].onchange = function (){ var is_monthes_visible = (IsSelectBoxFilled(object.duration_select)); object.ChangeDurationMonthesVisibleState(is_monthes_visible); }; } // on enter profession if ($(this.input_box).length > 0) { $(this.input_box)[0].onkeyup = function() { if ($(this).val().trim() != object.noc_title) object.SearchSuggestionContainer(); }; } } NOCSearcher.prototype.SearchSuggestionContainer = function() { if ($(this.input_box).length > 0) { var object = this; object.noc_title = $(object.input_box).val().trim(); if (object.clear_job_on_key_press) { object.noc_id = -1; object.job_id = -1; } $.ajax({ type: "POST", url: GetBaseURL(), data:'mode=noc_search_ajax&keyword=' + $(object.input_box).val() + "&use_new_noc=" + ReadCurrentURLParam("use_new_noc") + "&show_noc_before_title=" + (object.show_noc_before_title ? 1 : 0), beforeSend: function(){ }, success: function(data) { object.ShowSuggestionContainer(data); $(object.suggestion_container).html(data); object.LocateSuggestionContainer(); } }); } } NOCSearcher.prototype.CloneContainer = function () { if ((this.content_container == null) && (this.html_prototype != "")) { var object = this; this.content_container = $.parseHTML(this.html_prototype)[0]; $(this.content_container).removeClass("prototype"); this.UpdateContainerParams(this.content_container); // console.log(this.content_container); $(this.parent_container)[0].appendChild(this.content_container); this.FillControlsProperties(); } } NOCSearcher.prototype.SelectNocTitle = function (noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id) { var object = this; $(this.input_box).val(noc_title); this.HideSuggestionContainer(); if (object.can_auto_accept_job) { object.ShowWorkExperience(noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id); object.DoChange(); } else { console.log(this.result_box); var url = GetBaseURL() + "?mode=job_search_ajax&job_id=" + job_id + "&use_new_noc=" + ReadCurrentURLParam("use_new_noc") + "&show_noc_before_title=" + (object.show_noc_before_title ? 1 : 0); $.post( url, function(data, status) { $(this.result_box).show(); var apply_element_id = "apply_" + object._index; var html = "

آیا توضیحات زیر برای شما درست است؟

\n"; html += "

" + data + "

\n"; html += "
درست است
\n"; html += "

اگر توضیحات با شغل شما مطابقت ندارد، لطفاً با انتخاب ارزش شغلی متفاوت، دوباره وارد حرفه شوید.

\n"; $(object.result_box).show(); $(object.result_box).html(html); // $(object.remove_button)[0].scrollIntoView(); if ($("#" + apply_element_id).length) { $("#" + apply_element_id)[0].onclick = function(){ object.ShowWorkExperience(noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id); object.DoApplyProfession(); } } } ); } } NOCSearcher.prototype.ShowWorkExperience = function(noc_title, job_id, noc_id, noc_code, noc_level, noc_title_en, user_data_id) { this.noc_id = noc_id; this.job_id = job_id; this.noc_code = noc_code; this.noc_title = noc_title; this.user_data_id = user_data_id; $(this.result_box).hide(); this.UpdateNocDescription(noc_id, noc_code, noc_level, noc_title_en); this.ChangeContainerVisibility("#" + this.GetNocsElementIndexedPrefixedName("info"), true); } NOCSearcher.prototype.CalculateSuggestionItemHeight = function (il_item) { // height with padding var result = $(il_item).innerHeight(); // border bottom result = result + 1; return result; } NOCSearcher.prototype.CalculateSuggestionRealHeight = function (max_height) { var result = 0; var object = this; $(this.suggestion_container).children().each(function (ul_index, ul_child) { $(ul_child).children().each(function (il_index, il_child) { var child_height = object.CalculateSuggestionItemHeight(il_child); if ((result + child_height) > max_height) return result; result += child_height; }); }); return result; } NOCSearcher.prototype.SearchNocsContainerParent = function () { var parent = $(this.content_container).parent(); while (parent) { var tag_name = parent.get(0).tagName; if (tag_name == "FORM") return parent; parent = parent.parent(); } return undefined; } NOCSearcher.prototype.CalculateSuggestionTopHeight = function () { var pos = $(this.input_box).offset(); var window_top = VarAsInt($(window).scrollTop()); var parent = this.SearchNocsContainerParent(); var parent_top = 0; if (parent) parent_top = parent.offset().top; var result = pos.top - Math.max(window_top, parent_top) - 12; return result; } NOCSearcher.prototype.CalculateSuggestionBottomHeight = function () { var pos = $(this.input_box).offset(); var start_oy = pos.top + VarAsInt($(this.input_box).innerHeight()); var result = VarAsInt($(window).scrollTop()) + VarAsInt($(window).innerHeight()) - start_oy; result = result - 10; return result; } NOCSearcher.prototype.CalculateSuggestionTopPosition = function () { if (this.relative_container_pos) { var pos = $(this.input_box).offset(); var result = pos.top + VarAsInt($(this.input_box).innerHeight()) + 2; if (this.CalculateSuggestionTopHeight() > this.CalculateSuggestionBottomHeight()) result = pos.top - this.CalculateSuggestionHeight() - 1; return result; } return VarAsInt($(this.input_box).innerHeight()); } NOCSearcher.prototype.CalculateSuggestionHeight = function () { var result = Math.max(this.CalculateSuggestionBottomHeight(), this.CalculateSuggestionTopHeight()); return this.CalculateSuggestionRealHeight(result); } NOCSearcher.prototype.InitializeControls = function () { this.CloneContainer(); } NOCSearcher.prototype.OnRemove = function (event) { this.on_remove = event; } NOCSearcher.prototype.OnChange = function (event) { this.on_change = event; } NOCSearcher.prototype.OnApplyProfession = function(event) { this.on_apply_profession = event; } NOCSearcher.prototype.DoChange = function () { this.UpdateInterface(); if (this.on_change) this.on_change(this); } NOCSearcher.prototype.DoApplyProfession = function () { this.DoChange(); if (this.on_apply_profession) this.on_apply_profession(this); } NOCSearcher.prototype.DoRemove = function () { if (this.content_container != null) { $(this.content_container).remove(); if (this.on_remove) this.on_remove(this); } } NOCSearcher.prototype.GetInputValue = function (element_id) { element_id = this.GetNocsElementIndexedPrefixedName(element_id); if (element_id) { return $("#" + element_id).val(); } return ""; } NOCSearcher.prototype.UpdateNocDescription = function(noc_id, noc_code, noc_level, job_desc) { if ((Assigned(noc_id)) && (Assigned(noc_code)) && (Assigned(noc_level)) && (Assigned(job_desc))) { var level_caption = (noc_code.length == 5) ? "Teer" : "Level"; var description_html = "NOC " + noc_code + " (" + level_caption + " " + noc_level + ") - " + job_desc; var element_id = "#" + this.GetNocsElementIndexedPrefixedName("noc"); $(element_id).html(description_html); } } NOCSearcher.prototype.ShowNocVideoFiles = function(job_id, noc_id, video_files, is_visible) { console.log(video_files); if ((Assigned(noc_id)) && (Assigned(job_id)) && (Assigned(video_files)) && (Assigned(video_files.length > 0))) { video_files_html = ""; for (let i = 0; i < video_files.length; i++) { var video_files_html = "
"; video_files_html += "مثال کار: " + video_files[i].name + ""; video_files_html += ""; video_files_html += ""; video_files_html += ""; video_files_html += "
"; } var element_id = "#" + this.GetNocsElementIndexedPrefixedName("video_files"); $(element_id).html(video_files_html); $(element_id).changeVisibility(is_visible); } } NOCSearcher.prototype.SetInputValue = function (element_id, value) { element_id = this.GetNocsElementIndexedPrefixedName(element_id); if (element_id) { $("#" + element_id).val(value); } } NOCSearcher.prototype.GetInputRadioValue = function (element_id) { element_id = this.GetNocsElementIndexedPrefixedName(element_id); if (element_id) { var selector = "input[name=" + element_id + "]:checked"; return $(selector).val() } return ""; } NOCSearcher.nocs_index_counter = 0;