% aoData = [] unless local_assigns.key? :aoData %>
<% initial_size = 25 unless local_assigns.key? :initial_size %>
<% table_views = { table: true, grid: false } unless local_assigns.key? :table_views %>
<% table_filters = [] unless local_assigns.key? :table_filters %>
<% sort = [[0, 'asc']] unless local_assigns.key? :sort %>
<% defer_loading = false unless local_assigns.key? :defer_loading %>
<% quick_loading = false unless local_assigns.key? :quick_loading %>
<% debug = false unless local_assigns.key? :debug %>
<% content_for :scripts do %>
getTableParams(
'<%= table_name %>',
{
columns: <%= raw columns.to_json %>,
filters: <%= raw table_filters.to_json %>,
view: '<%= table_views.select { |k, v| v == true }.first[0].to_s %>',
size: <%= initial_size %>,
sort: <%= raw sort %>
},
create<%= table_name %>Table
);
function create<%= table_name %>Table(columns, view, size, sort) {
$.each(columns, function(key1, column) {
$.each(column, function(key2, value) {
if(key2 == 'render') {
columns[key1][key2] = new Function('data', 'type', 'row', value);
};
<% if defined?(table_group_actions) && table_group_actions.present? %>
if(key2 == 'data' && value == 'actions'){
columns[key1]['title'] = '';
};
<% end %>
});
});
$('#<%= table_name %>_content').contextMenu({
selector: '#<%= table_name %>_group_actions, #<%= table_name %>_actions',
trigger: 'left',
zIndex: 10,
callback: function(id, options) {
array = id.split('::');
object_ids = []
$.each(<%= table_name %>.api().rows({ selected: true }).ids(), function(key, value) {
object_ids.push(value);
})
if(array[1].includes('?')){
ExecuteRemoteJS(array[0], array[1].concat('&' + jQuery.param({ids: object_ids})));
}else{
ExecuteRemoteJS(array[0], array[1].concat('?' + jQuery.param({ids: object_ids})));
}
},
build: function($trigger, e) {
var items = ($(e.target).data('items') == null) ? $(e.target).parent().first().data('items') : $(e.target).data('items') ;
return {
items: items
};
}
});
/* Debounce Draw Function */
var <%= table_name %>_draw = debounce(function() {
if($('#<%= table_name %>_content').is(":visible") && !$('#<%= table_name %>_refresh').hasClass('zc-spin') && !document.hidden) {
return $("#<%= table_name %>").DataTable().draw(false);
}
}, 4000);
var <%= table_name %> = $('#<%= table_name %>').dataTable({
"sDom": "<'table-scroll-wrapper't><'grid_view'><'table-footer'i<'#<%= table_name %>_select_container.select_container'>p>",
"pagingType": "<%= quick_loading ? 'simple' : 'full_numbers' %>",
"language" : {
"paginate" : {
"previous" : "chevron_left",
"next" : "chevron_right"
},
"info": "Showing",
"infoEmpty": "Showing",
"infoFiltered": ""
},
"bProcessing": true,
"bServerSide": true,
"bInfo": true,
"colReorder": true,
<% if defined?(table_group_actions) && table_group_actions.present? %>
"select": { style: 'multi'},
<% end %>
"columns": [].concat(columns),
"aaSorting": sort,
"sAjaxSource": $('#<%= table_name %>_content table.datatable').data('source'),
<% if defer_loading %>
"deferLoading": 0,
<% end %>
"iDisplayLength": size,
"fnServerParams": function ( aoData ) {
aoData.push(
{ "name": "table_view_mode", "value": getTableViewMode('<%= table_name %>', view) },
{ "name": "sSearch", "value": $('#<%= table_name %>_search').val() },
{ "name": "table_quick_load", "value": "<%= quick_loading ? 'simple' : 'full_numbers' %>"}
);
<% if !aoData.blank? %>
<% aoData.each do |data| %>
aoData.push(<%= raw(data.to_json) %>);
<% end %>
<% end %>
<% if defined?(table_filters) %>
<% table_filters.each do |table_filter| %>
<% if table_filter["type"] == "checkbox" %>
aoData.push({ "name": "<%= zuo_parameterize(table_filter["name"]) %>", "value": $('#<%= table_name %>_content input[name="<%= zuo_parameterize(table_filter["name"]) %>[]"]:checked').map(function(_, el) { return $(el).val()}).get() });
<% elsif table_filter["type"] == "boolean" %>
aoData.push({ "name": "<%= zuo_parameterize(table_filter["name"]) %>", "value": $('#<%= table_name %>_content input[name="<%= zuo_parameterize(table_filter["name"]) %>"]:checked').val() });
<% elsif ["select", "group-select"].include?(table_filter["type"]) %>
aoData.push({ "name": "<%= zuo_parameterize(table_filter["name"]) %>", "value": $('#<%= table_name %>_content select[name="<%= zuo_parameterize(table_filter["name"]) %>"]').val() });
<% end %>
<% end %>
<% end %>
},
"fnDrawCallback": function(oSettings) {
$('#<%= table_name %>_content').find('.table [rel="status_popover"], .table[data-rel="status_popover"]').popover({ placement: "left", html: 'true', container: '.table'});
$('#<%= table_name %>_content').find('.table [data-toggle="tooltip"]').tooltip();
$('#<%= table_name %>_content .grid_view').addClass('hidden');
$('#<%= table_name %>_content table.datatable').addClass("hidden");
if (oSettings.oAjaxData.table_view_mode === 'grid') {
$('#<%= table_name %>_content .grid_view').html('');
$.each(oSettings.aoData, function(index, result) {
$('#<%= table_name %>_content .grid_view').append(result._aData.grid_view);
});
if (oSettings.aoData.length == 0) {
$(".login_grid").append("" + oSettings.oLanguage.sEmptyTable + "
")
}
$('#<%= table_name %>_content .grid_view').removeClass('hidden');
} else if (oSettings.oAjaxData.table_view_mode === 'table') {
$('#<%= table_name %>_content table.datatable').removeClass("hidden");
}
<%= table_name %>.find('input[type="checkbox"].select_row').on('click', function(e) {
if($('#<%= table_name %>_select_all').is(':checked')) {
$('#<%= table_name %>_select_all').prop("checked", false);
}
});
if (<%= table_name %>.find('tr[processing="true"]').length > 0 && <%= table_name %>.is(":visible")) {
<%= table_name %>_draw();
}
if (<%= table_name %>.find('tr[processing="true"]').length > 0 && $('#<%= table_name %>_wrapper .grid_view').is(":visible")) {
<%= table_name %>_draw();
}
resize_iframe();
/* Hide group actions and deselect */
$('#<%= table_name %>_select_all span').removeClass('z-icon-subtraction').addClass('z-icon-addition');
$('#<%= table_name %>_group_actions').addClass('hidden');
},
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
data = aoData;
if ( data && $.isArray(data) ) {
var tmp = {};var rbracket = /(.*?)\[\]$/;
$.each( data, function (key, val) {
var match = val.name.match(rbracket);
if ( match ) {var name = match[0];if ( ! tmp[ name ] ) {tmp[ name ] = [];}tmp[ name ].push( val.value );}else {tmp[val.name] = val.value;}
});
data = tmp;
}
<% if debug %>console.log(fnCallback); console.log(oSettings);console.log(data);<% end %>
oSettings.jqXHR = $.ajax({"dataType": 'json', "url": sSource, "data": data, "success": fnCallback,"error": function (textStatus, errorThrown) {
if (textStatus.status == 400 || textStatus.status == 302 ) {
window.location.replace("/");
} else if (textStatus.status == 500 ) {
$('#<%= table_name %>_refresh').removeClass('zc-spin');
alert('Table Server Error: <%= table_name %> Contact Support: ' + errorThrown);
} else if (textStatus.status == 502 ) {
$('#<%= table_name %>_refresh').removeClass('zc-spin');
} else {
window.location.replace("/");
};
}});
}
}).on('draw.dt', function() {
<% if debug %> console.log('Drawing Trigger <%= table_name %>'); <% end %>
}).on('processing.dt', function(e, settings, processing) {
$('#<%= table_name %>_refresh').toggleClass('zc-spin', processing);
});
initTable(
<%= table_name %>.api(),
'<%= table_name %>',
{ view, size },
columns,
<%= raw table_filters.to_json %>
);
}
<% end %>