mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
new UI - initialize and bind event handler to Add Zone button, Add Pod button, Add Host button, Add Primary Storage button.
This commit is contained in:
parent
cc928ed4a3
commit
7871c26281
@ -193,308 +193,13 @@ function showPage($pageToShow, jsonObj) {
|
||||
$pageToShow.data("jsonObj", jsonObj);
|
||||
}
|
||||
|
||||
if($pageToShow.attr("id") == "zone_page") {
|
||||
//***** Add Pod (begin) *****
|
||||
$("#midmenu_add_link").find("#label").text("Add Pod");
|
||||
$("#midmenu_add_link").data("jsonObj", jsonObj).show();
|
||||
$("#midmenu_add_link").unbind("click").bind("click", function(event) {
|
||||
var zoneObj = $(this).data("jsonObj");
|
||||
$("#dialog_add_pod").find("#add_pod_zone_name").text(fromdb(zoneObj.name));
|
||||
$("#dialog_add_pod #add_pod_name, #dialog_add_pod #add_pod_cidr, #dialog_add_pod #add_pod_startip, #dialog_add_pod #add_pod_endip, #add_pod_gateway").val("");
|
||||
|
||||
$("#dialog_add_pod")
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
var thisDialog = $(this);
|
||||
|
||||
// validate values
|
||||
var isValid = true;
|
||||
isValid &= validateString("Name", thisDialog.find("#add_pod_name"), thisDialog.find("#add_pod_name_errormsg"));
|
||||
isValid &= validateCIDR("CIDR", thisDialog.find("#add_pod_cidr"), thisDialog.find("#add_pod_cidr_errormsg"));
|
||||
isValid &= validateIp("Start IP Range", thisDialog.find("#add_pod_startip"), thisDialog.find("#add_pod_startip_errormsg")); //required
|
||||
isValid &= validateIp("End IP Range", thisDialog.find("#add_pod_endip"), thisDialog.find("#add_pod_endip_errormsg"), true); //optional
|
||||
isValid &= validateIp("Gateway", thisDialog.find("#add_pod_gateway"), thisDialog.find("#add_pod_gateway_errormsg")); //required when creating
|
||||
if (!isValid)
|
||||
return;
|
||||
|
||||
thisDialog.dialog("close");
|
||||
|
||||
var name = trim(thisDialog.find("#add_pod_name").val());
|
||||
var cidr = trim(thisDialog.find("#add_pod_cidr").val());
|
||||
var startip = trim(thisDialog.find("#add_pod_startip").val());
|
||||
var endip = trim(thisDialog.find("#add_pod_endip").val()); //optional
|
||||
var gateway = trim(thisDialog.find("#add_pod_gateway").val());
|
||||
|
||||
var array1 = [];
|
||||
array1.push("&zoneId="+zoneObj.id);
|
||||
array1.push("&name="+todb(name));
|
||||
array1.push("&cidr="+encodeURIComponent(cidr));
|
||||
array1.push("&startIp="+encodeURIComponent(startip));
|
||||
if (endip != null && endip.length > 0)
|
||||
array1.push("&endIp="+encodeURIComponent(endip));
|
||||
array1.push("&gateway="+encodeURIComponent(gateway));
|
||||
|
||||
var template = $("#leftmenu_pod_node_template").clone(true);
|
||||
var loadingImg = template.find(".adding_loading");
|
||||
var row_container = template.find("#row_container");
|
||||
$("#zone_" + zoneObj.id + " #zone_content").show();
|
||||
$("#zone_" + zoneObj.id + " #pods_container").prepend(template.show());
|
||||
$("#zone_" + zoneObj.id + " #zone_expand").removeClass().addClass("zonetree_openarrows");
|
||||
loadingImg.show();
|
||||
row_container.hide();
|
||||
template.fadeIn("slow");
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=createPod"+array1.join("")),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var item = json.createpodresponse;
|
||||
podJSONToTreeNode(item, template);
|
||||
loadingImg.hide();
|
||||
row_container.show();
|
||||
|
||||
forceLogout = false; // We don't force a logout if pod(s) exit.
|
||||
if (forceLogout) {
|
||||
$("#dialog_confirmation")
|
||||
.html("<p>You have successfully added your first Zone and Pod. After clicking 'OK', this UI will automatically refresh to give you access to the rest of cloud features.</p>")
|
||||
.dialog('option', 'buttons', {
|
||||
"OK": function() {
|
||||
$(this).dialog("close");
|
||||
window.location.reload();
|
||||
}
|
||||
}).dialog("open");
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleError(XMLHttpResponse);
|
||||
template.slideUp("slow", function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
//***** Add Pod (end) *****
|
||||
|
||||
if($pageToShow.attr("id") == "zone_page") {
|
||||
initAddPodButton($("#midmenu_add_link"), jsonObj);
|
||||
$("#midmenu_add2_link").unbind("click").hide();
|
||||
}
|
||||
else if($pageToShow.attr("id") == "pod_page") {
|
||||
//***** Add Host (begin) *****
|
||||
$("#midmenu_add_link").find("#label").text("Add Host");
|
||||
$("#midmenu_add_link").data("jsonObj", jsonObj).show();
|
||||
$("#midmenu_add_link").unbind("click").bind("click", function(event) {
|
||||
dialogAddHost = $("#dialog_add_host");
|
||||
var podObj = $(this).data("jsonObj");
|
||||
dialogAddHost.find("#zone_name").text(fromdb(podObj.zonename));
|
||||
dialogAddHost.find("#pod_name").text(fromdb(podObj.name));
|
||||
dialogAddHost.find("#new_cluster_name").val("");
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=listClusters&podid="+podObj.id+maxPageSize),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var items = json.listclustersresponse.cluster;
|
||||
var clusterSelect = dialogAddHost.find("#cluster_select").empty();
|
||||
if(items != null && items.length > 0) {
|
||||
for(var i=0; i<items.length; i++)
|
||||
clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
|
||||
dialogAddHost.find("input[value=existing_cluster_radio]").attr("checked", true);
|
||||
}
|
||||
else {
|
||||
clusterSelect.append("<option value='-1'>None Available</option>");
|
||||
dialogAddHost.find("input[value=new_cluster_radio]").attr("checked", true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialogAddHost
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
var dialogBox = $(this);
|
||||
var clusterRadio = dialogBox.find("input[name=cluster]:checked").val();
|
||||
|
||||
// validate values
|
||||
var isValid = true;
|
||||
isValid &= validateString("Host name", dialogBox.find("#host_hostname"), dialogBox.find("#host_hostname_errormsg"));
|
||||
isValid &= validateString("User name", dialogBox.find("#host_username"), dialogBox.find("#host_username_errormsg"));
|
||||
isValid &= validateString("Password", dialogBox.find("#host_password"), dialogBox.find("#host_password_errormsg"));
|
||||
if (!isValid)
|
||||
return;
|
||||
|
||||
dialogBox.dialog("close");
|
||||
|
||||
var array1 = [];
|
||||
array1.push("&zoneId="+podObj.zoneid);
|
||||
array1.push("&podId="+podObj.id);
|
||||
|
||||
var username = trim(dialogBox.find("#host_username").val());
|
||||
array1.push("&username="+encodeURIComponent(username));
|
||||
|
||||
var password = trim(dialogBox.find("#host_password").val());
|
||||
array1.push("&password="+encodeURIComponent(password));
|
||||
|
||||
if(clusterRadio == "new_cluster_radio") {
|
||||
var newClusterName = trim(dialogBox.find("#new_cluster_name").val());
|
||||
array1.push("&clustername="+todb(newClusterName));
|
||||
}
|
||||
else if(clusterRadio == "existing_cluster_radio") {
|
||||
var clusterId = dialogBox.find("#cluster_select").val();
|
||||
// We will default to no cluster if someone selects Join Cluster with no cluster available.
|
||||
if (clusterId != '-1') {
|
||||
array1.push("&clusterid="+clusterId);
|
||||
}
|
||||
}
|
||||
|
||||
var hostname = trim(dialogBox.find("#host_hostname").val());
|
||||
var url;
|
||||
if(hostname.indexOf("http://")==-1)
|
||||
url = "http://" + todb(hostname);
|
||||
else
|
||||
url = hostname;
|
||||
array1.push("&url="+encodeURIComponent(url));
|
||||
|
||||
var $midmenuItem1 = beforeAddingMidMenuItem() ;
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=addHost" + array1.join("")),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var items = json.addhostresponse.host;
|
||||
hostToMidmenu(items[0], $midmenuItem1);
|
||||
bindClickToMidMenu($midmenuItem1, hostToRigntPanel, getMidmenuId);
|
||||
afterAddingMidMenuItem($midmenuItem1, true);
|
||||
|
||||
if(items.length > 1) {
|
||||
for(var i=1; i<items.length; i++) {
|
||||
var $midmenuItem2 = $("#midmenu_item").clone();
|
||||
hostToMidmenu(items[i], $midmenuItem2);
|
||||
bindClickToMidMenu($midmenuItem2, hostToRigntPanel, getMidmenuId);
|
||||
$("#midmenu_container").append($midmenuItem2.show());
|
||||
}
|
||||
}
|
||||
|
||||
if(clusterRadio == "new_cluster_radio")
|
||||
dialogBox.find("#new_cluster_name").val("");
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);
|
||||
}
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
|
||||
//***** Add Host (end) *****
|
||||
|
||||
//***** Add Primary Storage (begin) *****
|
||||
$("#midmenu_add2_link").find("#label").text("Add Primary Storage");
|
||||
$("#midmenu_add2_link").data("jsonObj", jsonObj).show();
|
||||
$("#midmenu_add2_link").unbind("click").bind("click", function(event) {
|
||||
dialogAddPool = $("#dialog_add_pool");
|
||||
var podObj = $(this).data("jsonObj");
|
||||
dialogAddPool.find("#zone_name").text(fromdb(podObj.zonename));
|
||||
dialogAddPool.find("#pod_name").text(fromdb(podObj.name));
|
||||
|
||||
var clusterSelect = $("#dialog_add_pool").find("#pool_cluster").empty();
|
||||
$.ajax({
|
||||
data: createURL("command=listClusters&podid=" + podObj.id),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var items = json.listclustersresponse.cluster;
|
||||
if(items != null && items.length > 0) {
|
||||
for(var i=0; i<items.length; i++)
|
||||
clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#dialog_add_pool")
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
var thisDialog = $(this);
|
||||
|
||||
// validate values
|
||||
var protocol = thisDialog.find("#add_pool_protocol").val();
|
||||
|
||||
var isValid = true;
|
||||
isValid &= validateDropDownBox("Cluster", thisDialog.find("#pool_cluster"), thisDialog.find("#pool_cluster_errormsg"), false); //required, reset error text
|
||||
isValid &= validateString("Name", thisDialog.find("#add_pool_name"), thisDialog.find("#add_pool_name_errormsg"));
|
||||
isValid &= validateString("Server", thisDialog.find("#add_pool_nfs_server"), thisDialog.find("#add_pool_nfs_server_errormsg"));
|
||||
if (protocol == "nfs") {
|
||||
isValid &= validateString("Path", thisDialog.find("#add_pool_path"), thisDialog.find("#add_pool_path_errormsg"));
|
||||
} else {
|
||||
isValid &= validateString("Target IQN", thisDialog.find("#add_pool_iqn"), thisDialog.find("#add_pool_iqn_errormsg"));
|
||||
isValid &= validateString("LUN #", thisDialog.find("#add_pool_lun"), thisDialog.find("#add_pool_lun_errormsg"));
|
||||
}
|
||||
isValid &= validateString("Tags", thisDialog.find("#add_pool_tags"), thisDialog.find("#add_pool_tags_errormsg"), true); //optional
|
||||
if (!isValid)
|
||||
return;
|
||||
|
||||
thisDialog.dialog("close");
|
||||
|
||||
var $midmenuItem1 = beforeAddingMidMenuItem() ;
|
||||
|
||||
var array1 = [];
|
||||
array1.push("&zoneId="+podObj.zoneid);
|
||||
array1.push("&podId="+podObj.id);
|
||||
|
||||
var clusterId = thisDialog.find("#pool_cluster").val();
|
||||
array1.push("&clusterid="+clusterId);
|
||||
|
||||
var name = trim(thisDialog.find("#add_pool_name").val());
|
||||
array1.push("&name="+todb(name));
|
||||
|
||||
var server = trim(thisDialog.find("#add_pool_nfs_server").val());
|
||||
|
||||
var url = null;
|
||||
if (protocol == "nfs") {
|
||||
var path = trim(thisDialog.find("#add_pool_path").val());
|
||||
if(path.substring(0,1)!="/")
|
||||
path = "/" + path;
|
||||
url = nfsURL(server, path);
|
||||
} else {
|
||||
var iqn = trim(thisDialog.find("#add_pool_iqn").val());
|
||||
if(iqn.substring(0,1)!="/")
|
||||
iqn = "/" + iqn;
|
||||
var lun = trim(thisDialog.find("#add_pool_lun").val());
|
||||
url = iscsiURL(server, iqn, lun);
|
||||
}
|
||||
array1.push("&url="+encodeURIComponent(url));
|
||||
|
||||
var tags = trim(thisDialog.find("#add_pool_tags").val());
|
||||
if(tags != null && tags.length > 0)
|
||||
array1.push("&tags="+todb(tags));
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=createStoragePool&response=json" + array1.join("")),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var item = json.createstoragepoolresponse;
|
||||
primarystorageToMidmenu(item, $midmenuItem1);
|
||||
bindClickToMidMenu($midmenuItem1, primarystorageToRigntPanel, getMidmenuId);
|
||||
afterAddingMidMenuItem($midmenuItem1, true);
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);
|
||||
}
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
//***** Add Primary Storage (end) *****
|
||||
initAddHostButton($("#midmenu_add_link"), jsonObj);
|
||||
initAddPrimaryStorageButton($("#midmenu_add2_link"), jsonObj);
|
||||
}
|
||||
else {
|
||||
$("#midmenu_add_link").unbind("click").hide();
|
||||
@ -711,10 +416,32 @@ function afterLoadResourceJSP() {
|
||||
}
|
||||
});
|
||||
|
||||
//Add Zone button ***
|
||||
$("#midmenu_add_link").find("#label").text("Add Zone");
|
||||
$("#midmenu_add_link").show();
|
||||
$("#midmenu_add_link").unbind("click").bind("click", function(event) {
|
||||
//initialize Add Zone button
|
||||
initAddZoneButton($("#midmenu_add_link"));
|
||||
}
|
||||
|
||||
function nfsURL(server, path) {
|
||||
var url;
|
||||
if(server.indexOf("://")==-1)
|
||||
url = "nfs://" + server + path;
|
||||
else
|
||||
url = server + path;
|
||||
return url;
|
||||
}
|
||||
|
||||
function iscsiURL(server, iqn, lun) {
|
||||
var url;
|
||||
if(server.indexOf("://")==-1)
|
||||
url = "iscsi://" + server + iqn + "/" + lun;
|
||||
else
|
||||
url = server + iqn + "/" + lun;
|
||||
return url;
|
||||
}
|
||||
|
||||
function initAddZoneButton($midmenuAddLink1) {
|
||||
$midmenuAddLink1.find("#label").text("Add Zone");
|
||||
$midmenuAddLink1.show();
|
||||
$midmenuAddLink1.unbind("click").bind("click", function(event) {
|
||||
$("#dialog_add_zone")
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
@ -807,24 +534,303 @@ function afterLoadResourceJSP() {
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function nfsURL(server, path) {
|
||||
var url;
|
||||
if(server.indexOf("://")==-1)
|
||||
url = "nfs://" + server + path;
|
||||
else
|
||||
url = server + path;
|
||||
return url;
|
||||
function initAddPodButton($midmenuAddLink1, jsonObj) {
|
||||
$midmenuAddLink1.find("#label").text("Add Pod");
|
||||
$midmenuAddLink1.data("jsonObj", jsonObj).show();
|
||||
$midmenuAddLink1.unbind("click").bind("click", function(event) {
|
||||
var zoneObj = $(this).data("jsonObj");
|
||||
$("#dialog_add_pod").find("#add_pod_zone_name").text(fromdb(zoneObj.name));
|
||||
$("#dialog_add_pod #add_pod_name, #dialog_add_pod #add_pod_cidr, #dialog_add_pod #add_pod_startip, #dialog_add_pod #add_pod_endip, #add_pod_gateway").val("");
|
||||
|
||||
$("#dialog_add_pod")
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
var thisDialog = $(this);
|
||||
|
||||
// validate values
|
||||
var isValid = true;
|
||||
isValid &= validateString("Name", thisDialog.find("#add_pod_name"), thisDialog.find("#add_pod_name_errormsg"));
|
||||
isValid &= validateCIDR("CIDR", thisDialog.find("#add_pod_cidr"), thisDialog.find("#add_pod_cidr_errormsg"));
|
||||
isValid &= validateIp("Start IP Range", thisDialog.find("#add_pod_startip"), thisDialog.find("#add_pod_startip_errormsg")); //required
|
||||
isValid &= validateIp("End IP Range", thisDialog.find("#add_pod_endip"), thisDialog.find("#add_pod_endip_errormsg"), true); //optional
|
||||
isValid &= validateIp("Gateway", thisDialog.find("#add_pod_gateway"), thisDialog.find("#add_pod_gateway_errormsg")); //required when creating
|
||||
if (!isValid)
|
||||
return;
|
||||
|
||||
thisDialog.dialog("close");
|
||||
|
||||
var name = trim(thisDialog.find("#add_pod_name").val());
|
||||
var cidr = trim(thisDialog.find("#add_pod_cidr").val());
|
||||
var startip = trim(thisDialog.find("#add_pod_startip").val());
|
||||
var endip = trim(thisDialog.find("#add_pod_endip").val()); //optional
|
||||
var gateway = trim(thisDialog.find("#add_pod_gateway").val());
|
||||
|
||||
var array1 = [];
|
||||
array1.push("&zoneId="+zoneObj.id);
|
||||
array1.push("&name="+todb(name));
|
||||
array1.push("&cidr="+encodeURIComponent(cidr));
|
||||
array1.push("&startIp="+encodeURIComponent(startip));
|
||||
if (endip != null && endip.length > 0)
|
||||
array1.push("&endIp="+encodeURIComponent(endip));
|
||||
array1.push("&gateway="+encodeURIComponent(gateway));
|
||||
|
||||
var template = $("#leftmenu_pod_node_template").clone(true);
|
||||
var loadingImg = template.find(".adding_loading");
|
||||
var row_container = template.find("#row_container");
|
||||
$("#zone_" + zoneObj.id + " #zone_content").show();
|
||||
$("#zone_" + zoneObj.id + " #pods_container").prepend(template.show());
|
||||
$("#zone_" + zoneObj.id + " #zone_expand").removeClass().addClass("zonetree_openarrows");
|
||||
loadingImg.show();
|
||||
row_container.hide();
|
||||
template.fadeIn("slow");
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=createPod"+array1.join("")),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var item = json.createpodresponse;
|
||||
podJSONToTreeNode(item, template);
|
||||
loadingImg.hide();
|
||||
row_container.show();
|
||||
|
||||
forceLogout = false; // We don't force a logout if pod(s) exit.
|
||||
if (forceLogout) {
|
||||
$("#dialog_confirmation")
|
||||
.html("<p>You have successfully added your first Zone and Pod. After clicking 'OK', this UI will automatically refresh to give you access to the rest of cloud features.</p>")
|
||||
.dialog('option', 'buttons', {
|
||||
"OK": function() {
|
||||
$(this).dialog("close");
|
||||
window.location.reload();
|
||||
}
|
||||
}).dialog("open");
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleError(XMLHttpResponse);
|
||||
template.slideUp("slow", function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function iscsiURL(server, iqn, lun) {
|
||||
var url;
|
||||
if(server.indexOf("://")==-1)
|
||||
url = "iscsi://" + server + iqn + "/" + lun;
|
||||
else
|
||||
url = server + iqn + "/" + lun;
|
||||
return url;
|
||||
function initAddHostButton($midmenuAddLink1, jsonObj) {
|
||||
$midmenuAddLink1.find("#label").text("Add Host");
|
||||
$midmenuAddLink1.data("jsonObj", jsonObj).show();
|
||||
$midmenuAddLink1.unbind("click").bind("click", function(event) {
|
||||
dialogAddHost = $("#dialog_add_host");
|
||||
var podObj = $(this).data("jsonObj");
|
||||
dialogAddHost.find("#zone_name").text(fromdb(podObj.zonename));
|
||||
dialogAddHost.find("#pod_name").text(fromdb(podObj.name));
|
||||
dialogAddHost.find("#new_cluster_name").val("");
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=listClusters&podid="+podObj.id+maxPageSize),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var items = json.listclustersresponse.cluster;
|
||||
var clusterSelect = dialogAddHost.find("#cluster_select").empty();
|
||||
if(items != null && items.length > 0) {
|
||||
for(var i=0; i<items.length; i++)
|
||||
clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
|
||||
dialogAddHost.find("input[value=existing_cluster_radio]").attr("checked", true);
|
||||
}
|
||||
else {
|
||||
clusterSelect.append("<option value='-1'>None Available</option>");
|
||||
dialogAddHost.find("input[value=new_cluster_radio]").attr("checked", true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialogAddHost
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
var dialogBox = $(this);
|
||||
var clusterRadio = dialogBox.find("input[name=cluster]:checked").val();
|
||||
|
||||
// validate values
|
||||
var isValid = true;
|
||||
isValid &= validateString("Host name", dialogBox.find("#host_hostname"), dialogBox.find("#host_hostname_errormsg"));
|
||||
isValid &= validateString("User name", dialogBox.find("#host_username"), dialogBox.find("#host_username_errormsg"));
|
||||
isValid &= validateString("Password", dialogBox.find("#host_password"), dialogBox.find("#host_password_errormsg"));
|
||||
if (!isValid)
|
||||
return;
|
||||
|
||||
dialogBox.dialog("close");
|
||||
|
||||
var array1 = [];
|
||||
array1.push("&zoneId="+podObj.zoneid);
|
||||
array1.push("&podId="+podObj.id);
|
||||
|
||||
var username = trim(dialogBox.find("#host_username").val());
|
||||
array1.push("&username="+encodeURIComponent(username));
|
||||
|
||||
var password = trim(dialogBox.find("#host_password").val());
|
||||
array1.push("&password="+encodeURIComponent(password));
|
||||
|
||||
if(clusterRadio == "new_cluster_radio") {
|
||||
var newClusterName = trim(dialogBox.find("#new_cluster_name").val());
|
||||
array1.push("&clustername="+todb(newClusterName));
|
||||
}
|
||||
else if(clusterRadio == "existing_cluster_radio") {
|
||||
var clusterId = dialogBox.find("#cluster_select").val();
|
||||
// We will default to no cluster if someone selects Join Cluster with no cluster available.
|
||||
if (clusterId != '-1') {
|
||||
array1.push("&clusterid="+clusterId);
|
||||
}
|
||||
}
|
||||
|
||||
var hostname = trim(dialogBox.find("#host_hostname").val());
|
||||
var url;
|
||||
if(hostname.indexOf("http://")==-1)
|
||||
url = "http://" + todb(hostname);
|
||||
else
|
||||
url = hostname;
|
||||
array1.push("&url="+encodeURIComponent(url));
|
||||
|
||||
var $midmenuItem1 = beforeAddingMidMenuItem() ;
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=addHost" + array1.join("")),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var items = json.addhostresponse.host;
|
||||
hostToMidmenu(items[0], $midmenuItem1);
|
||||
bindClickToMidMenu($midmenuItem1, hostToRigntPanel, getMidmenuId);
|
||||
afterAddingMidMenuItem($midmenuItem1, true);
|
||||
|
||||
if(items.length > 1) {
|
||||
for(var i=1; i<items.length; i++) {
|
||||
var $midmenuItem2 = $("#midmenu_item").clone();
|
||||
hostToMidmenu(items[i], $midmenuItem2);
|
||||
bindClickToMidMenu($midmenuItem2, hostToRigntPanel, getMidmenuId);
|
||||
$("#midmenu_container").append($midmenuItem2.show());
|
||||
}
|
||||
}
|
||||
|
||||
if(clusterRadio == "new_cluster_radio")
|
||||
dialogBox.find("#new_cluster_name").val("");
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);
|
||||
}
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function initAddPrimaryStorageButton($midmenuAddLink2, jsonObj) {
|
||||
$midmenuAddLink2.find("#label").text("Add Primary Storage");
|
||||
$midmenuAddLink2.data("jsonObj", jsonObj).show();
|
||||
$midmenuAddLink2.unbind("click").bind("click", function(event) {
|
||||
dialogAddPool = $("#dialog_add_pool");
|
||||
var podObj = $(this).data("jsonObj");
|
||||
dialogAddPool.find("#zone_name").text(fromdb(podObj.zonename));
|
||||
dialogAddPool.find("#pod_name").text(fromdb(podObj.name));
|
||||
|
||||
var clusterSelect = $("#dialog_add_pool").find("#pool_cluster").empty();
|
||||
$.ajax({
|
||||
data: createURL("command=listClusters&podid=" + podObj.id),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var items = json.listclustersresponse.cluster;
|
||||
if(items != null && items.length > 0) {
|
||||
for(var i=0; i<items.length; i++)
|
||||
clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#dialog_add_pool")
|
||||
.dialog('option', 'buttons', {
|
||||
"Add": function() {
|
||||
var thisDialog = $(this);
|
||||
|
||||
// validate values
|
||||
var protocol = thisDialog.find("#add_pool_protocol").val();
|
||||
|
||||
var isValid = true;
|
||||
isValid &= validateDropDownBox("Cluster", thisDialog.find("#pool_cluster"), thisDialog.find("#pool_cluster_errormsg"), false); //required, reset error text
|
||||
isValid &= validateString("Name", thisDialog.find("#add_pool_name"), thisDialog.find("#add_pool_name_errormsg"));
|
||||
isValid &= validateString("Server", thisDialog.find("#add_pool_nfs_server"), thisDialog.find("#add_pool_nfs_server_errormsg"));
|
||||
if (protocol == "nfs") {
|
||||
isValid &= validateString("Path", thisDialog.find("#add_pool_path"), thisDialog.find("#add_pool_path_errormsg"));
|
||||
} else {
|
||||
isValid &= validateString("Target IQN", thisDialog.find("#add_pool_iqn"), thisDialog.find("#add_pool_iqn_errormsg"));
|
||||
isValid &= validateString("LUN #", thisDialog.find("#add_pool_lun"), thisDialog.find("#add_pool_lun_errormsg"));
|
||||
}
|
||||
isValid &= validateString("Tags", thisDialog.find("#add_pool_tags"), thisDialog.find("#add_pool_tags_errormsg"), true); //optional
|
||||
if (!isValid)
|
||||
return;
|
||||
|
||||
thisDialog.dialog("close");
|
||||
|
||||
var $midmenuItem1 = beforeAddingMidMenuItem() ;
|
||||
|
||||
var array1 = [];
|
||||
array1.push("&zoneId="+podObj.zoneid);
|
||||
array1.push("&podId="+podObj.id);
|
||||
|
||||
var clusterId = thisDialog.find("#pool_cluster").val();
|
||||
array1.push("&clusterid="+clusterId);
|
||||
|
||||
var name = trim(thisDialog.find("#add_pool_name").val());
|
||||
array1.push("&name="+todb(name));
|
||||
|
||||
var server = trim(thisDialog.find("#add_pool_nfs_server").val());
|
||||
|
||||
var url = null;
|
||||
if (protocol == "nfs") {
|
||||
var path = trim(thisDialog.find("#add_pool_path").val());
|
||||
if(path.substring(0,1)!="/")
|
||||
path = "/" + path;
|
||||
url = nfsURL(server, path);
|
||||
} else {
|
||||
var iqn = trim(thisDialog.find("#add_pool_iqn").val());
|
||||
if(iqn.substring(0,1)!="/")
|
||||
iqn = "/" + iqn;
|
||||
var lun = trim(thisDialog.find("#add_pool_lun").val());
|
||||
url = iscsiURL(server, iqn, lun);
|
||||
}
|
||||
array1.push("&url="+encodeURIComponent(url));
|
||||
|
||||
var tags = trim(thisDialog.find("#add_pool_tags").val());
|
||||
if(tags != null && tags.length > 0)
|
||||
array1.push("&tags="+todb(tags));
|
||||
|
||||
$.ajax({
|
||||
data: createURL("command=createStoragePool&response=json" + array1.join("")),
|
||||
dataType: "json",
|
||||
success: function(json) {
|
||||
var item = json.createstoragepoolresponse;
|
||||
primarystorageToMidmenu(item, $midmenuItem1);
|
||||
bindClickToMidMenu($midmenuItem1, primarystorageToRigntPanel, getMidmenuId);
|
||||
afterAddingMidMenuItem($midmenuItem1, true);
|
||||
},
|
||||
error: function(XMLHttpResponse) {
|
||||
handleErrorInMidMenu(XMLHttpResponse, $midmenuItem1);
|
||||
}
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}).dialog("open");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user