/** * Created by tlams on 10/11/16. */ $(document).ready(function() { /* MAC ADDR Tooltip */ $('[data-toggle="tooltip"]').tooltip({ 'selector': '', 'placement': 'left', 'container':'body' }); /* ARRAY CONFIGURATION */ $('#dataTables-storages').DataTable( { "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "all"]], "paging": true, "searching": true, "ordering": true, "info": true, responsive: { details: { type: 'inline', target: 'tr' } }, columnDefs: [ { className: 'control', orderable: false, targets: 0 } ], order: [ 1, 'asc' ] } ); $('#dataTables-cluster').DataTable( { "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "all"]], "paging": true, "searching": true, "ordering": true, "info": true, responsive: { details: { type: 'inline', target: 'tr' } }, columnDefs: [ { className: 'control', orderable: false, targets: 0 } ], order: [ 1, 'asc' ] } ); $('#dataTables-hypervisors').DataTable( { "lengthMenu": [[25, 50, 100, 500, -1], [25, 50, 100, 500, "all"]], "paging": true, "searching": true, "ordering": true, "info": true, responsive: { details: { type: 'inline', target: 'tr' } }, columnDefs: [ { className: 'control', orderable: false, targets: 0 } ], order: [ 1, 'asc' ] } ); $('#dataTables-hypervisor').DataTable( { "paging": false, "searching": false, "ordering": false, "info": true, responsive: { details: { type: 'inline', target: 'tr' } }, columnDefs: [ { className: 'control', orderable: false, targets: 0 } ], order: [ 2, 'asc' ] } ); $('.dataTables-vm').DataTable({ "lengthMenu": [[25, 50, 100, 500, -1], [25, 50, 100, 500, "all"]], "paging": true, "searching": true, "ordering": true, "info": true, "pagingType": "simple_numbers", responsive: { details: { type: 'column', target: 'tr' } }, columnDefs: [ { className: 'control', orderable: false, targets: 0 } ], order: [ 1, 'asc' ] } ); $( function() { /* VM GESTION */ var dialog, form, name = $( "#name" ), password = $( "#password" ), allFields = $( [] ).add( name ).add( password ); function sendrequest() { // J'initialise le variable box var box = $('.result'); var action = $( "#action" ); var vmid = $( "#vmid" ); var node = $( "#node" ); var commandinfo = "The status available in the table is not dynamically update, you must wait the next cron rotate.
You can play the status command to have an updated informations"; box.html('
'); $('.selectaction').prop('selectedIndex',0); // Je définis ma requête ajax $.ajax({ // Adresse à laquelle la requête est envoyée url: 'requires/pveaction.php', type : 'POST', data : 'user=' + name.val() + '&password=' + password.val() + '&action=' + action.val() + '&vmid=' + vmid.val() + '&node=' + node.val(), // Le délai maximun en millisecondes de traitement de la demande timeout: 32000, // La fonction à apeller si la requête aboutie success: function (data) { // Je charge les données dans box box.html('
Command return: '+data+'
'+ commandinfo +'
'); }, // La fonction à appeler si la requête n'a pas abouti error: function() { // J'affiche un message d'erreur box.html('
Error: Command failed, try again or contact an true admin.
'); } }); dialog.dialog( "close" ); $("html, body").animate({ scrollTop: $(document).height() }, "slow"); } dialog = $( "#dialog-form" ).dialog({ autoOpen: false, height: 250, width: 350, modal: true, resizable: false, buttons: { "Send": sendrequest, Cancel: function() { dialog.dialog( "close" ); } }, close: function() { form[ 0 ].reset(); allFields.removeClass( "ui-state-error" ); $('.selectaction').prop('selectedIndex',0); } }); form = dialog.find( "form" ).on( "submit", function( event ) { event.preventDefault(); sendrequest(); }); $('.dataTables-vm').on('change', '.selectaction',function() { var jsonout = JSON.parse(this.value.replace(/'/g, '"')); if (jsonout["action"] != "none") { $('#action').val(jsonout["action"]); $('#vmid').val(jsonout["vmid"]); $('#node').val(jsonout["node"]); dialog.dialog( "open" ); } }); /* NODE NON GRATA */ function nongrataswitch(node, action) { // J'initialise le variable box var box = $('.result'); var commandinfo = "This information will be automatic applied in the next update."; box.html('
'); var divid = '#'+node; // Je définis ma requête ajax $.ajax({ // Adresse à laquelle la requête est envoyée url: 'requires/pcmaction.php', type : 'POST', data : 'node=' + node + '&action=' + action, // Le délai maximun en millisecondes de traitement de la demande timeout: 32000, // La fonction à apeller si la requête aboutie success: function (data) { // Je charge les données dans box box.html('
information: ' + commandinfo); if (data == "sw_OFF") $(divid).html(' Nongrataimg'); else if (data == "sw_ON") $(divid).html(' Nongrataimg'); else $(divid).html(':('); }, // La fonction à appeler si la requête n'a pas abouti error: function() { // J'affiche un message d'erreur box.html('
Error: Command failed, try again or contact an administrator.
'); } }); dialog.dialog( "close" ); } $('.nongratalink').click(function() { var node = $(this).attr('node'); var action = $(this).attr('action'); nongrataswitch(node, action); return false; // return false so the browser will not scroll your page }); /* NEWVM -- SEARCH NODES */ form = dialog.find( "form" ).on( "submit", function( event ) { event.preventDefault(); sendrequest(); }); function newvm() { // J'initialise le variable box var box = $('#result'); var cpu = $( "#cpu" ); var ram = $( "#ram" ); var disk = $( "#disk" ); var cluster = $( "#enableClickableOptGroups" ); box.html('

Please wait... can take more than 1 minute
'); $.ajax({ // Adresse à laquelle la requête est envoyée url: 'requires/newvm.php', type : 'POST', data : 'cpu=' + cpu.val() + '&ram=' + ram.val() + '&disk=' + disk.val() + '&cluster=' + cluster.val(), // Le délai maximun en millisecondes de traitement de la demande timeout: 500000, // La fonction à apeller si la requête aboutie success: function (data) { // Je charge les données dans box box.html(data); }, // La fonction à appeler si la requête n'a pas abouti error: function() { // J'affiche un message d'erreur box.html('
Error: Command failed, try again or contact an admin.
'); } }); } $("#buttonnewvm").click(newvm); }); } );