1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

Day is end

This commit is contained in:
Retspen 2015-03-06 15:46:59 +02:00
parent cd4ac13e36
commit be9487e42f
7 changed files with 965 additions and 16 deletions

View file

@ -28,6 +28,7 @@ def create_instance(request, compute_id):
storages = [] storages = []
networks = [] networks = []
meta_prealloc = False meta_prealloc = False
computes = Compute.objects.all()
compute = Compute.objects.get(id=compute_id) compute = Compute.objects.get(id=compute_id)
flavors = Flavor.objects.filter().order_by('id') flavors = Flavor.objects.filter().order_by('id')

38
static/css/bootstrap-multiselect.css vendored Normal file
View file

@ -0,0 +1,38 @@
.multiselect-container {
position: absolute;
list-style-type: none;
margin: 0;
padding: 0;
}
.multiselect-container .input-group {
margin: 5px;
}
.multiselect-container > li {
padding: 0;
}
.multiselect-container > li > a.multiselect-all label {
font-weight: bold;
}
.multiselect-container > li > label.multiselect-group {
margin: 0;
padding: 3px 20px 3px 20px;
height: 100%;
}
.multiselect-container > li > a > label {
margin: 0;
height: 100%;
cursor: pointer;
font-weight: normal;
}
.multiselect-container > li > a > label.radio,
.multiselect-container > li > a > label.checkbox {
margin: 0;
}
.multiselect-container > li > a > label > input[type="checkbox"] {
margin-bottom: 5px;
}
.btn-group > .btn-group:nth-child(2) > .multiselect.btn {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}

635
static/js/bootstrap-multiselect.js vendored Normal file
View file

@ -0,0 +1,635 @@
/**
* bootstrap-multiselect.js
* https://github.com/davidstutz/bootstrap-multiselect
*
* Copyright 2012, 2013 David Stutz
*
* Dual licensed under the BSD-3-Clause and the Apache License, Version 2.0.
* See the README.
*/
!function($) {
"use strict";// jshint ;_;
if (typeof ko != 'undefined' && ko.bindingHandlers && !ko.bindingHandlers.multiselect) {
ko.bindingHandlers.multiselect = {
init : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {},
update : function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var ms = $(element).data('multiselect');
if (!ms) {
$(element).multiselect(ko.utils.unwrapObservable(valueAccessor()));
}
else if (allBindingsAccessor().options && allBindingsAccessor().options().length !== ms.originalOptions.length) {
ms.updateOriginalOptions();
$(element).multiselect('rebuild');
}
}
};
}
function Multiselect(select, options) {
this.options = this.mergeOptions(options);
this.$select = $(select);
// Initialization.
// We have to clone to create a new reference.
this.originalOptions = this.$select.clone()[0].options;
this.query = '';
this.searchTimeout = null;
this.options.multiple = this.$select.attr('multiple') == "multiple";
this.options.onChange = $.proxy(this.options.onChange, this);
// Build select all if enabled.
this.buildContainer();
this.buildButton();
this.buildSelectAll();
this.buildDropdown();
this.buildDropdownOptions();
this.buildFilter();
this.updateButtonText();
this.$select.hide().after(this.$container);
};
Multiselect.prototype = {
// Default options.
defaults: {
// Default text function will either print 'None selected' in case no
// option is selected, or a list of the selected options up to a length of 3 selected options.
// If more than 3 options are selected, the number of selected options is printed.
buttonText: function(options, select) {
if (options.length == 0) {
return this.nonSelectedText + ' <b class="caret"></b>';
}
else {
if (options.length > 3) {
return options.length + ' ' + this.nSelectedText + ' <b class="caret"></b>';
}
else {
var selected = '';
options.each(function() {
var label = ($(this).attr('label') !== undefined) ? $(this).attr('label') : $(this).html();
selected += label + ', ';
});
return selected.substr(0, selected.length - 2) + ' <b class="caret"></b>';
}
}
},
// Like the buttonText option to update the title of the button.
buttonTitle: function(options, select) {
var selected = '';
options.each(function () {
selected += $(this).text() + ', ';
});
return selected.substr(0, selected.length - 2);
},
// Is triggered on change of the selected options.
onChange : function(option, checked) {
},
buttonClass: 'btn',
dropRight: false,
selectedClass: 'active',
buttonWidth: 'auto',
buttonContainer: '<div class="btn-group" />',
// Maximum height of the dropdown menu.
// If maximum height is exceeded a scrollbar will be displayed.
maxHeight: false,
includeSelectAllOption: false,
selectAllText: ' Select all',
selectAllValue: 'multiselect-all',
enableFiltering: false,
enableCaseInsensitiveFiltering: false,
filterPlaceholder: 'Search',
// possible options: 'text', 'value', 'both'
filterBehavior: 'text',
preventInputChangeEvent: false,
nonSelectedText: 'None selected',
nSelectedText: 'selected'
},
// Templates.
templates: {
button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"></button>',
ul: '<ul class="multiselect-container dropdown-menu"></ul>',
filter: '<div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div>',
li: '<li><a href="javascript:void(0);"><label><input /></label></a></li>',
liGroup: '<li><label class="multiselect-group"></label></li>'
},
constructor: Multiselect,
buildContainer: function() {
this.$container = $(this.options.buttonContainer);
},
buildButton: function() {
// Build button.
this.$button = $(this.templates.button).addClass(this.options.buttonClass);
// Adopt active state.
if (this.$select.attr('disabled') == undefined) {
this.$button.removeClass('disabled');
}
else {
this.$button.addClass('disabled');
}
// Manually add button width if set.
if (this.options.buttonWidth) {
this.$button.css({
'width' : this.options.buttonWidth
});
}
// Keep the tab index from the select.
var tabindex = this.$select.attr('tabindex');
if (tabindex) {
this.$button.attr('tabindex', tabindex);
}
this.$container.prepend(this.$button)
},
// Build dropdown container ul.
buildDropdown: function() {
// Build ul.
this.$ul = $(this.templates.ul);
if (this.options.dropRight) {
this.$ul.addClass('pull-right');
}
// Set max height of dropdown menu to activate auto scrollbar.
if (this.options.maxHeight) {
// TODO: Add a class for this option to move the css declarations.
this.$ul.css({
'max-height': this.options.maxHeight + 'px',
'overflow-y': 'auto',
'overflow-x': 'hidden'
});
}
this.$container.append(this.$ul)
},
// Build the dropdown and bind event handling.
buildDropdownOptions: function() {
this.$select.children().each($.proxy(function(index, element) {
// Support optgroups and options without a group simultaneously.
var tag = $(element).prop('tagName').toLowerCase();
if (tag == 'optgroup') {
this.createOptgroup(element);
}
else if (tag == 'option') {
this.createOptionValue(element);
}
// Other illegal tags will be ignored.
}, this));
// Bind the change event on the dropdown elements.
$('li input', this.$ul).on('change', $.proxy(function(event) {
var checked = $(event.target).prop('checked') || false;
var isSelectAllOption = $(event.target).val() == this.options.selectAllValue;
// Apply or unapply the configured selected class.
if (this.options.selectedClass) {
if (checked) {
$(event.target).parents('li').addClass(this.options.selectedClass);
}
else {
$(event.target).parents('li').removeClass(this.options.selectedClass);
}
}
// Get the corresponding option.
var value = $(event.target).val();
var $option = this.getOptionByValue(value);
var $optionsNotThis = $('option', this.$select).not($option);
var $checkboxesNotThis = $('input', this.$container).not($(event.target));
// Toggle all options if the select all option was changed.
if (isSelectAllOption) {
$checkboxesNotThis.filter(function() {
return $(this).is(':checked') != checked;
}).trigger('click');
}
if (checked) {
$option.prop('selected', true);
if (this.options.multiple) {
// Simply select additional option.
$option.attr('selected', 'selected');
}
else {
// Unselect all other options and corresponding checkboxes.
if (this.options.selectedClass) {
$($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass);
}
$($checkboxesNotThis).prop('checked', false);
$optionsNotThis.removeAttr('selected').prop('selected', false);
// It's a single selection, so close.
this.$button.click();
}
if (this.options.selectedClass == "active") {
$optionsNotThis.parents("a").css("outline", "");
}
}
else {
// Unselect option.
$option.removeAttr('selected').prop('selected', false);
}
this.updateButtonText();
this.options.onChange($option, checked);
this.$select.change();
if(this.options.preventInputChangeEvent) {
return false;
}
}, this));
$('li a', this.$ul).on('touchstart click', function(event) {
event.stopPropagation();
$(event.target).blur();
});
// Keyboard support.
this.$container.on('keydown', $.proxy(function(event) {
if ($('input[type="text"]', this.$container).is(':focus')) {
return;
}
if ((event.keyCode == 9 || event.keyCode == 27) && this.$container.hasClass('open')) {
// Close on tab or escape.
this.$button.click();
}
else {
var $items = $(this.$container).find("li:not(.divider):visible a");
if (!$items.length) {
return;
}
var index = $items.index($items.filter(':focus'));
// Navigation up.
if (event.keyCode == 38 && index > 0) {
index--;
}
// Navigate down.
else if (event.keyCode == 40 && index < $items.length - 1) {
index++;
}
else if (!~index) {
index = 0;
}
var $current = $items.eq(index);
$current.focus();
if (event.keyCode == 32 || event.keyCode == 13) {
var $checkbox = $current.find('input');
$checkbox.prop("checked", !$checkbox.prop("checked"));
$checkbox.change();
}
event.stopPropagation();
event.preventDefault();
}
}, this));
},
// Will build an dropdown element for the given option.
createOptionValue: function(element) {
if ($(element).is(':selected')) {
$(element).attr('selected', 'selected').prop('selected', true);
}
// Support the label attribute on options.
var label = $(element).attr('label') || $(element).html();
var value = $(element).val();
var inputType = this.options.multiple ? "checkbox" : "radio";
var $li = $(this.templates.li);
$('label', $li).addClass(inputType);
$('input', $li).attr('type', inputType);
var selected = $(element).prop('selected') || false;
var $checkbox = $('input', $li);
$checkbox.val(value);
if (value == this.options.selectAllValue) {
$checkbox.parent().parent().addClass('multiselect-all');
}
$('label', $li).append(" " + label);
this.$ul.append($li);
if ($(element).is(':disabled')) {
$checkbox.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled');
}
$checkbox.prop('checked', selected);
if (selected && this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass);
}
},
// Create optgroup.
createOptgroup: function(group) {
var groupName = $(group).prop('label');
// Add a header for the group.
var $li = $(this.templates.liGroup);
$('label', $li).text(groupName);
this.$ul.append($li);
// Add the options of the group.
$('option', group).each($.proxy(function(index, element) {
this.createOptionValue(element);
}, this));
},
// Add the select all option to the select.
buildSelectAll: function() {
var alreadyHasSelectAll = this.$select[0][0] ? this.$select[0][0].value == this.options.selectAllValue : false;
console.log(this.options);
// If options.includeSelectAllOption === true, add the include all checkbox.
if (this.options.includeSelectAllOption && this.options.multiple && !alreadyHasSelectAll) {
this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>');
}
},
// Build and bind filter.
buildFilter: function() {
// Build filter if filtering OR case insensitive filtering is enabled and the number of options exceeds (or equals) enableFilterLength.
if (this.options.enableFiltering || this.options.enableCaseInsensitiveFiltering) {
var enableFilterLength = Math.max(this.options.enableFiltering, this.options.enableCaseInsensitiveFiltering);
if (this.$select.find('option').length >= enableFilterLength) {
this.$filter = $(this.templates.filter).attr('placeholder', this.options.filterPlaceholder);
this.$ul.prepend(this.$filter);
this.$filter.val(this.query).on('click', function(event) {
event.stopPropagation();
}).on('keydown', $.proxy(function(event) {
// This is useful to catch "keydown" events after the browser has updated the control.
clearTimeout(this.searchTimeout);
this.searchTimeout = this.asyncFunction($.proxy(function() {
if (this.query != event.target.value) {
this.query = event.target.value;
$.each($('li', this.$ul), $.proxy(function(index, element) {
var value = $('input', element).val();
if (value != this.options.selectAllValue) {
var text = $('label', element).text();
var value = $('input', element).val();
if (value && text && value != this.options.selectAllValue) {
// by default lets assume that element is not
// interesting for this search
var showElement = false;
var filterCandidate = '';
if ((this.options.filterBehavior == 'text' || this.options.filterBehavior == 'both')) {
filterCandidate = text;
}
if ((this.options.filterBehavior == 'value' || this.options.filterBehavior == 'both')) {
filterCandidate = value;
}
if (this.options.enableCaseInsensitiveFiltering && filterCandidate.toLowerCase().indexOf(this.query.toLowerCase()) > -1) {
showElement = true;
}
else if (filterCandidate.indexOf(this.query) > -1) {
showElement = true;
}
if (showElement) {
$(element).show();
}
else {
$(element).hide();
}
}
}
}, this));
}
}, this), 300, this);
}, this));
}
}
},
// Destroy - unbind - the plugin.
destroy: function() {
this.$container.remove();
this.$select.show();
},
// Refreshs the checked options based on the current state of the select.
refresh: function() {
$('option', this.$select).each($.proxy(function(index, element) {
var $input = $('li input', this.$ul).filter(function() {
return $(this).val() == $(element).val();
});
if ($(element).is(':selected')) {
$input.prop('checked', true);
if (this.options.selectedClass) {
$input.parents('li').addClass(this.options.selectedClass);
}
}
else {
$input.prop('checked', false);
if (this.options.selectedClass) {
$input.parents('li').removeClass(this.options.selectedClass);
}
}
if ($(element).is(":disabled")) {
$input.attr('disabled', 'disabled').prop('disabled', true).parents('li').addClass('disabled');
}
else {
$input.removeAttr('disabled').prop('disabled', false).parents('li').removeClass('disabled');
}
}, this));
this.updateButtonText();
},
// Select an option by its value or multiple options using an array of values.
select: function(selectValues) {
if(selectValues && !$.isArray(selectValues)) {
selectValues = [selectValues];
}
for (var i = 0; i < selectValues.length; i++) {
var value = selectValues[i];
var $option = this.getOptionByValue(value);
var $checkbox = this.getInputByValue(value);
if (this.options.selectedClass) {
$checkbox.parents('li').addClass(this.options.selectedClass);
}
$checkbox.prop('checked', true);
$option.attr('selected', 'selected').prop('selected', true);
this.options.onChange($option, true);
}
this.updateButtonText();
},
// Deselect an option by its value or using an array of values.
deselect: function(deselectValues) {
if(deselectValues && !$.isArray(deselectValues)) {
deselectValues = [deselectValues];
}
for (var i = 0; i < deselectValues.length; i++) {
var value = deselectValues[i];
var $option = this.getOptionByValue(value);
var $checkbox = this.getInputByValue(value);
if (this.options.selectedClass) {
$checkbox.parents('li').removeClass(this.options.selectedClass);
}
$checkbox.prop('checked', false);
$option.removeAttr('selected').prop('selected', false);
this.options.onChange($option, false);
}
this.updateButtonText();
},
// Rebuild the whole dropdown menu.
rebuild: function() {
this.$ul.html('');
// Remove select all option in select.
$('option[value="' + this.options.selectAllValue + '"]', this.$select).remove();
// Important to distinguish between radios and checkboxes.
this.options.multiple = this.$select.attr('multiple') == "multiple";
this.buildSelectAll();
this.buildDropdownOptions();
this.updateButtonText();
this.buildFilter();
},
// Build select using the given data as options.
dataprovider: function(dataprovider) {
var optionDOM = "";
dataprovider.forEach(function (option) {
optionDOM += '<option value="' + option.value + '">' + option.label + '</option>';
});
this.$select.html(optionDOM);
this.rebuild();
},
// Set options.
setOptions: function(options) {
this.options = this.mergeOptions(options);
},
// Get options by merging defaults and given options.
mergeOptions: function(options) {
return $.extend({}, this.defaults, options);
},
// Update button text and button title.
updateButtonText: function() {
var options = this.getSelected();
// First update the displayed button text.
$('button', this.$container).html(this.options.buttonText(options, this.$select));
// Now update the title attribute of the button.
$('button', this.$container).attr('title', this.options.buttonTitle(options, this.$select));
},
// Get all selected options.
getSelected: function() {
return $('option:selected[value!="' + this.options.selectAllValue + '"]', this.$select);
},
// Get the corresponding option by ts value.
getOptionByValue: function(value) {
return $('option', this.$select).filter(function() {
return $(this).val() == value;
});
},
// Get an input in the dropdown by its value.
getInputByValue: function(value) {
return $('li input', this.$ul).filter(function() {
return $(this).val() == value;
});
},
updateOriginalOptions: function() {
this.originalOptions = this.$select.clone()[0].options;
},
asyncFunction: function(callback, timeout, self) {
var args = Array.prototype.slice.call(arguments, 3);
return setTimeout(function() {
callback.apply(self || window, args);
}, timeout);
}
};
$.fn.multiselect = function(option, parameter) {
return this.each(function() {
var data = $(this).data('multiselect'), options = typeof option == 'object' && option;
// Initialize the multiselect.
if (!data) {
$(this).data('multiselect', ( data = new Multiselect(this, options)));
}
// Call multiselect method.
if ( typeof option == 'string') {
data[option](parameter);
}
});
};
$.fn.multiselect.Constructor = Multiselect;
// Automatically init selects by their data-role.
$(function() {
$("select[data-role=multiselect]").multiselect();
});
}(window.jQuery);

View file

@ -21,8 +21,8 @@
<!-- WebVirtCloud CSS --> <!-- WebVirtCloud CSS -->
<link href="{% static "css/webvirtcloud.css" %}" rel="stylesheet"> <link href="{% static "css/webvirtcloud.css" %}" rel="stylesheet">
<!-- Morris Charts CSS --> <!-- Aditional CSS -->
<link href="{% static "css/plugins/morris.css" %}" rel="stylesheet"> {% block style %}{% endblock %}
<!-- Custom Fonts --> <!-- Custom Fonts -->
<link href="{% static "font-awesome/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css"> <link href="{% static "font-awesome/css/font-awesome.min.css" %}" rel="stylesheet" type="text/css">

View file

@ -0,0 +1,65 @@
{% load i18n %}
{% if request.user.is_superuser %}
<a href="#addFlavor" type="button" class="btn btn-success pull-right" data-toggle="modal">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</a>
<!-- Modal Flavor -->
<div class="modal fade" id="addFlavor" tabindex="-1" role="dialog" aria-labelledby="addFlavorLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Add New Flavor" %}</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="text" name="label" class="form-control" placeholder="Micro" maxlength="20"
required pattern="[a-zA-Z0-9]+">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "VCPU" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="vcpu" value="1" maxlength="1" required
pattern="[0-9]">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "RAM" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="memory" value="512" maxlength="5" required
pattern="[0-9]+">
</div>
<label class="col-sm-1 control-label">{% trans "MB" %}</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "HDD" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="disk" value="10" maxlength="3" required
pattern="[0-9]+">
</div>
<label class="col-sm-1 control-label">{% trans "GB" %}</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
{% trans "Close" %}
</button>
<button type="submit" class="btn btn-primary" name="create_flavor">
{% trans "Add" %}
</button>
</div>
</form>
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
{% endif %}

View file

@ -1,19 +1,229 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Compute" %}{% endblock %} {% load static %}
{% block title %}{% trans "Create new instance" %}{% endblock %}
{% block style %}
<link href="{% static "css/bootstrap-multiselect.css" %}" rel="stylesheet">
{% endblock %}
{% block content %} {% block content %}
<div class="container-fluid"> <!-- Page Heading -->
<div class="row"> <div class="row">
<div class="col-lg-12">
{% include 'sidebar.html' %} {% include 'create_flav_block.html' %}
<h1 class="page-header">{% trans "New instance on" %} {{ compute.name }}</h1>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> </div>
<button type="button" class="btn btn-success pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button> </div>
<h1 class="page-header">{{ compute.name }}</h1> <!-- /.row -->
{% include 'errors_block.html' %} {% include 'errors_block.html' %}
</div> <div class="row">
</div>
</div> {% if not flavors %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "Hypervisor doesn't have any Flavors" %}
</div>
</div>
{% else %}
<div class="col-lg-12">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>{% trans "Name" %}</th>
<th>{% trans "VCPU's" %}</th>
<th>{% trans "RAM" %}</th>
<th>{% trans "HDD" %}</th>
<th colspan="2">{% trans "Action" %}</th>
</tr>
</thead>
<tbody>
{% for flavor in flavors %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ flavor.label }}</td>
<td>{{ flavor.vcpu }}</td>
<td>{{ flavor.memory }} {% trans "MB" %}</td>
<td>{{ flavor.disk }} {% trans "GB" %}</td>
<td style="width:5px;">
<div class="modal fade" id="addVMflavor{{ forloop.counter }}" tabindex="-1" role="dialog" aria-labelledby="addVMFlavorLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{% trans "Create Virtual Machine" %} ({{ flavor.label }})</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Name" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="name"
placeholder="{% trans "Name" %}" maxlength="14" required
pattern="[a-zA-Z0-9\.\-_]+">
<input type="hidden" name="vcpu" value="{{ flavor.vcpu }}">
<input type="hidden" name="memory" value="{{ flavor.memory }}">
<input type="hidden" name="hdd_size" value="{{ flavor.disk }}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Storage" %}</label>
<div class="col-sm-6">
<select name="storage" class="form-control">
{% if storages %}
{% for storage in storages %}
<option value="{{ storage }}">{{ storage }}</option>
{% endfor %}
{% else %}
<option value="">{% trans "None" %}</option>
{% endif %}
</select>
</div>
</div>
<div class="form-group meta-prealloc">
<label class="col-sm-3 control-label">{% trans "Metadata" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="meta_prealloc" title="Metadata preallocation" value="true">
</div>
<label class="col-lg-1 control-label">{% trans "Image" %}</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Network" %}</label>
<div class="col-sm-6">
<select name="networks" class="form-control">
{% for network in networks %}
<option value="{{ network }}">{{ network }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "MAC" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="mac" maxlength="17" value="{{ mac_auto }}" required pattern="[a-zA-Z0-9:]+">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Host-Model" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="host_model" value="true" checked>
</div>
<label class="col-lg-1 control-label">{% trans "CPU" %}</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "VirtIO" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="virtio" value="true" checked>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
{% if storages %}
<button type="submit" class="btn btn-primary" name="create">{% trans "Create" %}</button>
{% else %}
<button class="btn btn-primary disabled">{% trans "Create" %}</button>
{% endif %}
</div>
</form>
</div>
</div>
</div>
<a data-toggle="modal" href="#addVMflavor{{ forloop.counter }}" class="btn btn-sm btn-default">
<span class="glyphicon glyphicon-plus"></span>
</a>
</td>
<td style="width:5px;">
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
<input type="hidden" name="flavor" value="{{ flavor.id }}">
<button type="submit" class="btn btn-sm btn-default" name="delete_flavor" onclick="return confirm('{% trans "Are you sure?" %}')">
<span class="glyphicon glyphicon-trash"></span>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>
{% endblock %}
{% block script %}
<script src="{% static "js/bootstrap-multiselect.js" %}"></script>
<script>
function toggleValue(string, updated_value, checked) {
var result = '';
if (checked) {
result = string;
if (result != '') result += ',';
result += updated_value;
} else {
$.each(string.split(','), function (index, value) {
if (value == updated_value) return;
if (result != '') result += ',';
result += value;
});
}
return result;
}
$(document).ready(function () {
$('#image-control').multiselect({
buttonText: function (options, select) {
return 'Add image <b class="caret"></b>';
},
buttonTitle: function (options, select) {
return '';
},
onChange: function (element, checked) {
var input_value = toggleValue($('#images').val(), element.val(), checked);
$('#images').val(input_value);
var selected_list_html = '';
var counter = 0;
if (input_value != '') {
$.each(input_value.split(','), function (index, value) {
var li = '<li>hdd' + counter +
' -> ' + value + ' ' +
'<a class="btn-link" onclick="javascript:$(\'#image-control\').multiselect(\'deselect\', \'' + value + '\')">x</a></li>';
selected_list_html += li;
counter++;
});
}
$('#img-list').html(selected_list_html);
}
});
$('#network-control').multiselect({
buttonText: function (options, select) {
return 'Add network <b class="caret"></b>';
},
buttonTitle: function (options, select) {
return '';
},
onChange: function (element, checked) {
var input_value = toggleValue($('#networks').val(), element.val(), checked);
$('#networks').val(input_value);
var selected_list_html = '';
var counter = 0;
if (input_value != '') {
$.each(input_value.split(','), function (index, value) {
var li = '<li>eth' + counter +
' -> ' + value + ' ' +
'<a class="btn-link" onclick="javascript:$(\'#network-control\').multiselect(\'deselect\', \'' + value + '\')">x</a></li>';
selected_list_html += li;
counter++;
});
}
$('#net-list').html(selected_list_html);
}
});
});
</script>
{% endblock %} {% endblock %}

View file

@ -3,11 +3,11 @@
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens --> <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse"> <div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav"> <ul class="nav navbar-nav side-nav">
<li {% class_active request "^/instance" %}"> <li {% class_active request "^/instance" %}>
<a href="{% url 'instances' %}"><i class="fa fa-fw fa-desktop"></i> {% trans "Instances" %}</a> <a href="{% url 'instances' %}"><i class="fa fa-fw fa-desktop"></i> {% trans "Instances" %}</a>
</li> </li>
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
<li {% class_active request "^/compute" %}> <li {% class_active request "^/compute" %}{% class_active request "^/create" %}>
<a href="{% url 'computes' %}"><i class="fa fa-fw fa-tasks"></i> {% trans "Computes" %}</a> <a href="{% url 'computes' %}"><i class="fa fa-fw fa-tasks"></i> {% trans "Computes" %}</a>
</li> </li>
<li {% class_active request "^/user" %}> <li {% class_active request "^/user" %}>