Skip to content

Commit

Permalink
Refactor: form base (#1755)
Browse files Browse the repository at this point in the history
refactor(frontend): prepare base and set public
  • Loading branch information
frankiejol authored May 13, 2022
1 parent 71b331e commit 98645da
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
32 changes: 29 additions & 3 deletions public/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ ravadaApp.directive("solShowMachine", swMach)
ws = new WebSocket(url);
};
ws.onmessage = function (event) {

if ( $scope.modalOpened == true ) {
return;
}
$scope.list_machines_time++;
var data = JSON.parse(event.data);

Expand Down Expand Up @@ -482,6 +486,14 @@ ravadaApp.directive("solShowMachine", swMach)
return machine.is_base == 0 && machine.is_locked ==0;
};

$scope.can_manage_base = function(machine) {
if (machine.is_base) {
return $scope.can_remove_base(machine);
} else {
return $scope.can_prepare_base(machine);
}
};

$scope.list_images=function() {
$http.get('/list_images.json').then(function(response) {
$scope.images = response.data;
Expand All @@ -492,12 +504,26 @@ ravadaApp.directive("solShowMachine", swMach)
$('#'+prefix+machine.id).modal({show:true})
$scope.with_cd = false;
$http.get("/machine/info/"+machine.id+".json").then(function(response) {
if(response.status != 200 ) {
window.location.reload();
}
machine.info=response.data;
}
);
,function errorCallback(response) {
console.log(response);
window.location.reload();
});
}
$scope.cancel_modal=function(){
$scope.modalOpened=false;
$scope.cancel_modal=function(machine,field){
$scope.modalOpened=false;
if (typeof(machine)!='undefined' && typeof(field)!='undefined') {
console.log(field);
if (machine[field]) {
machine[field]=0;
} else {
machine[field]=1;
}
}
}
$scope.toggle_show_clones =function(id, value) {
if (typeof(value) == 'undefined') {
Expand Down
53 changes: 33 additions & 20 deletions templates/main/admin_machines.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,30 @@
</button>

</td>
<td class="lgMachToggle">
<td class="lgMachToggle" >
% if ($_user->can_create_base ) {
<i ng-show="machine.has_clones" class="fa fa-check" aria-hidden="true"
title ="<%=l 'Cannot remove base, machine has clones' %>" ng-cloak></i>
<input type="checkbox" checked
ng-show="can_remove_base(machine)"
ng-click="open_modal('mb_',machine)"/>
<input type="checkbox"
ng-show="!machine.is_volatile && can_prepare_base(machine)"
ng-click="open_modal('mb_',machine)"
title ="<%=l 'Prepare base' %>" ng-cloak="1"/>
ng-model="machine.is_base"
ng-true-value="1" ng-false-value="0"
ng-show="can_manage_base(machine)"
ng-disabled="list_machines_time<2"
ng-click="open_modal('mb_',machine)"/>
<div class="modal fade" tabindex="-1" role="dialog" id="mb_{{machine.id}}">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><%=l 'Changing Base State' %></h4>
<button type="button" class="close"
data-dismiss="modal" aria-label="Close"
ng-click="cancel_modal(machine,'is_base')"
><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body" ng-show="can_remove_base(machine)">
<div class="modal-body" ng-show="!machine.is_base">
<p><%=l 'Are you sure you want to remove the base of' %> {{machine.name}}?</p>
</div>
<div class="modal-body" ng-show="can_prepare_base(machine)">
<div class="modal-body" ng-show="machine.is_base">
<div ng-show="machine.info.cdrom">
<p>
<%=l 'This machine has a CD-ROM' %>
Expand All @@ -190,10 +192,13 @@
</div>
<p><%=l 'Are you sure you want to prepare the base of' %> {{machine.name}}?</p>
</div>
<div ng-show="!machine.info">
<i class="fas fa-sync-alt fa-spin"></i>
</div>
<div class="modal-footer" ng-show="machine.info">
<button type="button" class="btn btn-secondary" data-dismiss="modal" ng-click="cancel_modal()"><%=l 'No' %></button>
<button type="button" class="btn btn-primary" ng-click="cancel_modal();action('machine','remove_base',machine.id)" ng-show="can_remove_base(machine)" data-dismiss="modal"><%=l 'Yes' %></button>
<button type="button" class="btn btn-primary" ng-click="cancel_modal();request('prepare_base',{ 'id_domain': machine.id, 'with_cd': with_cd })" ng-show="can_prepare_base(machine)" data-dismiss="modal"><%=l 'Yes' %></button>
<button type="button" class="btn btn-secondary" data-dismiss="modal" ng-click="cancel_modal(machine,'is_base')"><%=l 'No' %></button>
<button type="button" class="btn btn-primary" ng-click="cancel_modal(machine);action('machine','remove_base',machine.id)" ng-show="!machine.is_base" data-dismiss="modal"><%=l 'Yes' %></button>
<button type="button" class="btn btn-primary" ng-click="cancel_modal();request('prepare_base',{ 'id_domain': machine.id, 'with_cd': with_cd })" ng-show="machine.is_base" data-dismiss="modal"><%=l 'Yes' %></button>
</div>
</div>
</div>
Expand All @@ -202,23 +207,31 @@
</td>
<td class="lgMachToggle">
% if ($_user->can_create_base ) {
<input type="checkbox" checked ng-show="machine.is_public" ng-click="open_modal('mp_',machine)" title="<%=l 'Make private'%>" ng-cloak>

<input type="checkbox" ng-hide="!machine.is_base || machine.is_public" ng-click="open_modal('mp_',machine)" title="<%=l 'Make public' %>" ng-cloak>
<input type="checkbox"
ng-click="open_modal('mp_',machine)"
title="<%=l 'Make public'%>"
ng-disabled="list_machines_time<2" ng-model="machine.is_public"
ng-true-value="1" ng-false-value="0"
ng-show="machine.is_base"
>

<div class="modal fade" tabindex="-1" role="dialog" id="mp_{{machine.id}}">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title"><%=l 'Changing Public State' %></h4>
<button type="button" class="close"
data-dismiss="modal"
aria-label="Close"
ng-click="cancel_modal(machine,'is_public')"
><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<p><%=l 'Are you sure you want to change the Public state of' %> {{machine.name}} <%=l 'to' %> {{(machine.is_public==0)}}?</p>
<p><%=l 'Are you sure you want to change the Public state of' %> {{machine.name}} <%=l 'to' %> {{!(machine.is_public==0)}}?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" ng-click="cancel_modal()"><%=l 'No' %></button>
<button type="button" class="btn btn-primary" ng-click="cancel_modal();set_public(machine.id, machine.is_public==0)" data-dismiss="modal"><%=l 'Yes' %></button>
<button type="button" class="btn btn-secondary" data-dismiss="modal" ng-click="cancel_modal(machine,'is_public')"><%=l 'No' %></button>
<button type="button" class="btn btn-primary" ng-click="cancel_modal();set_public(machine.id, machine.is_public)" data-dismiss="modal"><%=l 'Yes' %></button>
</div>
</div>
</div>
Expand Down

0 comments on commit 98645da

Please sign in to comment.