

var select2Opt = {minimumResultsForSearch: -1, dropdownAutoWidth: false, width: '100%'};

function InitSelect2() {
    $('#s2_channel').select2(select2Opt);
}

function InitDatatable() {
    $('#datatable-1').on('xhr.dt', function (e, settings, json) {
        if (typeof (json.data) == 'object') {
            for (var i in json.data) {
                var status = json.data[i].status;
                var claimsCount = json.data[i].sound_counter + json.data[i].video_counter + json.data[i].no_epg + json.data[i].wrong_epg;
                json.data[i].logo = '<img class="img-rounded- channel-logo '+ (json.data[i].logo ? "": "no-logo" )+'" src="' + ( json.data[i].logo ? json.data[i].logo + "?" + $.random(100000) : '{{ app.request_context.baseUrl }}/img/icon-channel-no-logo.svg') + '" alt="">';
                json.data[i].name = '<a href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/edit-channel?id=' + json.data[i].id + '">' + escapeHtml(json.data[i].name) + '</a>';
                // for demo:
                // change data output from time<br>status to status:title=time
                var temp = json.data[i].monitoring_status.split("<br>");
                json.data[i].monitoring_status = temp[1] ? temp[1].replace( '<span', '<span title="'+ temp[0] +'"' ) : temp[0] ;

                json.data[i].genres_name = escapeHtml(json.data[i].genres_name);

                json.data[i].languages = '<div class="nowrap'+ (json.data[i].languages.indexOf(',') != -1 ?" flexible" : "") +'"><span class="">' +json.data[i].languages+ '</span></div>';
                json.data[i].cmd = '<div class="nowrap"><span class="" title="' +json.data[i].cmd+ '">' +json.data[i].cmd+ '</span></div>';

                json.data[i].tv_archive_type = ( json.data[i].tv_archive_type ? '<img class="icon-tv-archive" src="{{app.request_context.baseUrl}}/img/icon-timeshift.svg" alt="'+json.data[i].tv_archive_type+'" title="'+json.data[i].tv_archive_type+'">' : "-" /*'<span class="fa fa-circle-thin"></span>'*/ );
                json.data[i].status = '\
                       <div class="mswitch">\
                            <input type="checkbox" \
                                   id="channel_status_'+ json.data[i].id +'"\
                                   name="form[status]" readonly="readonly" class="form-control" \
                                   ' + ( json.data[i].status ? 'checked="checked"' : '' ) +'\
                                   data-id="' + json.data[i].id + '"\
                                   value="' + ( json.data[i].status ? 'on' : 'off' ) +'">\
                            <label class="label-success" \
                                   title="' + ( json.data[i].status ? "{{ 'Published'|trans }}" : "{{ 'Unpublished'|trans }}" ) + '" \
                                   for="channel_status_'+ json.data[i].id +'"></label>\
                        </div>\
                        ';

                if (claimsCount) {
                    json.data[i].claims = [json.data[i].video_counter, json.data[i].sound_counter, json.data[i].no_epg, json.data[i].wrong_epg].join('/');
                } else {
                    json.data[i].claims = "-/-/-/-";
                }
                json.data[i].operations = '<div class="col-xs-3 col-sm-8 ddd">\n\
                                                <a href="#" class="dropdown-toggle" 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 class="" href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/edit-channel?id=' + json.data[i].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 }}/get-channel-epg-item" data-id="' + json.data[i].id  + '">\n\
                                                            <span>{{ 'Manage EPG'|trans }}</span>\n\
                                                        </a>\n\
                                                    </li>\n\
                                                    <li>\n\
                                                        <a href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/move-channel?channel_id=' + json.data[i].id  + '">\n\
                                                            <span>{{ 'Move'|trans }}</span>\n\
                                                        </a>\n\
                                                    </li>\n\
                                                    '+ (claimsCount ? '\
                                                    <li>\n\
                                                        <a class="main_ajax no_context_menu" ' + (claimsCount ? '': 'disabled="disabled"') + ' href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/itv-reset-claims" data-media_id="' + json.data[i].id  + '" data-media_type="' + json.data[i].media_type  + '">\n\
                                                            <span>{{ 'Reset media-claims'|trans }}</span>\n\
                                                        </a>\n\
                                                    </li>\n' : '' ) + '\
                                                    <li>\n\
                                                        <a class="main_ajax no_context_menu" href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/' + (status ? 'disable' : 'enable') + '-channel" data-id="' + json.data[i].id  + '">\n\
                                                            <span>' + (status ? "{{ 'Unpublish'|trans }}" : "{{ 'Publish'|trans }}") + '</span>\n\
                                                        </a>\n\
                                                    </li>\n\
                                                    <li>\n\
                                                        <a class="main_ajax no_context_menu" href="{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/remove-channel" data-id="' + json.data[i].id  + '">\n\
                                                            <span>{{ 'Delete'|trans }}</span>\n\
                                                        </a>\n\
                                                    </li>\n\
                                                </ul>\n\
                                            </div>';

            }
        }
    }).dataTable({
        "processing": true,
        "serverSide": true,
        "ajax": {
            "url": "{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/iptv-list-json"
        },
        "language": {
            "url": "{{ app.datatable_lang_file }}"
        },
        "bFilter": true,
        "lengthChange": true,
        "bPaginate": true,
        "bInfo":     true,

        fixedHeader: {
            header: true,
            headerOffset: $('header.navbar').height()
        },
		select: {
            style:    'multi',
            selector: 'td.select-checkbox'
        },
        rowId: "RowOrder", // required to restore selected rows on reload
        //"pagingType": "full_numbers",
        
        // modify the sDom param from dataTables.bootstrap.js
        "sDom": "<'clearfix'<'pull-right'fAV><'button-place'B>>rt<'row-fluid'<'col-md-4 no-padding'i><'col-md-8 no-padding'pl>>",
        bAutoWidth: false,
        
        //from macro
        "columns": [
            // be sure to change col indexes at aoColumnDefs if added
            { "data": null, defaultContent: "", orderable: false, /*visible: true,*/ className: 'w-1p select-checkbox'},
        {% for key, item in app['dropdownAttribute'] %}
            {% if 'all' != item.name %}
            {"data": "{{ item.name }}", /**/ "name": "{{ item.name }}" {% if not(item.checked) %}, visible: false, className: 'none'{% endif %}}{% if not loop.last %},{% endif %}
            {% endif %}
        {% endfor %}
        ],

        /* Before shift: 
        "aoColumnDefs": [ 
            { "targets": [ -1 ], "sortable": false},
            { "searchable": false, "targets": [ 2, 4, 5, 8, 9, 10, 11] },
            { "sortable": false, "targets": [8, 11] },
            { className: "w-1p dt-center",  "targets": [ 1 ] },
            //{ className: 'dt-right', orderable: false, targets: [0] },
            { className: "w-1p dt-right",  "targets": [ 2 ] },
            //{ className: "dt-nowrap", "targets": [ 3, 6 ] },
            { className: "dt-center", "targets": [ 7 ] },
            { className: "dt-status", "targets": [ -3 ] },
            { className: "action-menu", "targets": [ -1 ] }
        ]*/

        "order": [[ 2, "asc" ]], // set the Dafault oder column. works OK when table state is saved and loaded
        "aoColumnDefs": [ 
            //{ "targets": [ -1 ], "sortable": false },
            { "searchable": false, "targets": [ 0, 3, 5, 6, 8, 10, 11, 12, -1 ] },
            { "sortable": false, "targets": [ 0, 6, 10, -1 ] },
            { className: "w-1p dt--center",  "targets": [ 1 ] },
            { className: "w-1p dt--right",  "targets": [ 2 ] },
            { className: "tv-lang", "targets": [ 6 ] },
            { className: "dt-center", "targets": [ 8 ] },
            { className: "dt-status", "targets": [ -3 ] },
            { className: "action-menu", "targets": [ -1 ] }
        ],


        // remove column.visible from stateSave 
        // the DT was applying the column visibility setting from stateSave after dropdown filter
        "stateSaveParams": function (settings, data) {
                                
                                data.columns.forEach(
                                    function(item) {
                                        item.visible = null;
                                        delete item.visible;
                                });
                                //console.log( data.columns );
                            },


        "buttons": [
            
            // Ganre button
            {
                //text: '<i class="fa fa-th-list fa-tag-"></i> {{'Change genre'|trans }}',
                text: '<i class="fa fa-th-list fa-tag-"></i> {{'Genre'|trans }}',
                action: function ( e, dt, node, config ) {
                    e.stopPropagation();
                    e.preventDefault();
                    JScloseModalBox();
                    $('#modalbox').find('.modal-header-name').html("<span class='text-default'>{{ 'Change tv-genre'|trans }}</span>");
                    $('#modalbox').find('.devoops-modal-inner').html($("#change_channel_genre_template").html());
                    $('#modalbox').find('.devoops-modal-bottom').html($("#modal_form_button_template").html());
                    $('#tv_genre_id').select2(select2Opt);

                    // if parameter "rowId": not set use this:
                    //console.log( dt.rows( { selected: true } ).data().toArray().map( function(tr) { return tr.RowOrder.replace("dTRow_","") }).toString() );
                    var ids = dt.rows( { selected: true } ).ids().toArray().toString().replace(/dTRow_/g,"");
                    $('#modalbox').find('.devoops-modal-inner').find("input[name='id']").val( ids );
                    $("#group_action_form").attr('action', "{{app.request_context.baseUrl}}/{{ app.controller_alias }}/change-channel-genre" );

                    $('#modalbox').show();
                }
            },

            // Language button
            {
                //text: '<i class="fa fa-language"></i> {{'Change language'|trans }}',
                text: '<i class="fa fa-language"></i> {{'Language'|trans }}',
                action: function ( e, dt, node, config ) {
                    e.stopPropagation();
                    e.preventDefault();
                    JScloseModalBox();
                    $('#modalbox').find('.modal-header-name').html("<span class='text-default'>{{ 'Change language'|trans }}</span>");
                    $('#modalbox').find('.devoops-modal-inner').html($("#change_channel_language_template").html());
                    $('#modalbox').find('.devoops-modal-bottom').html($("#modal_form_button_template").html());
                    $('#s2_languages').select2(select2Opt);

                    // if parameter "rowId": not set use this:
                    //console.log( dt.rows( { selected: true } ).data().toArray().map( function(tr) { return tr.RowOrder.replace("dTRow_","") }).toString() );
                    var ids = dt.rows( { selected: true } ).ids().toArray().toString().replace( /dTRow_/g, "" );
                    $('#modalbox').find('.devoops-modal-inner').find("input[name='id']").val( ids );
                    $("#group_action_form").attr('action', "{{app.request_context.baseUrl}}/{{ app.controller_alias }}/change-channel-language" );

                    $('#modalbox').show();
                }
            },
            
            // Switch on/off
            {   
                extend: 'collection',
                // params are described here:
                // https://datatables.net/reference/button/collection
                text: '<i class="fa fa-toggle-on"></i> {{ 'Switch on/off'|trans }} <i class="fa fa-caret-down"></i>',
                autoClose: true,
                background: true,
                //backgroundClassName: "dt-button-background",
                fade: 0, // speed 
                buttons: [
                    {
                        text: '{{ 'Switch on'|trans }}',
                        action: function ( e, dt, node, config ) {
                            e.stopPropagation();
                            e.preventDefault();
                            JScloseModalBox();
                            
                            var sendData = {};
                            var ids = dt.rows( { selected: true } ).ids().toArray().toString().replace(/dTRow_/g, "" );
                            sendData.group_key = "id";
                            sendData.id = ids;

                            if ((sendData.id).search(',') != -1){
                                sendData.id = JSON.stringify(sendData.id.split(','));
                            }

                            ajaxPostSend( "{{app.request_context.baseUrl}}/{{ app.controller_alias }}/enable-channel", sendData, false, false, true);
                            
                        }
                    },
                    {
                        text: '{{ 'Switch off'|trans }}',
                        action: function ( e, dt, node, config ) {
                            e.stopPropagation();
                            e.preventDefault();
                            JScloseModalBox();

                            var sendData = {};
                            var ids = dt.rows( { selected: true } ).ids().toArray().toString().replace( /dTRow_/g, "" );
                            sendData.group_key = "id";
                            sendData.id = ids;

                            if ((sendData.id).search(',') != -1){
                                sendData.id = JSON.stringify(sendData.id.split(','));
                            }

                            ajaxPostSend( "{{app.request_context.baseUrl}}/{{ app.controller_alias }}/disable-channel", sendData, false, false, true);

                        }
                    }
                ]
            },

            // Delete button
            {
                //text: '<i class="fa fa-trash fa-trash-o-"></i> {{'Delete channel'|trans }}',
                text: '<i class="fa fa-trash fa-trash-o-"></i> {{'Delete'|trans }}',
                //titleAttr: "Yes! We have title !",
                //className: 'dt-button-delete',
                action: function ( e, dt, node, config ) {
                    
                    if( $(this).hasClass('disabled') )
                        return false;
                    
                    e.stopPropagation();
                    e.preventDefault();
                    JScloseModalBox();

                    var tr = dt.rows( { selected: true } )
                    var sendData = {};
                    var ids = dt.rows( { selected: true } ).ids().toArray().toString().replace(/dTRow_/g, "" );
                    
                    if( confirm("{{'Are you sure you want to delete'|trans }} " +tr.count()+ " {{'channel(s)'|trans }} ?\n{{'Undo this action will be impossible'|trans }}!") ) {
                        /*
                        dt.rows( { selected: true } ).remove();
                        dt.ajax.reload();
                        resetTableButtons();
                        */
                        sendData.group_key = "id";
                        sendData.id = ids;

                        if ((sendData.id).search(',') != -1){
                            sendData.id = JSON.stringify(sendData.id.split(','));
                        }

                        ajaxPostSend( "{{app.request_context.baseUrl}}/{{ app.controller_alias }}/remove-channel", sendData, false, false, true);
                        resetTableButtons();
                        setGroupSelectState( "none" );
                    }
                    return false;
                }
            }
        ]
    }).prev('.dataTables_processing').hide('');
}

