var $ = jQuery; $(document).ready(function () { $(".close-alert").click(function () { $(this).parent().hide(); }); $('#job-type-modal').modal({ backdrop: 'static', keyboard: false, show: true }); $('.select2-checkbox').each(function(i, elem){ $(elem).select2({ closeOnSelect: false, "language": { "noResults": function(){ return $(elem).data('locale') == 'ar' ? "لم يتم العثور علي نتائج" : "No results found"; } }, }).data('select2').$dropdown.addClass('select2-checkbox-container'); }); $("#chkall").click(function(){ if($("#chkall").is(':checked')){ $("#L-job-major > option").prop("selected", "selected"); $("#L-job-major").trigger("change"); } else { $("#L-job-major > option").removeAttr("selected"); $("#L-job-major").trigger("change"); } }); jQuery('#new-job-type').submit(function(e) { $('.help').hide(); e.preventDefault(); showLoader(); $.ajax({ type: 'POST', url: $(this).prop('action'), data: $(this).serialize(), dataType: 'json', success: submissionSuccess }).fail(function (e) { hideLoader(); if (e.responseJSON && e.responseJSON.errors && 422 === e.status) { let errors = e.responseJSON.errors; for (let key in e.responseJSON.errors) { let $help = $('#' + key + '-help'); $help.text(errors[key]); $help.show(); } } else { $('#job-type-modal').modal('toggle'); } }); }); $('#close-skills-hint').click(function (e) { $.cookie('skills_check',0, { path: '/' }); }); // Resend activation link via email const $activation_link = $('#resend-activation'); if ($activation_link.length > 0) { $activation_link.click(function (e) { e.preventDefault(); showLoader(); const $form = $('#resend-activation-form'); $.ajax({ url: $form.attr('action'), method: 'POST', data: $form.serialize() }).done(res => window.location = res.data.redirect_to) .fail(e => window.location = e.responseJSON.data.redirect_to) .always(_ => hideLoader()); }); } $('#close-job-titles-hint').click(function (e) { $.cookie('job_titles_check',0, { path: '/' }); }); $.fn.select2.defaults.set('language', { noResults: function () { return opts.no_results; } }); if ($('.skills-input').length>0 ) { $('.skills-input').select2(); } bindDatepicker(); if ( $('[data-toggle="tooltip"]').length>0) { $('[data-toggle="tooltip"]').tooltip(); } $(document).on('submit', 'form.ajax-form', function (e) { e.preventDefault(); var success_fn = $(this).data('success'); var success_args = $(this).data('success-args'); if (success_fn != undefined) { success_fn = window[success_fn]; if (success_args != undefined) { success_fn = success_fn(...success_args.split(',')); } } else { success_fn = submissionFormSuccess; } var data = new FormData(this) $.ajax({ url: ajax_object.ajax_url, method: 'post', data: data, dataType: 'json', processData: false, contentType: false, beforeSend: function() { showLoader(); }, success: success_fn, error: submissionFormError('form.ajax-form'), complete: function() { hideLoader(); } }); }); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { trigger_truncate_action(); }); $( '.arial' ).each( function() { $element = $(this); $element.html( $element.html().toIndiaDigits ); } ); if ($('.select2-multiple').length>0) { $('.select2-multiple').select2({ tags: true, tokenSeparators: [','], minimumInputLength: 2 }); } // Teleworker Skills if ($('.L-select-teleworker-skill').length > 0) { let $select2 = $('#teleworkers-skills'); $select2.select2({ language: $select2.data('locale'), tokenSeparators: [','], minimumInputLength: 2, ajax: { url: $select2.data('url'), dataType: 'json', delay: 250, data: function (params) { return { search_term: params.term // search term }; }, processResults: function (response) { return { results: response.data['skills'] }; }, cache: true } }); } if( $('.L-teleworker-job-skills').length > 0 ){ url = decodeURIComponent( window.location.search); const result = url.split('&') const jobSkillsList = result.filter((item) => item.includes('q[job_skills][]=')) const jobSkillsNumbers = [] jobSkillsList.forEach(item => { jobSkillsNumbers.push(item.split('=')[1]) }) let $job_skills_select2 = $('#L-teleworker-job-skills'); if (jobSkillsNumbers.length > 0) { $job_skills_select2.select2({ language: { inputTooShort: function(args) { // args.minimum is the minimum required length // args.input is the user-typed text return $job_skills_select2.data('locale') ? "الرجاء اضافه 2 عنصر" : "please enter 2 or more character"; }, inputTooLong: function(args) { // args.maximum is the maximum allowed length // args.input is the user-typed text return "You typed too much"; }, noResults: function() { return $job_skills_select2.data('locale') ? "لم يتم العثور علي نتائج" : "No results found"; }, searching: function() { return $job_skills_select2.data('locale') ? "جاري البحث..." : "Searching..."; }, }, tokenSeparators: [','], minimumInputLength: 2, ajax: { url: $job_skills_select2.data('url'), dataType: 'json', delay: 250, data: function (params) { return { search_term: params.term // search term }; }, processResults: function (response) { return { results: response.data.skills, more: false }; }, cache: true }, initSelection: function (element, callback) { var id = $(element).val(); if(id !== "") { $.ajax("/ar/skills/search/", { data: {skills: jobSkillsNumbers}, dataType: "json" }).done(function(data) { $skills = data.data.skills; $skills.forEach(function(item) { element.append(''); callback({id: item.id,text: item.text}); }) }); } } }); } else { $job_skills_select2.select2({ language: { inputTooShort: function(args) { // args.minimum is the minimum required length // args.input is the user-typed text return $job_skills_select2.data('locale') ? "الرجاء اضافه 2 عنصر" : "please enter 2 or more character"; }, inputTooLong: function(args) { // args.maximum is the maximum allowed length // args.input is the user-typed text return "You typed too much"; }, noResults: function() { return $job_skills_select2.data('locale') ? "لم يتم العثور علي نتائج" : "No results found"; }, searching: function() { return $job_skills_select2.data('locale') ? "جاري البحث..." : "Searching..."; }, }, tokenSeparators: [','], minimumInputLength: 2, ajax: { url: $job_skills_select2.data('url'), dataType: 'json', delay: 250, data: function (params) { return { search_term: params.term // search term }; }, processResults: function (response) { return { results: response.data.skills, more: false }; }, cache: true } }); } } $('#job_type_id').change(function() { let $txtFieldWrap = $(this).parents('.L-job_type_select_gp').find('.L-others_select_text'); let $txtCheck = $(this).parents('.L-job_type_select_gp').find('.job-type-notification'); let $type = $(this).val(); if( $type == 'Others') { $txtFieldWrap.show(); $txtCheck.hide(); } else { $txtFieldWrap.hide(); $txtCheck.show(); } }); $('#job-type').change(function() { let $txtFieldWrap = $(this).parents('.L-job_type_select_gp').find('.L-others_select_text'); let $type = $(this).val().split('-'); if( $type[1] == 'Others') { $txtFieldWrap.show(); } else { $txtFieldWrap.hide(); } }); $('#job-type').change(function() { let $txtFieldWrap = $(this).parents('.L-job_type_select_gp').find('.L-others_select_text'); let $type = $(this).val().split('-'); if( $type[1] == 'Others') { $txtFieldWrap.show(); } else { $txtFieldWrap.hide(); } }); $('#job_title_id').change(function() { let $txtFieldWrap = $(this).parents('.L-job_title_select_gp').find('.L-others_select_text'); let $title = $(this).val(); if( $title == 'Others') { $txtFieldWrap.show(); } else { $txtFieldWrap.hide(); } }); // Disable teleworker save skills button while selecting from the drop-down results $('#teleworkers_skills').on('select2:opening', function () { $('#save-skills-button').prop( 'disabled', true ); }); // Enable Teleworker save skills button while selecting from the drop-down results $('#teleworkers_skills').on('select2:select select2:close', function () { $('#save-skills-button').prop( 'disabled', false ); }); // Job Skills if( $('.L-select-job-skills').length > 0 ){ let $job_skills_select2 = $('#job_skills'); $job_skills_select2.select2({ language: $job_skills_select2.data('locale'), tokenSeparators: [','], minimumInputLength: 2, ajax: { url: $job_skills_select2.data('url'), dataType: 'json', delay: 250, data: function (params) { console.log(123); return { search_term: params.term // search term }; }, processResults: function (response) { return { results: response }; }, cache: true } }); } // Disable Company/SP new job button while selecting from skills drop-down results $('#job_skills').on('select2:opening', function () { $('#save-job-button').prop( 'disabled', true ); }); // Enable Teleworker new job button while selecting from skills drop-down results $('#job_skills').on('select2:select select2:close', function () { $('#save-job-button').prop( 'disabled', false ); }); // Employee Page search skills if( $('.L-system-skills').length > 0 ){ let $system_skill_select2 = $('#search-system-skills'); $system_skill_select2.select2({ tags: true, language: $system_skill_select2.data('locale'), tokenSeparators: [','], minimumInputLength: 2, ajax: { url: $system_skill_select2.data('url'), dataType: 'json', delay: 250, data: function (params) { return { search_term: params.term // search term }; }, processResults: function (response) { return { results: response }; }, cache: true } }); } // Disable search employees button while selecting from skills drop-down results $('#search-system-skills').on('select2:opening', function () { $('#search-employees-button').prop( 'disabled', true ); }); // Enable search employees button while selecting from skills drop-down results $('#search-system-skills').on('select2:select select2:close', function () { $('#search-employees-button').prop( 'disabled', false ); }); $('.secured-attachment').click(function(e) { e.preventDefault(); $(this).siblings(".secured-attachment-form").submit(); }); // Clear filter forms and resubmit $('#clear_filters_form').on('click', function () { $(this).closest('form').find('input[type=text], textarea').val(''); $('.submit_filters_form').click(); }); $('#new-project-form').on('hidden.bs.modal', function () { $('.collapse').collapse('hide'); }); function showHideText(sSelector, options) { // Def. options var defaults = { charQty: 100, ellipseText: "...", moreText: "Show more", lessText: "Show less" }; var settings = $.extend({}, defaults, options); var s = this; s.container = $(sSelector); s.containerH = s.container.height(); s.container.each(function () { var content = $(this).html(); if (content.length > settings.charQty) { var visibleText = content.substr(0, settings.charQty); var hiddenText = content.substr(settings.charQty, content.length - settings.charQty); var html = visibleText + '' + settings.ellipseText + '' + hiddenText + '' + settings.moreText + ''; $(this).html(html); } }); s.showHide = function (event) { event.preventDefault(); if ($(this).hasClass("less")) { $(this).removeClass("less"); $(this).html(settings.moreText); $(this).prev().fadeToggle('fast', function () { $(this).parent().prev().fadeIn(); }); } else { $(this).addClass("less"); $(this).html(settings.lessText); $(this).parent().prev().hide(); $(this).prev().fadeToggle('fast'); } } $(".morelink").bind('click', s.showHide); } var th = new showHideText('.collapsible-text', { charQty: 250, ellipseText: "...", moreText: "", lessText: "" }); handleFormError(); $(document).ajaxComplete(function() { handleFormError(); }); }); function trigger_truncate_action() { let elementsToEllipsis = $('[data-toggle="ellipsis"]'); elementsToEllipsis.each((i, element) => { let $element = $(element); let options = {}; if( $element.data('type') !== undefined ) options.type = $element.data('type'); if( $element.data('count') !== undefined ) options.count = $element.data('count'); $ellipsis_element = $.data($element[0], 'plugin_ellipsis'); if($ellipsis_element){ $ellipsis_element.reset( options ); } $element.ellipsis(options); }); } function submissionFormSuccess(res) { location.reload(); } function submissionFormError(form_selector) { return function(err) { hideLoader() // Remove all error fields before populating errors $(form_selector + ' div.error').remove(); $(form_selector).find(":submit").removeAttr( "disabled" ); var errors = err.responseJSON.data for (var errorField in errors) { var selector = form_selector + " [name=" + errorField + "]"; var $inputFormGroup = $(selector).parent(); $inputFormGroup.append("