
        function InitDatatable() {
            $('#datatable-1').on('xhr.dt', function (e, settings, json) {
                if (typeof (json.data) == 'object') {
                    for (var i in json.data) {
                        var id = json.data[i].id;
                        var status = json.data[i].status;
                        var name = json.data[i].name;
                        var tracks = json.data[i].tracks_count;

                        json.data[i].operations = "<div class='col-xs-3 col-sm-8'>\n\
                                                        <a href='#' class='dropdown-toggle no_context_menu' data-toggle='dropdown'>\n\
                                                            <i class='pull-right fa fa-cog'></i>\n\
                                                        </a>\n\
                                                        <ul class='dropdown-menu pull-right'>\n\
                                                            <li>\n\
                                                                <a href='{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/edit-audio-albums?id=" + id + "'>\n\
                                                                    <span>{{ 'Edit'|trans }}</span>\n\
                                                                </a>\n\
                                                            </li>\n\
                                                            <li>\n\
                                                                <a class='main_ajax no_context_menu' href='{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/toggle-audio-albums' data-albumsid='" + id + "' data-albumsstatus='" + status + "'>\n\
                                                                    <span>" + (status != 0 ? "{{ 'Unpublish'|trans }}" : "{{ 'Publish'|trans }}") + "</span>\n\
                                                                </a>\n\
                                                            </li>\n\
                                                            <li>\n\
                                                                <a class='remove-audio-albums no_context_menu'  data-albumsid='" + id + "'>\n\
                                                                    <span>{{ 'Delete'|trans }}</span>\n\
                                                                </a>\n\
                                                            </li>\n\
                                                        </ul>\n\
                                                    </div>";
                        
                        //json.data[i].status = status != 0 ? "<span class=''>{{ 'Published'|trans }}</span>" : "<span class=''>{{ 'Unpublished'|trans }}</span>";
                        json.data[i].status = '\
                           <div class="mswitch">\
                                <input type="checkbox" \
                                       id="album_status_'+ json.data[i].id +'"\
                                       name="form[status]" readonly="readonly" class="form-control" \
                                       ' + ( json.data[i].status != 0 ? 'checked="checked"' : '' ) +'\
                                       data-albumsid="' + json.data[i].id + '"\
                                       data-albumsstatus="' + json.data[i].status +'">\
                                <label class="label-success" \
                                       title="' + ( json.data[i].status != 0 ? "{{'Published'|trans}}" : "{{'Unpublished'|trans}}" ) + '" \
                                       for="album_status_'+ json.data[i].id +'"></label>\
                            </div>';

                        json.data[i].name = '<a href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/edit-audio-albums?id=' + id + '" >' +escapeHtml( name )+ '</a>';
                        json.data[i].year = escapeHtml( json.data[i].year );
                        json.data[i].ganre_name = escapeHtml( json.data[i].ganre_name );
                        json.data[i].language = escapeHtml( json.data[i].language );
                        json.data[i].tracks_count = '<a href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/edit-audio-albums?id=' + id + '&step=2" >' + tracks + '</a>';
                    }
                }
            }).dataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {
                    "url": "{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/audio-albums-list-json"
                },
                "language": {
                    "url": "{{ app.datatable_lang_file }}"
                },
                {% if attribute(app, 'dropdownAttribute') is defined %}
                {{ main_macro.get_datatable_column(app['dropdownAttribute']) }}
                {% endif %}
                "bFilter": true,
                "bPaginate": true,
                "lengthChange": true,
                "bInfo": true,
                
                "fixedHeader": {
                    header: true,
                    headerOffset: $('header.navbar').height()
                },

                "columnDefs": [
                    { className: "action-menu", "targets": [ -1 ] },
                    {"searchable": false, "targets": [-1, -3, -2, 2]},
                    {"sortable": false, "targets": [-1, -3, 2]},
                    {"className": "data-filter-status", "targets": [-2]}
                ]
            }).prev('.dataTables_processing').hide('');
        }

        function yelp() {
            $(document).ready(function () {
                $(document).on('click', "a.main_ajax", function (e) {
                    e.stopPropagation();
                    e.preventDefault();
                    var _this = this;
                    var sendData = $(_this).data();
                    if ($(_this).attr("disabled")) {
                        JSErrorModalBox({msg: "{{ 'Action is not available'|trans }}! " + ($(_this).attr('warning_msg') ? $(_this).attr('warning_msg') : '')});
                    } else {
                        ajaxPostSend($(_this).attr('href'), sendData, false );
                    }
                    $(this).closest('div.open').removeClass('open');
                    return false;
                });

                $(document).on('click', "a.remove-audio-albums", function (e) {
                    e.stopPropagation();
                    e.preventDefault();
                    var _this = this;
                    if ($(_this).attr("disabled")) {
                        JSErrorModalBox({msg: "{{ 'Action is not available'|trans }}! " + ($(_this).attr('warning_msg') ? $(_this).attr('warning_msg') : '')});
                        return false;
                    }
                    JScloseModalBox();
                    $('#modalbox').find('.modal-header-name span').addClass('txt-danger').text('{{ 'Warning'|trans }}' + '!');
                    $('#modalbox').find('.devoops-modal-inner').html($("#modal_del_body").text());
                    $('#modalbox').find('.devoops-modal-bottom').html($("#modal_del_buttons").text());

                    $('#del_album_btn').data($(_this).data());

                    $('#modalbox').show();
                    $(this).closest('div.open').removeClass('open');
                    return false;
                });

                $(document).on('change', ".mswitch input", function(e){
                    ajaxPostSend('{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/toggle-audio-albums', $(this).data() );
                });

                // stop sending Form on Enter press:
                $(document).on('keyup keypress', 'form input[type="text"]', function(e) {
                    if(e.which == 13) {
                        e.preventDefault();
                        e.stopPropagation();
                        return false;
                    }
                });

                LoadDataTablesScripts(InitDatatable);
            });
        }

        document.addEventListener("DOMContentLoaded", yelp, false);

        function closeModalBox() {
            $("#modalbox").hide();
            $('#modalbox').find('.modal-header-name span').removeClass('txt-danger').empty();
            $('#modalbox').find('.devoops-modal-inner').empty();
            $('#modalbox').find('.devoops-modal-bottom').empty();
        }
