create shared function populateClusterFieldInAddPoolDialog() - reduce code repetition.

This commit is contained in:
Jessica Wang 2011-02-09 14:26:47 -08:00
parent 25a9236438
commit 118ab360d0
3 changed files with 43 additions and 75 deletions

View File

@ -630,28 +630,8 @@ function bindAddPrimaryStorageButton($leftmenuItem1) {
$dialogAddPool.find("#pod_name").text(fromdb(clusterObj.podname));
}
var $clusterSelect = $("#dialog_add_pool").find("#pool_cluster").empty();
$.ajax({
data: createURL("command=listClusters&podid=" + podId),
async: false,
dataType: "json",
success: function(json) {
var items = json.listclustersresponse.cluster;
if(items != null && items.length > 0) {
clustersUnderPod = {};
for(var i=0; i<items.length; i++) {
clustersUnderPod["cluster_"+items[i].id] = items[i];
if(sourceClusterId != null && items[i].id == sourceClusterId)
$clusterSelect.append("<option value='" + items[i].id + "' selected>" + fromdb(items[i].name) + "</option>");
else
$clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
}
}
}
});
bindAddPrimaryStorageDialog($dialogAddPool);
populateClusterFieldInAddPoolDialog($dialogAddPool, podId);
bindClusterFieldInAddPoolDialog($dialogAddPool);
$button.unbind("click").bind("click", function(event) {
$dialogAddPool.find("#info_container").hide();

View File

@ -1617,17 +1617,44 @@ function initUpdateConsoleCertButton($midMenuAddLink2) {
}
var clustersUnderPod = {};
function bindAddPrimaryStorageDialog($dialog) {
$dialog.find("#pool_cluster").unbind("change").change(function() {
var curOption = $(this).val();
if(!curOption)
function populateClusterFieldInAddPoolDialog($dialog, podId) {
$.ajax({
data: createURL("command=listClusters&podid=" + podId),
dataType: "json",
async: false,
success: function(json) {
clustersUnderPod = {};
var items = json.listclustersresponse.cluster;
var $clusterSelect = $dialog.find("#pool_cluster").empty();
if(items != null && items.length > 0) {
for(var i=0; i<items.length; i++) {
clustersUnderPod["cluster_"+items[i].id] = items[i];
$clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
}
}
$clusterSelect.change();
}
});
}
function bindClusterFieldInAddPoolDialog($dialog) {
$dialog.find("#pool_cluster").unbind("change").change(function(event) {
event.stopPropagation();;
var $protocolSelector = $dialog.find("#add_pool_protocol");
var clusterId = $(this).val();
if(clusterId == null) {
$protocolSelector.empty();
return false;
}
var $protocolSelector = $dialog.find("#add_pool_protocol");
var clusterObj = clustersUnderPod['cluster_'+curOption];
if(clusterObj == null)
return;
var clusterObj = clustersUnderPod['cluster_'+clusterId];
if(clusterObj == null) {
$protocolSelector.empty();
return false;
}
if(clusterObj.hypervisortype == "KVM") {
$protocolSelector.empty();
@ -1682,30 +1709,11 @@ function initAddPrimaryStorageShortcut($midmenuAddLink2, currentPageInRightPanel
$dialogAddPool.find("#pod_dropdown").bind("change", function(event) {
var podId = $(this).val();
if(podId == null || podId.length == 0)
return;
var $clusterSelect = $dialogAddPool.find("#pool_cluster").empty();
$.ajax({
data: createURL("command=listClusters&podid=" + podId),
dataType: "json",
async: false,
success: function(json) {
clustersUnderPod = {};
var items = json.listclustersresponse.cluster;
if(items != null && items.length > 0) {
for(var i=0; i<items.length; i++) {
clustersUnderPod["cluster_"+items[i].id] = items[i];
$clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
}
if(!$clusterSelect.val())
$("option", $clusterSelect)[0].attr("selected", "selected");
$clusterSelect.change();
}
}
});
return;
populateClusterFieldInAddPoolDialog($dialogAddPool, podId);
});
bindAddPrimaryStorageDialog($dialogAddPool);
bindClusterFieldInAddPoolDialog($dialogAddPool);
$("#add_primarystorage_shortcut").unbind("click").bind("click", function(event) {
$dialogAddPool.find("#zone_dropdown").change(); //refresh cluster dropdown (do it here to avoid race condition)

View File

@ -830,30 +830,10 @@ function bindAddPrimaryStorageButtonOnZonePage($button, zoneId, zoneName) {
var podId = $(this).val();
if(podId == null || podId.length == 0)
return;
var $clusterSelect = $dialogAddPool.find("#pool_cluster").empty();
$.ajax({
data: createURL("command=listClusters&podid=" + podId),
dataType: "json",
async: false,
success: function(json) {
var items = json.listclustersresponse.cluster;
if(items != null && items.length > 0) {
clustersUnderPod = {};
for(var i=0; i<items.length; i++) {
clustersUnderPod["cluster_"+items[i].id] = items[i];
$clusterSelect.append("<option value='" + items[i].id + "'>" + fromdb(items[i].name) + "</option>");
}
if(!$clusterSelect.val()) {
$("option", $clusterSelect)[0].attr("selected", "selected");
}
$clusterSelect.change();
}
}
});
populateClusterFieldInAddPoolDialog($dialogAddPool, podId);
});
bindAddPrimaryStorageDialog($dialogAddPool);
bindClusterFieldInAddPoolDialog($dialogAddPool);
$button.unbind("click").bind("click", function(event) {
$dialogAddPool.find("#info_container").hide();