/**
 * Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */
jQuery(function() {
    console.log('ready!!!');
    
    //var mainAction = '/modules/plesk-lvemanager/index.php/send-request';
    //var mainActionForUser = '/modules/plesk-lvemanager/index.php/send-client-request';
    
    

    var sendRequest = function (url, data) {
        jQuery.ajax({
            url : url,
            data : data,
            dataType : 'json',
            type : 'post',
            success : function(json) {
                console.log(json)
            },
            error: function(xhr, ajaxOptions, thrownError) {
                console.log(xhr.statusText, xhr.responseText);
            }
        });
    };

    //Buttons for admin
    jQuery('#button1').click(function(){
        sendRequest(mainAction, {
            'command': 'cloudlinux-limits'
        });
    });

    jQuery('#button2').click(function(){
        sendRequest(mainAction, {
            'command': 'cloudlinux-limits',
            'method': 'get',
            'params': {'username': 'user1'}
        });
    });

    jQuery('#button3').click(function(){
        sendRequest(mainAction, {
            'command': 'cloudlinux-limits',
            'method': 'set',
            'params': {
                'username': 'user1',
                'iops': Number(jQuery('#iops3').val()),
                'io': Number(jQuery('#io3').val())
            }
        });
    });

    jQuery('#button4').click(function(){
        sendRequest(mainAction, {
            'command111': 'cloudlinux-limits'
        });
    });

    jQuery('#button5').click(function(){
        sendRequest(mainAction, {
            'command': 'cloudlinux-top',
            'params': {'max': 100}
        });
    });

    jQuery('#button6').click(function(){
        sendRequest(mainAction, {
            'command': 'cloudlinux-limits',
            'params': {'username': 'unknown_user'}
        });
    });

    //Buttons for client
    jQuery('#button11').click(function(){
        sendRequest(mainActionForUser, {
            'command': 'cloudlinux-limits'
        });
    });

    jQuery('#button12').click(function(){
        sendRequest(mainActionForUser, {
            'command': 'cloudlinux-limits',
            'params': {'username': 'USER'}
        });
    });

    jQuery('#button13').click(function(){
        sendRequest(mainActionForUser, {
            'command': 'cloudlinux-limits',
            'method': 'get',
            'params': {'help':''}
        });
    });

    jQuery('#button14').click(function(){
        sendRequest(mainActionForUser, {
            'command': 'cloudlinux-limits',
            'params': {
                'lve-id': 'UID',
                'json': ''
            }
        });
    });

    jQuery('#button15').click(function(){
        sendRequest(mainActionForUser, {
            'command': 'cloudlinux-limits',
            'method': 'set',
            'params': {
                'iops': Number(jQuery('#iops15').val()),
                'io': Number(jQuery('#io15').val())
            }
        });
    });

});