function yelp() {
    $(document).ready(function () {

        LoadDataTablesScripts(InitDatatable);
        LoadSelect2Script(InitSelect2);
        

        var table = $('#datatable-1').DataTable();
        // for this task
        // see https://datatables.net/extensions/buttons/examples/api/enable.html
        table
            .on( 'select', function ( e, dt, type, indexes ) {
                //var rowData = table.rows( indexes ).data().toArray();
                //events.prepend( '<div><b>'+type+' selection</b> - '+JSON.stringify( rowData )+'</div>' );

                var rows = dt.rows( { selected: true } ).count();
                
                $(".dt-buttons .dt-button").show().removeClass( "disabled" );

                if ( rows == dt.rows().count() ){
                    setGroupSelectState( "all" );
                } else {
                    setGroupSelectState( "some" );
                }
                /*
                if ( rows == 1 ) {
                    $(".dt-buttons .dt-button").removeClass( "disabled" );
                } else {
                    $(".dt-buttons .dt-button").addClass( "disabled" );
                    $(".dt-buttons .dt-button-delete").removeClass( "disabled" );
                }
                */
            } )
            .on( 'deselect', function ( e, dt, type, indexes ) {
                //var rowData = table.rows( indexes ).data().toArray();
                //events.prepend( '<div><b>'+type+' <i>de</i>selection</b> - '+JSON.stringify( rowData )+'</div>' );

                var rows = dt.rows( { selected: true } ).count();
                
                if ( rows >= 1 ) {
                    $(".dt-buttons .dt-button").show().removeClass( "disabled" );
                    setGroupSelectState( "some" );
                } else if ( rows == 0 ) {
                    setGroupSelectState( "none" );
                    resetTableButtons();
                }

            } )

            // expand Processing width for overflow table
            .on( 'processing.dt', function ( e, settings, processing ) {
                $(settings.aanFeatures.r).css( 'width', $(settings.aanFeatures.t).width() );
            } );


            // reset Buttons on Paging reload 
            $('#datatable-1').on( 'page.dt', function () {
                resetTableButtons( );
                setGroupSelectState( "none" );
            } );

            // Reinit group actions Table Buttons
            $('#datatable-1').on( 'draw.dt', function ( e, settings ) {
                if( table.rows( { selected: true } ).ids().length == 0 ) {
                    resetTableButtons(); 
                    setGroupSelectState('none');
                }
            } );


        // Select dropdowns 
        $( "#select_all" ).click( function(e){
            if( !$(this).hasClass("disabled") ) {
                table.rows().select();
            }
        });

        $( "#select_none" ).click( function(e){
            if( !$(this).hasClass("disabled") ) {
                table.rows().deselect();
            }
        });

        $( "#select_inverse" ).click( function(e){
            if( !$(this).hasClass("disabled") ) {
                var rowsSelected = table.rows( { selected: true } );
                table.rows().select();
                rowsSelected.deselect();
            }
        });

        // Disable annoying message on disabled buttons
        $(document).off('click', "a[disabled], a.disabled");

        setTimeout( initTableButtons, 200 );

        $(document).on('change', ".mswitch input", function(e){
            //value = ( json.data[i].status ? 'on' : 'off' )
            var status = $(this).attr( 'value' ) == 'on' ? true : false;
            //var msg = "Канал "+ $(this).data().id +": "+ (status ? 'Отключен':'Включен' );
            ajaxPostSend('{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/' + (status ? 'disable' : 'enable') + '-channel', $(this).data() );
        });


        $(".datepicker").datepicker({
            language    : '{% if attribute(app, 'locale') is defined and app['locale']|length == 2 %}{{ app['locale'] }}{% else %}en{% endif %}',
            dateFormat  : 'dd-mm-yy',
            firstDay    : 1,
            showOn: "both",
            showAnim: "slideDown",
            buttonImage: "{{app.request_context.baseUrl}}/img/calendar.gif",
            buttonImageOnly: true,
            buttonText: "{{ 'Select date'|trans }}",

            dayNamesMin : [
                '{{ 'Sun'|trans }}',
                '{{ 'Mon'|trans }}',
                '{{ 'Tue'|trans }}',
                '{{ 'Wed'|trans }}',
                '{{ 'Thu'|trans }}',
                '{{ 'Fri'|trans }}',
                '{{ 'Sat'|trans }}'
            ],
            monthNames  : [
                '{{ 'January'|trans }}',
                '{{ 'February'|trans }}',
                '{{ 'March'|trans }}',
                '{{ 'April'|trans }}',
                '{{ 'May'|trans }}',
                '{{ 'June'|trans }}',
                '{{ 'July'|trans }}',
                '{{ 'August'|trans }}',
                '{{ 'September'|trans }}',
                '{{ 'October'|trans }}',
                '{{ 'November'|trans }}',
                '{{ 'December'|trans }}'
            ]
        });

        $(document).on('click', "a.main_ajax", function (e) {
            e.stopPropagation();
            e.preventDefault();
            ajaxPostSend($(this).attr('href'), $(this).data());
            $(this).closest('div.open').removeClass('open');
            return false;
        });

        $(document).on('change', "#s2_channel", function(e){
            ajaxPostSend("{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/get-channel-epg-item?id=" + $(this).val(), {});
        });

        $(document).on('click', "#get_epg_button", function(e){
            e.stopPropagation();
            e.preventDefault();
            if ($("#s2_channel").val()) {
                ajaxPostSend("{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/get-channel-epg-item?id=" + $("#s2_channel").val(), {epg_date : $("#epg_date").val()});
            } else {
                JSErrorModalBox({msg: "{{ 'Channel not selected'|trans }}"})
            }
        });

        $("#modalbox_ad").on('click', "button[type='submit']", function(e){
            var sendData = {id:0, epg_data:'', epg_body: ''};
            sendData.id = $("#s2_channel").val();
            sendData.epg_date = $("#epg_date").val();
            sendData.epg_body = $("#epg_body").val();
            ajaxPostSend($('#epg_form').attr('action'), sendData);
        });

        $(document).on('click', '#restart_archives_button', function(e){
            e.stopPropagation();
            e.preventDefault();
            JSshowModalBox();
            ajaxPostSend($(this).attr('href'), {}, false, false, true);
            return false;
        });

        $("#datatable-1").on('click', "a[href$='itv-reset-claims']", function(e){
            e.stopPropagation();
            e.preventDefault();
            if ($(this).attr("disabled")) {
                JSErrorModalBox({msg: "{{ 'This action is unavailable'|trans }}"})
            } else {
                $(this).closest('.open').removeClass("open");
                $("#modalbox").data('complete', 1);
                $('#modalbox').find('.devoops-modal-header').html("\n\
                            <div class='row'>\n\
                                <div class='col-xs-10 col-sm-10'>\n\
                                    <span class='text-default'>{{ 'Reset claims counter'|trans }}</span>\n\
                                </div>\n\
                            </div>");
                $('#modalbox').find('.devoops-modal-inner').html("\n\
                            <div class='row'>\n\
                                <div class='col-xs-10 col-sm-10'>\n\
                                    <span>{{ 'Do you really want to reset claims counter?'|trans }}</span>\n\
                                </div>\n\
                            </div>");
                $('#modalbox').find('.devoops-modal-bottom').html("\n\
                            <div class='col-xs-10 col-sm-6 pull-right'>\n\
                                <button type='submit' id='reset_claims_counter' class='btn btn-success col-sm-5 pull-right'>{{ 'Reset'|trans }}</button>\n\
                                <button type='reset' class='btn btn-default col-sm-5 pull-left' >{{ 'Cancel'|trans }}</button>\n\
                            </div>");
                $("#reset_claims_counter").data($(this).data());
                $('#modalbox').show();
            }
            return false;
        });

        $(document).on('click', '#reset_claims_counter', function(e){
            $('#modalbox').hide();

            ajaxPostSend("{{ app.request_context.baseUrl }}/{{ app.controller_alias }}/itv-reset-claims", { media_id: $(this).data("media_id"), media_type: $(this).data("media_type")}, false, false);
        });

        $(document).on('click', '#save_channel', function(e){
            e.stopPropagation();
            e.preventDefault();
            var sendData = {};
            $("input, select", "#modalbox").filter('.own_fields').each(function(){
                sendData[$(this).attr('name')] = $(this).val();
            });

            if (('' + sendData.id).search(',') != -1){
                sendData.id = JSON.stringify(sendData.id.split(','));
            }

            JScloseModalBox();
            ajaxPostSend($("#group_action_form").attr('action'), sendData, false, false, true);
        });
    });
}

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

function showModalBox(data){
    fillEPGForm(data);
    $("#modalbox_ad").show();
}

function fillEPGForm(data){
    $('#s2_channel option[value="'+data.ch_id+'"]').prop('selected', 'selected');
    $('#s2_channel').select2(select2Opt);
    $("#epg_date").removeAttr('disabled').datepicker( "setDate", data.epg_date);
    $("#epg_body").val(data.epg_body);
}

function initTableButtons() { 
    //$(".dataTables_wrapper .dt-buttons .dt-button").hide();
    $(".dt-group-select-dropdown").prependTo( $(".dataTables_wrapper .dt-buttons").first() );

    resetTableButtons();
}
function resetTableButtons() { 
    $(".dt-buttons .dt-button").not(".dt-group-select-dropdown .dt-button").addClass( "disabled" ).hide();
}
function setGroupSelectState(state) {
    if ( typeof state != "string" ){
        return;
    }

    $(".dt-group-select-dropdown").removeClass( "all none some" ).addClass( state );
    
    $("#select_all, #select_none, #select_inverse").removeClass( "disabled" );
        
        switch( state ) {
    
    case "none": $("#select_none, #select_inverse").addClass( "disabled" );
                 break;

    case "all":  $("#select_all").addClass( "disabled" );
                 break;
    
    }
}

var saveEPGSuccess = function(){
    JSSuccessModalBox();
};

var saveEPGSuccessError = function(){
    JSErrorModalBox();
};

var restartArchive = function(data){
    $("#modalbox").data('complete', 1);
    $('#modalbox').find('.devoops-modal-inner').html('<span>{{ 'Done'|trans }}! ' + (data.msg ? data.msg : '') +  '</span>');
};

var restartArchiveError = function(data){
    $('#modalbox').find('.devoops-modal-inner').html('<span>{{ 'Error'|trans }}! ' + (data.error? data.error: '') +  '</span>');
    $("#modalbox").data('complete', 1);
};
