diff --git a/lib/Ravada/Front.pm b/lib/Ravada/Front.pm index 62fba02a7..9263e4443 100644 --- a/lib/Ravada/Front.pm +++ b/lib/Ravada/Front.pm @@ -212,6 +212,7 @@ sub _get_clone_info($user, $base, $clone = Ravada::Front::Domain->open($base->{i ,is_active => $clone->is_active ,screenshot => $clone->_data('screenshot') ,date_changed => $clone->_data('date_changed') + ,autostart=> $clone->_data('autostart') }; $c->{can_hibernate} = ($clone->is_active && !$clone->is_volatile); diff --git a/public/js/admin.js b/public/js/admin.js index 83d80fd11..c7f1f0ff3 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -556,15 +556,18 @@ ravadaApp.directive("solShowMachine", swMach) }); }; - $scope.action = function(target,action,machineId){ + $scope.action = function(target,action,machine, confirmed){ if (action === 'view-new-tab') { - window.open('/machine/view/' + machineId + '.html'); + window.open('/machine/view/' + machine.id + '.html'); } else if (action === 'view') { - window.location.assign('/machine/view/' + machineId + '.html'); + window.location.assign('/machine/view/' + machine.id + '.html'); + } + else if ((action === 'shutdown' || action === 'force_shutdown') && machine.autostart == 1 && !confirmed) { + $scope.open_modal('afc_', machine); } else { - $http.get('/'+target+'/'+action+'/'+machineId+'.json') + $http.get('/'+target+'/'+action+'/'+machine.id +'.json') .then(function(response) { if(response.status == 300 || response.status == 403) { console.error('Reponse error', response.status); diff --git a/public/js/ravada.js b/public/js/ravada.js index 408913582..5902fc149 100644 --- a/public/js/ravada.js +++ b/public/js/ravada.js @@ -200,12 +200,21 @@ $scope.host_shutdown = 0; $scope.host_force_shutdown = 0; } else if (action == 'shutdown' || action == 'hibernate' || action == 'force_shutdown' || action == 'reboot') { - $scope.host_restore = 0; - var id=machine.id; - if (machine.clone) { - id=machine.clone.id; + if (machine.autostart == 1 && confirmed && (action == 'shutdown' || action == 'force_shutdown')) { + action = tmp_action; + } + if (machine.autostart == 1 && (action == 'shutdown' || action == 'force_shutdown') && !confirmed) { + $('#'+'afc_'+machine.id).modal({show:true}) + tmp_action = action; + } + else { + $scope.host_restore = 0; + var id=machine.id; + if (machine.clone) { + id=machine.clone.id; + } + $http.get( '/machine/'+action+'/'+id+'.json'); } - $http.get( '/machine/'+action+'/'+id+'.json'); } else { alert("unknown action "+action); } @@ -332,11 +341,13 @@ subscribe_list_bookings(url); } }; + $scope.tmp_action = null; $scope.only_public = false; $scope.toggle_only_public=function() { $scope.only_public = !$scope.only_public; }; $scope.startIntro = startIntro; + }; function singleMachinePageC($scope, $http, $interval, request, $location) { @@ -498,15 +509,20 @@ return string; }; - $scope.action = function(target,action,machineId,params){ + $scope.action = function(target,action,machine,params){ if (action === 'view-new-tab') { - window.open('/machine/view/' + machineId + '.html'); + window.open('/machine/view/' + machine.id + '.html'); } else if (action === 'view') { - window.location.assign('/machine/view/' + machineId + '.html'); + window.location.assign('/machine/view/' + machine.id + '.html'); } + else if ((action === 'shutdown' || action === 'force_shutdown') && machine.autostart == 1 && !params.confirmed) { + $('#shutdownModal').modal({show:true}) + $scope.tmp_action = action; + $scope.force = params.force; + } else { - $http.get('/'+target+'/'+action+'/'+machineId+'.json'+'?'+this.getQueryStringFromObject(params)) + $http.get('/'+target+'/'+action+'/'+machine.id+'.json'+'?'+this.getQueryStringFromObject(params)) .then(function() { }, function(data,status) { console.error('Repos error', status, data); @@ -514,6 +530,8 @@ }); } }; + $scope.tmp_action = null; + $scope.force = null; var subscribe_requests = function(url) { var ws = new WebSocket(url); diff --git a/script/rvd_front b/script/rvd_front index 8449f5132..33b8a79fd 100644 --- a/script/rvd_front +++ b/script/rvd_front @@ -4408,9 +4408,9 @@ sub shutdown_machine { if ($domain) { my $req; $req = Ravada::Request->force_shutdown_domain(id_domain => $domain->id, uid => $USER->id) - if ($c->param('force')); + if ($c->param('force') eq 'true'); $req = Ravada::Request->shutdown_domain(id_domain => $domain->id, uid => $USER->id) - unless ($c->param('force')); + unless ($c->param('force') eq 'true'); $id_req = $req->id if $req; } return $c->redirect_to('/machines') if $type eq 'html'; diff --git a/templates/main/admin_machines.html.ep b/templates/main/admin_machines.html.ep index 8f1670d96..88b4d10ee 100644 --- a/templates/main/admin_machines.html.ep +++ b/templates/main/admin_machines.html.ep @@ -199,7 +199,7 @@ @@ -279,7 +279,7 @@
+ +
+ +
+%= include 'main/vm_actions_shutdown_modal' diff --git a/templates/main/vm_actions_shutdown_modal.html.ep b/templates/main/vm_actions_shutdown_modal.html.ep new file mode 100644 index 000000000..87d7bb668 --- /dev/null +++ b/templates/main/vm_actions_shutdown_modal.html.ep @@ -0,0 +1,20 @@ +