Commit 63d2bd2e authored by robertperez-upc's avatar robertperez-upc Committed by Francesc Guasch
Browse files

Create machine form improvements (#1639) (#1642)

Create machine form improvements (#1639)
parent 3aadd59f
......@@ -105,7 +105,9 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.showMinSize = false;
$scope.min_size = 15;
$scope.change_iso = function(id) {
$scope.id_iso_id = id.id;
if (id.min_disk_size != null) {
$scope.min_size = id.min_disk_size;
$scope.showMinSize = true;
......@@ -114,10 +116,12 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.showMinSize = false;
$scope.min_size = 1;
}
if (id.device != null) {
return id.device;
}
else return "<NONE>";
return (id.device != null) ? id.device : "<NONE>";
};
$scope.onIdIsoSelected = function() {
$scope.iso_file = $scope.change_iso(this.id_iso)
$scope.id_file = ($scope.iso_file === "<NONE>") ? "" : $scope.iso_file;
};
$scope.validate_new_name = function() {
......@@ -135,9 +139,23 @@ ravadaApp.directive("solShowMachine", swMach)
}
};
$scope.getVisualizableObjects = function(value, objects, name) {
var visualizable_objects = [];
if (objects) {
var lowercased_value = value ? value.toLowerCase() : '';
for (var i = 0, j = objects.length; i < j; i ++) {
var search_value = name ? objects[i][name] : objects[i];
if ((! lowercased_value) || (search_value.toLowerCase().indexOf(lowercased_value) >= 0)) {
visualizable_objects.push(objects[i]);
}
}
}
return visualizable_objects;
};
$scope.type = function(v) {
return typeof(v);
}
};
$scope.get_machine_info = function(id) {
$http.get('/machine/info/'+id+'.json')
......
......@@ -2439,6 +2439,7 @@ sub new_machine {
my $c = shift;
my @error ;
if ($c->param('submit')) {
$c->param('id_iso', $c->param('id_iso_id')) if $c->param('id_iso_id');
push @error,("Name is mandatory") if !$c->param('name');
push @error,("Invalid name '".$c->param('name')."'"
.".It can only contain alphabetic, numbers, undercores and dashes.")
......
......@@ -3,9 +3,10 @@
<form name="new_machineForm" role="form" method="post" action="/new_machine.html" novalidate>
<div class="form-group row">
<label for="backend" class="col-xl-3 col-form-label"><%=l 'Backend' %> <a
title="Choose the virtualization type of the Virtual Machine."><i class="fa fa-info-circle"></i></a></label>
title="Choose the virtualization type of the Virtual Machine." ng-show="backends.length > 1"><i class="fa fa-info-circle"></i></a></label>
<div class="col-lg-9">
<select class= "form-control"
<label for="backend" class="col-xl-3 col-form-label" ng-show="backends.length === 1">{{backends[0]}}</label>
<select class= "form-control" ng-show="backends.length > 1"
ng-change="loadTemplate()"
name="backend"
ng-model="backend"
......@@ -20,13 +21,14 @@
<label for="id_iso" class="col-xl-3 col-form-label"><%=l 'Select Template' %> <a
title="Choose the OS you want to install."><i class="fa fa-info-circle"></i></a></label>
<div class="col-lg-9">
<select class="form-control"
name ="id_iso"
ng-model="id_iso"
ng-options="item.name for item in images track by item.id"
ng-change="iso_file = change_iso(id_iso)"
required=""
></select>
<input type="hidden" name="id_iso_id" ng-value="id_iso_id">
<input type="text" class="form-control" placeholder="<%=l 'Type the template name' %>"
name="id_iso"
ng-model="id_iso"
required=""
uib-typeahead="item as item.name for item in getVisualizableObjects($viewValue, images, 'name')"
typeahead-min-length="0"
typeahead-on-select="onIdIsoSelected()">
<div class="mb-2" ng-show="id_iso.description" >
<small ng-bind-html="id_iso.description">{{id_iso.description}}</small>
</div>
......@@ -44,13 +46,12 @@
<label for="iso_file" class="col-xl-3 col-form-label"><%=l 'Select ISO' %> <a
title="Select the .iso file the machine will utilize when installing the OS." href="http://ravada.readthedocs.io/en/latest/docs/new_iso_image.html"><i class="fa fa-info-circle"></i></a></label>
<div class="col-lg-9" ng-init="iso_file = '<NONE>'" >
<select class="form-control"
name ="iso_file"
ng-model="iso_file"
ng-options="item for item in isos track by item"
required=""
></select>
<input type="text" class="form-control" placeholder="<%=l 'Type the ISO pathname' %>"
name="id_file"
ng-model="id_file"
required=""
uib-typeahead="item for item in getVisualizableObjects($viewValue, isos)"
typeahead-min-length="0">
</div>
</div>
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment