mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-20 11:52:37 +09:00
Feature #3748: Complete VNet create wizard
This commit is contained in:
1 parent
2575436fb6
commit
24e83d42e6
7 files changed
+393
-26
No files matched your search
@@ -8,7 +8,10 @@ define(function(require) {
|
||||
var Sunstone = require('sunstone');
|
||||
var Locale = require('utils/locale');
|
||||
var Tips = require('utils/tips');
|
||||
|
||||
var CustomTags = require('utils/form-panels/custom-tags');
|
||||
var ArTab = require('tabs/vnets-tab/utils/ar-tab');
|
||||
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
*/
|
||||
@@ -41,10 +44,10 @@ define(function(require) {
|
||||
'buttonText': Locale.tr("Update"),
|
||||
'resetButton': false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BaseFormPanel.call(this);
|
||||
};
|
||||
}
|
||||
|
||||
FormPanel.FORM_PANEL_ID = FORM_PANEL_ID;
|
||||
FormPanel.prototype = Object.create(BaseFormPanel.prototype);
|
||||
@@ -56,6 +59,7 @@ define(function(require) {
|
||||
FormPanel.prototype.onShow = _onShow;
|
||||
FormPanel.prototype.fill = _fill;
|
||||
FormPanel.prototype.setup = _setup;
|
||||
FormPanel.prototype.add_ar_tab = _add_ar_tab;
|
||||
|
||||
return FormPanel;
|
||||
|
||||
@@ -64,7 +68,19 @@ define(function(require) {
|
||||
*/
|
||||
|
||||
function _htmlWizard() {
|
||||
return TemplateWizardHTML({formPanelId: this.formPanelId});
|
||||
var opts = {
|
||||
info: false,
|
||||
select: true,
|
||||
selectOptions: {"multiple_choice": true}
|
||||
};
|
||||
|
||||
this.securityGroupsTable = new SecurityGroupsTable("vnet_create", opts);
|
||||
|
||||
return TemplateWizardHTML({
|
||||
'formPanelId': this.formPanelId,
|
||||
'customTagsHTML': CustomTags.html(),
|
||||
'securityGroupsTableHTML': this.securityGroupsTable.dataTableHTML
|
||||
});
|
||||
}
|
||||
|
||||
function _htmlAdvanced() {
|
||||
@@ -72,8 +88,21 @@ define(function(require) {
|
||||
}
|
||||
|
||||
function _setup(context) {
|
||||
this.arTabObjects = {};
|
||||
var that = this;
|
||||
|
||||
var number_of_ar = 0;
|
||||
|
||||
// add new ar tabs
|
||||
$("#vnet_wizard_ar_btn", context).bind("click", function() {
|
||||
that.add_ar_tab(number_of_ar, context);
|
||||
number_of_ar++;
|
||||
|
||||
context.foundation();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// close icon: removing the tab on click
|
||||
$("#vnetCreateARTab", context).on("click", "i.remove-tab", function() {
|
||||
var target = $(this).parent().attr("href");
|
||||
@@ -81,6 +110,8 @@ define(function(require) {
|
||||
var dl = $(this).closest('dl');
|
||||
var content = $(target);
|
||||
|
||||
var ar_id = content.attr("ar_id");
|
||||
|
||||
dd.remove();
|
||||
content.remove();
|
||||
|
||||
@@ -88,14 +119,7 @@ define(function(require) {
|
||||
$('a', dl.children('dd').last()).click();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#vnet_wizard_ar_btn", context).bind("click", function() {
|
||||
// TODO add_ar_tab(number_of_ar, context);
|
||||
number_of_ar++;
|
||||
|
||||
context.foundation();
|
||||
delete that.arTabObjects[ar_id];
|
||||
|
||||
return false;
|
||||
});
|
||||
@@ -187,18 +211,46 @@ define(function(require) {
|
||||
//Initialize shown options
|
||||
$('#network_mode', context).trigger("change");
|
||||
|
||||
//TODO setupSecurityGroupTableSelect(context, "vnet_create", {"multiple_choice": true});
|
||||
//TODO setupCustomTags($("#vnetCreateContextTab", context));
|
||||
//
|
||||
this.securityGroupsTable.initialize();
|
||||
this.securityGroupsTable.refreshResourceTableSelect();
|
||||
|
||||
CustomTags.setup( $("#vnetCreateContextTab", context) );
|
||||
|
||||
// Add first AR
|
||||
//TODO $("#vnet_wizard_ar_btn", context).trigger("click");
|
||||
$("#vnet_wizard_ar_btn", context).trigger("click");
|
||||
|
||||
$(document).foundation('reflow', 'tab');
|
||||
Tips.setup();
|
||||
return false;
|
||||
}
|
||||
|
||||
function _add_ar_tab(ar_id, context) {
|
||||
var str_ar_tab_id = 'ar' + ar_id;
|
||||
|
||||
var ar_tab = new ArTab();
|
||||
this.arTabObjects[ar_id] = ar_tab;
|
||||
|
||||
var html_tab_content =
|
||||
'<div id="'+str_ar_tab_id+'Tab" class="ar_tab content" ar_id="'+ar_id+'">'+
|
||||
ar_tab.html(str_ar_tab_id) +
|
||||
'</div>';
|
||||
|
||||
// Append the new div containing the tab and add the tab to the list
|
||||
var a = $("<dd><a id='ar_tab"+str_ar_tab_id+"' href='#"+str_ar_tab_id+"Tab'>"+
|
||||
Locale.tr("Address Range")+" <i class='fa fa-times-circle remove-tab'></i></a></dd>"
|
||||
).appendTo($("dl#vnet_wizard_ar_tabs", context));
|
||||
|
||||
$(html_tab_content).appendTo($("#vnet_wizard_ar_tabs_content", context));
|
||||
|
||||
$("a", a).trigger("click");
|
||||
|
||||
var ar_section = $('#' + str_ar_tab_id + 'Tab', context);
|
||||
ar_tab.setup(ar_section, str_ar_tab_id);
|
||||
}
|
||||
|
||||
function _submitWizard(context) {
|
||||
var that = this;
|
||||
|
||||
//Fetch values
|
||||
var network_json = {};
|
||||
|
||||
@@ -206,17 +258,16 @@ define(function(require) {
|
||||
this.retrieveWizardFields($("#vnetCreateBridgeTab", context), network_json);
|
||||
this.retrieveWizardFields($("#vnetCreateContextTab", context), network_json);
|
||||
|
||||
/* TODO
|
||||
var secgroups = retrieveSecurityGroupTableSelect(context, "vnet_create");
|
||||
var secgroups = this.securityGroupsTable.retrieveResourceTableSelect();
|
||||
if (secgroups != undefined && secgroups.length != 0) {
|
||||
network_json["SECURITY_GROUPS"] = secgroups.join(",");
|
||||
}*/
|
||||
}
|
||||
|
||||
// TODO retrieveCustomTags($("#vnetCreateContextTab", context), network_json);
|
||||
$.extend(network_json, CustomTags.retrieve( $("#vnetCreateContextTab", context) ));
|
||||
|
||||
/* TODO
|
||||
$('.ar_tab', context).each(function() {
|
||||
hash = retrieve_ar_tab_data(this);
|
||||
var ar_id = $(this).attr("ar_id");
|
||||
var hash = that.arTabObjects[ar_id].retrieve();
|
||||
|
||||
if (!$.isEmptyObject(hash)) {
|
||||
if (!network_json["AR"])
|
||||
@@ -224,7 +275,7 @@ define(function(require) {
|
||||
|
||||
network_json["AR"].push(hash);
|
||||
}
|
||||
});*/
|
||||
});
|
||||
|
||||
if (this.action == "create") {
|
||||
network_json = {
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="content" id="vnetCreateSecurityTab">
|
||||
{{! TODO generateSecurityGroupTableSelect("vnet_create")}}
|
||||
{{{securityGroupsTableHTML}}}
|
||||
<div class="row" id="default_sg_warning">
|
||||
<div class="large-12 columns">
|
||||
<span class="radius secondary label">
|
||||
@@ -254,9 +254,10 @@
|
||||
<div class="large-12 columns">
|
||||
<span>{{tr "Custom attributes"}}</span>
|
||||
<br>
|
||||
<br></div>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
{{! TODO customTagsHtml()}}
|
||||
{{{customTagsHTML}}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -292,6 +292,8 @@ define(function(require) {
|
||||
|
||||
delete ar["SECURITY_GROUPS"];
|
||||
|
||||
// TODO bug: extra attributes are not shown
|
||||
|
||||
var arExtraAttr = ar;
|
||||
|
||||
return TemplateARInfo({
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<div class="row" name="str_ar_tab_id" str_ar_tab_id="{{str_ar_tab_id}}">
|
||||
<div class="large-12 columns">
|
||||
<input wizard_field="TYPE" type="radio" name="{{str_ar_tab_id}}_ar_type" id="{{str_ar_tab_id}}_ar_type_ip4" value="IP4"/><label for="{{str_ar_tab_id}}_ar_type_ip4">{{tr "IPv4"}}</label>
|
||||
<input wizard_field="TYPE" type="radio" name="{{str_ar_tab_id}}_ar_type" id="{{str_ar_tab_id}}_ar_type_ip4_6" value="IP4_6"/><label for="{{str_ar_tab_id}}_ar_type_ip4_6">{{tr "IPv4/6"}}</label>
|
||||
<input wizard_field="TYPE" type="radio" name="{{str_ar_tab_id}}_ar_type" id="{{str_ar_tab_id}}_ar_type_ip6" value="IP6"/><label for="{{str_ar_tab_id}}_ar_type_ip6">{{tr "IPv6"}}</label>
|
||||
<input wizard_field="TYPE" type="radio" name="{{str_ar_tab_id}}_ar_type" id="{{str_ar_tab_id}}_ar_type_ether" value="ETHER"/><label for="{{str_ar_tab_id}}_ar_type_ether">{{tr "Ethernet"}}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-6 columns">
|
||||
<div class="row collapse ar_input type_ip4 type_ip4_6">
|
||||
<label for="{{str_ar_tab_id}}_ip_start">{{tr "IP Start"}}:
|
||||
<span class="tip">{{tr "First IP address"}}</span>
|
||||
</label>
|
||||
<input wizard_field="IP" type="text" name="IP" id="{{str_ar_tab_id}}_ip_start"/>
|
||||
</div>
|
||||
<div class="row collapse ar_input type_ip4 type_ip4_6 type_ip6 type_ether">
|
||||
<label for="{{str_ar_tab_id}}_mac_start">{{tr "MAC Start"}}:
|
||||
<span class="tip">{{tr "First MAC address"}}</span>
|
||||
</label>
|
||||
<input wizard_field="MAC" type="text" name="MAC" id="{{str_ar_tab_id}}_mac_start" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-6 columns ar_input type_ip4 type_ip4_6 type_ip6 type_ether">
|
||||
<label for="{{str_ar_tab_id}}_size">{{tr "Size"}}:
|
||||
<span class="tip">{{tr "Number of addresses in the range"}}</span>
|
||||
</label>
|
||||
<input wizard_field="SIZE" required type="text" name="SIZE" id="{{str_ar_tab_id}}_size" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-6 columns ar_input type_ip4_6 type_ip6">
|
||||
<label for="{{str_ar_tab_id}}_global_prefix">{{tr "Global prefix"}}:
|
||||
<span class="tip">{{tr "IPv6 global address prefix to create leases"}}</span>
|
||||
</label>
|
||||
<input wizard_field="GLOBAL_PREFIX" type="text" name="GLOBAL_PREFIX" id="{{str_ar_tab_id}}_global_prefix"/>
|
||||
</div>
|
||||
<div class="large-6 columns ar_input type_ip4_6 type_ip6">
|
||||
<label for="{{str_ar_tab_id}}_ula_prefix">{{tr "ULA prefix"}}:
|
||||
<span class="tip">{{tr "IPv6 unique local address (ULA) prefix to create leases"}}</span>
|
||||
</label>
|
||||
<input wizard_field="ULA_PREFIX" type="text" name="ULA_PREFIX" id="{{str_ar_tab_id}}_ula_prefix"/>
|
||||
</div>
|
||||
</div>
|
||||
{{#advancedSection (tr "Advanced Options") }}
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<span>{{tr "Custom attributes"}}</span>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" id="{{str_ar_tab_id}}_custom_tags">
|
||||
<div class="12 columns">
|
||||
{{{customTagsHTML}}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<br>
|
||||
<br>
|
||||
<hr>
|
||||
<div class="large-12 columns">
|
||||
<span>{{tr "Security Groups"}}</span>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" id="{{str_ar_tab_id}}_security_groups">
|
||||
{{{securityGroupsTableHTML}}}
|
||||
</div>
|
||||
{{/advancedSection}}
|
||||
@@ -0,0 +1,124 @@
|
||||
define(function(require) {
|
||||
// Dependencies
|
||||
var Locale = require('utils/locale');
|
||||
var Tips = require('utils/tips');
|
||||
var CustomTags = require('utils/form-panels/custom-tags');
|
||||
var SecurityGroupsTable = require('tabs/secgroups-tab/datatable');
|
||||
|
||||
var TemplateHTML = require('hbs!./ar-tab');
|
||||
|
||||
function ArTab() {
|
||||
return this;
|
||||
}
|
||||
|
||||
ArTab.prototype = {
|
||||
'html': _generate_ar_tab_content,
|
||||
'setup': _setup_ar_tab_content,
|
||||
'retrieve': _retrieve_ar_tab_data
|
||||
};
|
||||
|
||||
return ArTab;
|
||||
|
||||
function _generate_ar_tab_content(str_ar_tab_id){
|
||||
var opts = {
|
||||
info: false,
|
||||
select: true,
|
||||
selectOptions: {"multiple_choice": true}
|
||||
};
|
||||
|
||||
this.securityGroupsTable = new SecurityGroupsTable(str_ar_tab_id, opts);
|
||||
|
||||
return TemplateHTML({
|
||||
'str_ar_tab_id': str_ar_tab_id,
|
||||
'customTagsHTML': CustomTags.html(),
|
||||
'securityGroupsTableHTML': this.securityGroupsTable.dataTableHTML
|
||||
});
|
||||
}
|
||||
|
||||
function _setup_ar_tab_content(ar_section, str_ar_tab_id) {
|
||||
|
||||
this.ar_section = ar_section;
|
||||
|
||||
$('input[name$="ar_type"]',ar_section).change(function(){
|
||||
$('div.ar_input', ar_section).hide();
|
||||
|
||||
$('input[wizard_field="IP"]',ar_section).removeAttr('required');
|
||||
|
||||
switch($(this).val()){
|
||||
case "IP4":
|
||||
$('div.type_ip4', ar_section).show();
|
||||
$('input[wizard_field="IP"]',ar_section).attr('required', '');
|
||||
|
||||
break;
|
||||
case "IP4_6":
|
||||
$('div.type_ip4_6', ar_section).show();
|
||||
$('input[wizard_field="IP"]',ar_section).attr('required', '');
|
||||
|
||||
break;
|
||||
case "IP6":
|
||||
$('div.type_ip6', ar_section).show();
|
||||
break;
|
||||
case "ETHER":
|
||||
$('div.type_ether', ar_section).show();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
$('input#'+str_ar_tab_id+'_ar_type_ip4',ar_section).prop('checked', true);
|
||||
$('input#'+str_ar_tab_id+'_ar_type_ip4',ar_section).change();
|
||||
|
||||
CustomTags.setup($('#'+str_ar_tab_id+'_custom_tags',ar_section));
|
||||
|
||||
this.securityGroupsTable.initialize();
|
||||
this.securityGroupsTable.refreshResourceTableSelect();
|
||||
|
||||
Tips.setup(ar_section);
|
||||
}
|
||||
|
||||
function _retrieve_ar_tab_data(){
|
||||
var data = {};
|
||||
|
||||
var ar_type = $('input[name$="ar_type"]:checked',this.ar_section).val();
|
||||
|
||||
var fields = [];
|
||||
|
||||
switch(ar_type){
|
||||
case "IP4":
|
||||
fields = $('div.type_ip4', this.ar_section).children("input");
|
||||
break;
|
||||
case "IP4_6":
|
||||
fields = $('div.type_ip4_6', this.ar_section).children("input");
|
||||
break;
|
||||
case "IP6":
|
||||
fields = $('div.type_ip6', this.ar_section).children("input");
|
||||
break;
|
||||
case "ETHER":
|
||||
fields = $('div.type_ether', this.ar_section).children("input");
|
||||
break;
|
||||
}
|
||||
|
||||
fields.each(function(){
|
||||
var field=$(this);
|
||||
|
||||
if (field.val() != null && field.val().length){ //if has a length
|
||||
data[field.attr('name')] = field.val();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (!$.isEmptyObject(data)) {
|
||||
data["TYPE"] = ar_type;
|
||||
}
|
||||
|
||||
$.extend(data, CustomTags.retrieve(this.ar_section));
|
||||
|
||||
var str_ar_tab_id = $('div[name="str_ar_tab_id"]', this.ar_section).attr("str_ar_tab_id");
|
||||
|
||||
var secgroups = this.securityGroupsTable.retrieveResourceTableSelect();
|
||||
if (secgroups != undefined && secgroups.length != 0){
|
||||
data["SECURITY_GROUPS"] = secgroups.join(",");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
<div class="row">
|
||||
<div class="large-4 columns">
|
||||
<input type="text" id="KEY" name="key" />
|
||||
</div>
|
||||
<div class="large-6 columns">
|
||||
<input type="text" id="VALUE" name="value" />
|
||||
</div>
|
||||
<div class="large-2 columns">
|
||||
<button type="button" class="button secondary small radius" id="add_custom">
|
||||
{{tr "Add"}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<table id="custom_tags" class="dataTable policies_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{tr "KEY"}}</th>
|
||||
<th>{{tr "VALUE"}}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbodyinput">
|
||||
<tr>
|
||||
</tr>
|
||||
<tr>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,86 @@
|
||||
define(function(require) {
|
||||
|
||||
var Locale = require('utils/locale');
|
||||
var TemplateHTML = require('hbs!./custom-tags');
|
||||
|
||||
function _html(){
|
||||
return TemplateHTML();
|
||||
}
|
||||
|
||||
function _setup(context){
|
||||
$('#add_custom', context).click(function() {
|
||||
var table = $('#custom_tags', context)[0];
|
||||
var rowCount = table.rows.length;
|
||||
var row = table.insertRow(rowCount);
|
||||
|
||||
var cell1 = row.insertCell(0);
|
||||
var element1 = document.createElement("input");
|
||||
element1.id = "KEY";
|
||||
element1.type = "text";
|
||||
element1.value = $('input#KEY', context).val();
|
||||
cell1.appendChild(element1);
|
||||
|
||||
var cell2 = row.insertCell(1);
|
||||
var element2 = document.createElement("input");
|
||||
element2.id = "VALUE";
|
||||
element2.type = "text";
|
||||
element2.value = $('input#VALUE', context).val();
|
||||
cell2.appendChild(element2);
|
||||
|
||||
var cell3 = row.insertCell(2);
|
||||
cell3.innerHTML = "<i class='fa fa-times-circle fa fa-lg remove-tab'></i>";
|
||||
});
|
||||
|
||||
context.on("click", "i.remove-tab", function() {
|
||||
$(this).closest("tr").remove();
|
||||
});
|
||||
}
|
||||
|
||||
// context is the container div of customTagsHtml()
|
||||
function _retrieveCustomTags(context){
|
||||
var template_json = {};
|
||||
|
||||
$('#custom_tags tr', context).each(function(){
|
||||
if ($('#KEY', $(this)).val()) {
|
||||
template_json[$('#KEY', $(this)).val()] = $('#VALUE', $(this)).val();
|
||||
}
|
||||
});
|
||||
|
||||
return template_json;
|
||||
}
|
||||
/*
|
||||
// div is the container div of customTagsHtml()
|
||||
// template_json are the key:values that will be put into the table
|
||||
function fillCustomTags(div, template_json){
|
||||
$.each(template_json, function(key, value){
|
||||
var table = $('#custom_tags', div)[0];
|
||||
var rowCount = table.rows.length;
|
||||
var row = table.insertRow(rowCount);
|
||||
|
||||
var cell1 = row.insertCell(0);
|
||||
var element1 = document.createElement("input");
|
||||
element1.id = "KEY";
|
||||
element1.type = "text";
|
||||
element1.value = htmlDecode(key);
|
||||
cell1.appendChild(element1);
|
||||
|
||||
var cell2 = row.insertCell(1);
|
||||
var element2 = document.createElement("input");
|
||||
element2.id = "VALUE";
|
||||
element2.type = "text";
|
||||
element2.value = htmlDecode(value);
|
||||
cell2.appendChild(element2);
|
||||
|
||||
|
||||
var cell3 = row.insertCell(2);
|
||||
cell3.innerHTML = "<i class='fa fa-times-circle fa fa-lg remove-tab'></i>";
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
return {
|
||||
'html': _html,
|
||||
'setup': _setup,
|
||||
'retrieve': _retrieveCustomTags
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user