(function($) {
"use strict";  
  initDataTable('.table-table_recruitment_channel', admin_url+'recruitment/table_recruitment_channel');
  init_recruitment_channel();    
})(jQuery);
function init_recruitment_channel(id) {
    load_small_table_item_channel(id, '#campaign_sm_view', 'rec_channel_id', 'recruitment/get_recruitment_channel_data_ajax', '.campaign_sm');
  }
  function load_small_table_item_channel(pr_id, selector, input_name, url, table) {
    "use strict";
    var _tmpID = $('input[name="' + input_name + '"]').val();
    // Check if id passed from url, hash is prioritized becuase is last
    if (_tmpID !== '' && !window.location.hash) {
        pr_id = _tmpID;
        // Clear the current id value in case user click on the left sidebar credit_note_ids
        $('input[name="' + input_name + '"]').val('');
    } else {
        // check first if hash exists and not id is passed, becuase id is prioritized
        if (window.location.hash && !pr_id) {
            pr_id = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
        }
    }
    if (typeof(pr_id) == 'undefined' || pr_id === '') { return; }
    if (!$("body").hasClass('small-table')) { toggle_small_view_campaign(table, selector); }
    $('input[name="' + input_name + '"]').val(pr_id);
    do_hash_helper(pr_id);
    $(selector).load(admin_url + url + '/' + pr_id);
    if (is_mobile()) {
        $('html, body').animate({
            scrollTop: $(selector).offset().top + 150
        }, 600);
    }
}
function toggle_small_view_campaign(table, main_data) {
    "use strict";
    var hidden_columns = [5];
    $("body").toggleClass('small-table');
    var tablewrap = $('#small-table');
    if (tablewrap.length === 0) { return; }
    var _visible = false;
    if (tablewrap.hasClass('col-md-5')) {
        tablewrap.removeClass('col-md-5').addClass('col-md-12');
        _visible = true;
        $('.toggle-small-view').find('i').removeClass('fa fa-angle-double-right').addClass('fa fa-angle-double-left');
    } else {
        tablewrap.addClass('col-md-5').removeClass('col-md-12');
        $('.toggle-small-view').find('i').removeClass('fa fa-angle-double-left').addClass('fa fa-angle-double-right');
    }
    var _table = $(table).DataTable();
    // Show hide hidden columns
    _table.columns(hidden_columns).visible(_visible, false);
    _table.columns.adjust();
    $(main_data).toggleClass('hide');
    $(window).trigger('resize');
}

function duplicate_recruitment_channel(invoker,id){
  "use strict"; 
  if (confirm_delete()) {

      $.post(admin_url + 'recruitment/duplicate_recruitment_channel/'+id).done(function(response) {
        response = JSON.parse(response);

        var table_recruitment_channel = $('table.table-table_recruitment_channel');
        table_recruitment_channel.DataTable().ajax.reload(null, false);

        if(response.status == 'true' || response.status == true){
            alert_float('success', response.message);
        }

    });
  }

}