diff --git a/ui/new/jsp/tab_instances.html b/ui/new/jsp/tab_instances.html deleted file mode 100755 index 4cecc8f6626..00000000000 --- a/ui/new/jsp/tab_instances.html +++ /dev/null @@ -1,128 +0,0 @@ -
-
- Instance
-

- Name of the Instance Selected.. -

-
-
-
-
- Details
-
- Volume
-
- Statistics
-
-
-
-
-
-
-
-
- Running
-
-

- 10.1.1.200

-
-
-
-
-
-
- Zone:
-
-
-
- JW
-
-
-
-
-
- Template:
-
-
-
- Centos 5.3(x36.4) no GUI
-
-
-
-
-
- Service:
-
-
-
- Small Instance
-
-
-
-
-
- HA:
-
-
-
-
-
-
-
-
-
-
-
- Created:
-
-
-
- 07/20/2010 11:29:04 -
-
-
-
-
-
- Account:
-
-
-
- Admin
-
-
-
-
-
- Domain:
-
-
-
- ROOT
-
-
-
-
-
- Host:
-
-
-
- Xenserver-test5 -
-
-
-
-
-
- ISO:
-
-
-
-
-
-
-
-
-
-
diff --git a/ui/new/scripts/cloud.core.js b/ui/new/scripts/cloud.core.js index 366e089c0ab..2ff90c72b3e 100755 --- a/ui/new/scripts/cloud.core.js +++ b/ui/new/scripts/cloud.core.js @@ -16,788 +16,784 @@ * */ -<<<<<<< HEAD -// Version: @VERSION@ -======= -// Version: 1.9.1.6 ->>>>>>> 10bc0b5... new UI - left menu, middle menu, instance -var g_mySession = null; -var g_sessionKey = null; -var g_role = null; // roles - root, domain-admin, ro-admin, user -var g_username = null; -var g_account = null; -var g_domainid = null; -var g_enableLogging = false; + +var g_mySession = null; +var g_sessionKey = null; +var g_role = null; // roles - root, domain-admin, ro-admin, user +var g_username = null; +var g_account = null; +var g_domainid = null; +var g_enableLogging = false; var g_timezoneoffset = null; -var g_timezone = null; - -// capabilities -var g_networkType = "vnet"; // vnet, vlan, direct -function getNetworkType() { return g_networkType; } - -var g_hypervisorType = "kvm"; -function getHypervisorType() { return g_hypervisorType; } - -var g_directAttachNetworkGroupsEnabled = "false"; +var g_timezone = null; + +// capabilities +var g_networkType = "vnet"; // vnet, vlan, direct +function getNetworkType() { return g_networkType; } + +var g_hypervisorType = "kvm"; +function getHypervisorType() { return g_hypervisorType; } + +var g_directAttachNetworkGroupsEnabled = "false"; function getDirectAttachNetworkGroupsEnabled() { return g_directAttachNetworkGroupsEnabled; } var g_directAttachedUntaggedEnabled = "false" -function getDirectAttachUntaggedEnabled() { return g_directAttachedUntaggedEnabled; } - +function getDirectAttachUntaggedEnabled() { return g_directAttachedUntaggedEnabled; } + var g_systemVmUseLocalStorage = "false" -function getSystemVmUseLocalStorage() { return g_systemVmUseLocalStorage; } - -//keyboard keycode -var keycode_Enter = 13; - -//dropdown field size -var maxPageSize = "&pagesize=500"; - -//XMLHttpResponse.status -var ERROR_ACCESS_DENIED_DUE_TO_UNAUTHORIZED = 401; -var ERROR_INTERNET_NAME_NOT_RESOLVED = 12007; -var ERROR_INTERNET_CANNOT_CONNECT = 12029; -var ERROR_VMOPS_ACCOUNT_ERROR = 531; - -var g_logger = new Logger(); -$(function() { - if(g_enableLogging) - g_logger.open(); -}); - -// Test Tool. Please comment this out or remove this when going production. -// This is intended to provide a simple test tool to create user accounts and -// domains. -function initializeTestTool() { - $("#launch_test").click(function(event) { - testWindow = window.open('/client/test'); +function getSystemVmUseLocalStorage() { return g_systemVmUseLocalStorage; } + +//keyboard keycode +var keycode_Enter = 13; + +//dropdown field size +var maxPageSize = "&pagesize=500"; + +//XMLHttpResponse.status +var ERROR_ACCESS_DENIED_DUE_TO_UNAUTHORIZED = 401; +var ERROR_INTERNET_NAME_NOT_RESOLVED = 12007; +var ERROR_INTERNET_CANNOT_CONNECT = 12029; +var ERROR_VMOPS_ACCOUNT_ERROR = 531; + +var g_logger = new Logger(); +$(function() { + if(g_enableLogging) + g_logger.open(); +}); + +// Test Tool. Please comment this out or remove this when going production. +// This is intended to provide a simple test tool to create user accounts and +// domains. +function initializeTestTool() { + $("#launch_test").click(function(event) { + testWindow = window.open('/client/test'); testWindow.g_sessionKey=g_sessionKey; - return false; - }); -} - -// Role Functions -function isAdmin() { - return (g_role == 1); -} - -function isUser() { - return (g_role == 0); -} - -function isDomainAdmin() { - return (g_role == 2); -} - + return false; + }); +} + +// Role Functions +function isAdmin() { + return (g_role == 1); +} + +function isUser() { + return (g_role == 0); +} + +function isDomainAdmin() { + return (g_role == 2); +} + function createURL(url) { return url + "&sessionkey=" + g_sessionKey; } -function setDateField(dateValue, dateField, htmlMarkup) { - if (dateValue != null && dateValue.length > 0) { - var disconnected = new Date(); - disconnected.setISO8601(dateValue); - var showDate; - if(g_timezoneoffset != null) - showDate = disconnected.getTimePlusTimezoneOffset(g_timezoneoffset); - else - showDate = disconnected.format("m/d/Y H:i:s"); - if(htmlMarkup == null) - dateField.text(showDate); - else - dateField.html(htmlMarkup + showDate); - } -} - -function initResizable(resizeElement, alsoResizeElement) { - var alsoResizeUi_originalHeight; - $("#"+resizeElement).resizable({ - handles: 'e, w', - autoHide: true, - //containment: ".grid_header" , - alsoResize: "."+alsoResizeElement - }); -} - -var sortBy = ""; -var parseFunction = function() {} -var sortingOrder = "asc"; - -function sortArrayAlphabetically(a, b) { - if(a[sortBy] == null || b[sortBy] == null) - return 0; - - var A = a[sortBy].toLowerCase(); - var B = b[sortBy].toLowerCase(); - - if(sortingOrder == "asc") { - if (A < B) - return -1; - if (A > B) - return 1; - } else { - if (A < B) - return 1; - if (A > B) - return -1; - } - return 0; -} - -function sortArrayAlphabeticallyParse(a, b) { - if(a[sortBy] == null || b[sortBy] == null) - return 0; - - var A = parseFunction(a[sortBy]).toLowerCase(); - var B = parseFunction(b[sortBy]).toLowerCase(); - - if(sortingOrder == "asc") { - if (A < B) - return -1; - if (A > B) - return 1; - } else { - if (A < B) - return 1; - if (A > B) - return -1; - } - return 0; -} - -function sortArrayNumerically(a, b) { - if(a[sortBy] == null || b[sortBy] == null) - return 0; - - var A = parseInt(a[sortBy]); - var B = parseInt(b[sortBy]); - - if(sortingOrder == "asc") { - if (A < B) - return -1; - if (A > B) - return 1; - } else { - if (A < B) - return 1; - if (A > B) - return -1; - } - return 0; -} - -function sortArrayNumericallyParse(a, b) { - if(a[sortBy] == null || b[sortBy] == null) - return 0; - - var A = parseFunction(parseInt(a[sortBy])); - var B = parseFunction(parseInt(b[sortBy])); - - if(sortingOrder == "asc") { - if (A < B) - return -1; - if (A > B) - return 1; - } else { - if (A < B) - return 1; - if (A > B) - return -1; - } - return 0; -} - -function sortArrayByDate(a, b) { - if(a[sortBy] == null || b[sortBy] == null) - return 0; - - var A = convertMilliseconds(a[sortBy]); - var B = convertMilliseconds(b[sortBy]); - - if(sortingOrder == "asc") { - if (A < B) - return -1; - if (A > B) - return 1; - } else { - if (A < B) - return 1; - if (A > B) - return -1; - } - return 0; -} - -function convertMilliseconds(string) { - if (string != null && string.length > 0) { - var date1 = new Date(); - date1.setISO8601(string); - return date1.getTime(); - } else { - return null; - } -} - -function drawGrid(items, submenuContent, template, fnJSONToTemplate) { - var grid = submenuContent.find("#grid_content").empty(); - if (items != null && items.length > 0) { - for (var i = 0; i < items.length; i++) { - var newTemplate = template.clone(true); - fnJSONToTemplate(items[i], newTemplate); - grid.append(newTemplate.show()); - } - setGridRowsTotal(submenuContent.find("#grid_rows_total"), items.length); - if(items.length < pageSize) - submenuContent.find("#nextPage_div").hide(); - else - submenuContent.find("#nextPage_div").show(); - } else { - setGridRowsTotal(submenuContent.find("#grid_rows_total"), null); - submenuContent.find("#nextPage_div").hide(); - } -} - -//listItems() function takes care of loading image, pagination -var items = []; +function setDateField(dateValue, dateField, htmlMarkup) { + if (dateValue != null && dateValue.length > 0) { + var disconnected = new Date(); + disconnected.setISO8601(dateValue); + var showDate; + if(g_timezoneoffset != null) + showDate = disconnected.getTimePlusTimezoneOffset(g_timezoneoffset); + else + showDate = disconnected.format("m/d/Y H:i:s"); + if(htmlMarkup == null) + dateField.text(showDate); + else + dateField.html(htmlMarkup + showDate); + } +} + +function initResizable(resizeElement, alsoResizeElement) { + var alsoResizeUi_originalHeight; + $("#"+resizeElement).resizable({ + handles: 'e, w', + autoHide: true, + //containment: ".grid_header" , + alsoResize: "."+alsoResizeElement + }); +} + +var sortBy = ""; +var parseFunction = function() {} +var sortingOrder = "asc"; + +function sortArrayAlphabetically(a, b) { + if(a[sortBy] == null || b[sortBy] == null) + return 0; + + var A = a[sortBy].toLowerCase(); + var B = b[sortBy].toLowerCase(); + + if(sortingOrder == "asc") { + if (A < B) + return -1; + if (A > B) + return 1; + } else { + if (A < B) + return 1; + if (A > B) + return -1; + } + return 0; +} + +function sortArrayAlphabeticallyParse(a, b) { + if(a[sortBy] == null || b[sortBy] == null) + return 0; + + var A = parseFunction(a[sortBy]).toLowerCase(); + var B = parseFunction(b[sortBy]).toLowerCase(); + + if(sortingOrder == "asc") { + if (A < B) + return -1; + if (A > B) + return 1; + } else { + if (A < B) + return 1; + if (A > B) + return -1; + } + return 0; +} + +function sortArrayNumerically(a, b) { + if(a[sortBy] == null || b[sortBy] == null) + return 0; + + var A = parseInt(a[sortBy]); + var B = parseInt(b[sortBy]); + + if(sortingOrder == "asc") { + if (A < B) + return -1; + if (A > B) + return 1; + } else { + if (A < B) + return 1; + if (A > B) + return -1; + } + return 0; +} + +function sortArrayNumericallyParse(a, b) { + if(a[sortBy] == null || b[sortBy] == null) + return 0; + + var A = parseFunction(parseInt(a[sortBy])); + var B = parseFunction(parseInt(b[sortBy])); + + if(sortingOrder == "asc") { + if (A < B) + return -1; + if (A > B) + return 1; + } else { + if (A < B) + return 1; + if (A > B) + return -1; + } + return 0; +} + +function sortArrayByDate(a, b) { + if(a[sortBy] == null || b[sortBy] == null) + return 0; + + var A = convertMilliseconds(a[sortBy]); + var B = convertMilliseconds(b[sortBy]); + + if(sortingOrder == "asc") { + if (A < B) + return -1; + if (A > B) + return 1; + } else { + if (A < B) + return 1; + if (A > B) + return -1; + } + return 0; +} + +function convertMilliseconds(string) { + if (string != null && string.length > 0) { + var date1 = new Date(); + date1.setISO8601(string); + return date1.getTime(); + } else { + return null; + } +} + +function drawGrid(items, submenuContent, template, fnJSONToTemplate) { + var grid = submenuContent.find("#grid_content").empty(); + if (items != null && items.length > 0) { + for (var i = 0; i < items.length; i++) { + var newTemplate = template.clone(true); + fnJSONToTemplate(items[i], newTemplate); + grid.append(newTemplate.show()); + } + setGridRowsTotal(submenuContent.find("#grid_rows_total"), items.length); + if(items.length < pageSize) + submenuContent.find("#nextPage_div").hide(); + else + submenuContent.find("#nextPage_div").show(); + } else { + setGridRowsTotal(submenuContent.find("#grid_rows_total"), null); + submenuContent.find("#nextPage_div").hide(); + } +} + +//listItems() function takes care of loading image, pagination +var items = []; function listItems(submenuContent, commandString, jsonResponse1, jsonResponse2, template, fnJSONToTemplate ) { - if(currentPage==1) - submenuContent.find("#prevPage_div").hide(); - else + if(currentPage==1) + submenuContent.find("#prevPage_div").hide(); + else submenuContent.find("#prevPage_div").show(); submenuContent.find("#loading_gridtable").show(); - submenuContent.find("#pagination_panel").hide(); + submenuContent.find("#pagination_panel").hide(); index = 0; - $.ajax({ - data: createURL(commandString), - dataType: "json", - async: false, + $.ajax({ + data: createURL(commandString), + dataType: "json", + async: false, success: function(json) { - //IF jsonResponse1=="listaccountsresponse", jsonResponse2=="account", THEN json[jsonResponse1][jsonResponse2] == json.listaccountsresponse.account - items = json[jsonResponse1][jsonResponse2]; - drawGrid(items, submenuContent, template, fnJSONToTemplate); - submenuContent.find("#loading_gridtable").hide(); - submenuContent.find("#pagination_panel").show(); - }, - error: function(XMLHttpResponse) { - submenuContent.find("#loading_gridtable").hide(); - handleError(XMLHttpResponse, function() { - if(XMLHttpResponse.status == ERROR_VMOPS_ACCOUNT_ERROR) { - submenuContent.find("#grid_content").empty(); - setGridRowsTotal(submenuContent.find("#grid_rows_total"), null); - submenuContent.find("#nextPage_div").hide(); - } - submenuContent.find("#loading_gridtable").hide(); - submenuContent.find("#pagination_panel").show(); - }); - } - }); -} - - -//event binder -var currentPage = 1; -var pageSize = 50; //consistent with server-side -function submenuContentEventBinder(submenuContent, listFunction) { - submenuContent.find("#nextPage").bind("click", function(event){ - event.preventDefault(); - currentPage++; - listFunction(); - }); - - submenuContent.find("#prevPage").bind("click", function(event){ - event.preventDefault(); - currentPage--; - listFunction(); - }); - - submenuContent.find("#refresh").bind("click", function(event){ - event.preventDefault(); - currentPage=1; - listFunction(); - }); - - submenuContent.find("#search_button").bind("click", function(event) { - event.preventDefault(); - currentPage = 1; - listFunction(); - }); - - submenuContent.find("#adv_search_button").bind("click", function(event) { - event.preventDefault(); - currentPage = 1; - listFunction(); - submenuContent.find("#search_button").data("advanced", false); - submenuContent.find("#advanced_search").hide(); - }); - - submenuContent.find("#search_input").bind("keypress", function(event) { - if(event.keyCode == keycode_Enter) { - event.preventDefault(); - submenuContent.find("#search_button").click(); - } - }); - - submenuContent.find("#advanced_search").bind("keypress", function(event) { - if(event.keyCode == keycode_Enter) { - event.preventDefault(); - submenuContent.find("#adv_search_button").click(); - } - }); - - submenuContent.find("#advanced_search_close").bind("click", function(event) { - event.preventDefault(); - submenuContent.find("#search_button").data("advanced", false); - submenuContent.find("#advanced_search").hide(); - }); - - submenuContent.find("#advanced_search_link").bind("click", function(event) { - event.preventDefault(); - submenuContent.find("#search_button").data("advanced", true); - submenuContent.find("#advanced_search").show(); - }); - - var zoneSelect = submenuContent.find("#advanced_search #adv_search_zone"); - if(zoneSelect.length>0) { //if zone dropdown is found on Advanced Search dialog - $.ajax({ + //IF jsonResponse1=="listaccountsresponse", jsonResponse2=="account", THEN json[jsonResponse1][jsonResponse2] == json.listaccountsresponse.account + items = json[jsonResponse1][jsonResponse2]; + drawGrid(items, submenuContent, template, fnJSONToTemplate); + submenuContent.find("#loading_gridtable").hide(); + submenuContent.find("#pagination_panel").show(); + }, + error: function(XMLHttpResponse) { + submenuContent.find("#loading_gridtable").hide(); + handleError(XMLHttpResponse, function() { + if(XMLHttpResponse.status == ERROR_VMOPS_ACCOUNT_ERROR) { + submenuContent.find("#grid_content").empty(); + setGridRowsTotal(submenuContent.find("#grid_rows_total"), null); + submenuContent.find("#nextPage_div").hide(); + } + submenuContent.find("#loading_gridtable").hide(); + submenuContent.find("#pagination_panel").show(); + }); + } + }); +} + + +//event binder +var currentPage = 1; +var pageSize = 50; //consistent with server-side +function submenuContentEventBinder(submenuContent, listFunction) { + submenuContent.find("#nextPage").bind("click", function(event){ + event.preventDefault(); + currentPage++; + listFunction(); + }); + + submenuContent.find("#prevPage").bind("click", function(event){ + event.preventDefault(); + currentPage--; + listFunction(); + }); + + submenuContent.find("#refresh").bind("click", function(event){ + event.preventDefault(); + currentPage=1; + listFunction(); + }); + + submenuContent.find("#search_button").bind("click", function(event) { + event.preventDefault(); + currentPage = 1; + listFunction(); + }); + + submenuContent.find("#adv_search_button").bind("click", function(event) { + event.preventDefault(); + currentPage = 1; + listFunction(); + submenuContent.find("#search_button").data("advanced", false); + submenuContent.find("#advanced_search").hide(); + }); + + submenuContent.find("#search_input").bind("keypress", function(event) { + if(event.keyCode == keycode_Enter) { + event.preventDefault(); + submenuContent.find("#search_button").click(); + } + }); + + submenuContent.find("#advanced_search").bind("keypress", function(event) { + if(event.keyCode == keycode_Enter) { + event.preventDefault(); + submenuContent.find("#adv_search_button").click(); + } + }); + + submenuContent.find("#advanced_search_close").bind("click", function(event) { + event.preventDefault(); + submenuContent.find("#search_button").data("advanced", false); + submenuContent.find("#advanced_search").hide(); + }); + + submenuContent.find("#advanced_search_link").bind("click", function(event) { + event.preventDefault(); + submenuContent.find("#search_button").data("advanced", true); + submenuContent.find("#advanced_search").show(); + }); + + var zoneSelect = submenuContent.find("#advanced_search #adv_search_zone"); + if(zoneSelect.length>0) { //if zone dropdown is found on Advanced Search dialog + $.ajax({ data: createURL("command=listZones&available=true&response=json"+maxPageSize), - dataType: "json", - success: function(json) { - var zones = json.listzonesresponse.zone; - zoneSelect.empty(); - zoneSelect.append(""); - if (zones != null && zones.length > 0) { - for (var i = 0; i < zones.length; i++) { - zoneSelect.append(""); - } - } - } - }); - - var podSelect = submenuContent.find("#advanced_search #adv_search_pod").empty(); - var podLabel = submenuContent.find("#advanced_search #adv_search_pod_label"); - if(podSelect.length>0 && isAdmin()) { //if pod dropdown is found on Advanced Search dialog and if its role is admin - zoneSelect.bind("change", function(event) { - var zoneId = $(this).val(); - if (zoneId == null || zoneId.length == 0) { - podLabel.css("color", "gray"); - podSelect.attr("disabled", "disabled"); - podSelect.empty(); - } else { - podLabel.css("color", "black"); - podSelect.removeAttr("disabled"); - $.ajax({ + dataType: "json", + success: function(json) { + var zones = json.listzonesresponse.zone; + zoneSelect.empty(); + zoneSelect.append(""); + if (zones != null && zones.length > 0) { + for (var i = 0; i < zones.length; i++) { + zoneSelect.append(""); + } + } + } + }); + + var podSelect = submenuContent.find("#advanced_search #adv_search_pod").empty(); + var podLabel = submenuContent.find("#advanced_search #adv_search_pod_label"); + if(podSelect.length>0 && isAdmin()) { //if pod dropdown is found on Advanced Search dialog and if its role is admin + zoneSelect.bind("change", function(event) { + var zoneId = $(this).val(); + if (zoneId == null || zoneId.length == 0) { + podLabel.css("color", "gray"); + podSelect.attr("disabled", "disabled"); + podSelect.empty(); + } else { + podLabel.css("color", "black"); + podSelect.removeAttr("disabled"); + $.ajax({ data: createURL("command=listPods&zoneId="+zoneId+"&response=json"+maxPageSize), - dataType: "json", - async: false, - success: function(json) { - var pods = json.listpodsresponse.pod; - podSelect.empty(); - if (pods != null && pods.length > 0) { - for (var i = 0; i < pods.length; i++) { - podSelect.append(""); - } - } - } - }); - } - return false; - }); - - zoneSelect.change(); - } - } - - var domainSelect = submenuContent.find("#advanced_search #adv_search_domain"); - if(domainSelect.length>0 && isAdmin()) { - var domainSelect = domainSelect.empty(); - $.ajax({ + dataType: "json", + async: false, + success: function(json) { + var pods = json.listpodsresponse.pod; + podSelect.empty(); + if (pods != null && pods.length > 0) { + for (var i = 0; i < pods.length; i++) { + podSelect.append(""); + } + } + } + }); + } + return false; + }); + + zoneSelect.change(); + } + } + + var domainSelect = submenuContent.find("#advanced_search #adv_search_domain"); + if(domainSelect.length>0 && isAdmin()) { + var domainSelect = domainSelect.empty(); + $.ajax({ data: createURL("command=listDomains&available=true&response=json"+maxPageSize), - dataType: "json", - success: function(json) { - var domains = json.listdomainsresponse.domain; - if (domains != null && domains.length > 0) { - for (var i = 0; i < domains.length; i++) { - domainSelect.append(""); - } - } - } - }); - } - - var vmSelect = submenuContent.find("#advanced_search").find("#adv_search_vm"); - if(vmSelect.length>0) { - vmSelect.empty(); - vmSelect.append(""); - $.ajax({ + dataType: "json", + success: function(json) { + var domains = json.listdomainsresponse.domain; + if (domains != null && domains.length > 0) { + for (var i = 0; i < domains.length; i++) { + domainSelect.append(""); + } + } + } + }); + } + + var vmSelect = submenuContent.find("#advanced_search").find("#adv_search_vm"); + if(vmSelect.length>0) { + vmSelect.empty(); + vmSelect.append(""); + $.ajax({ data: createURL("command=listVirtualMachines&response=json"+maxPageSize), - dataType: "json", - success: function(json) { - var items = json.listvirtualmachinesresponse.virtualmachine; - if (items != null && items.length > 0) { - for (var i = 0; i < items.length; i++) { - vmSelect.append(""); - } - } - } - }); - } -} - -// Validation functions -function showError(isValid, field, errMsgField, errMsg) { - if(isValid) { - errMsgField.text("").hide(); - field.addClass("text").removeClass("error_text"); - } - else { - errMsgField.text(errMsg).show(); - field.removeClass("text").addClass("error_text"); - } -} - -function showError2(isValid, field, errMsgField, errMsg, appendErrMsg) { - if(isValid) { - errMsgField.text("").hide(); - field.addClass("text2").removeClass("error_text2"); - } - else { - if(appendErrMsg) //append text - errMsgField.text(errMsgField.text()+errMsg).show(); - else //reset text - errMsgField.text(errMsg).show(); - field.removeClass("text2").addClass("error_text2"); - } -} - -function validateDropDownBox(label, field, errMsgField, appendErrMsg) { - var isValid = true; - var errMsg = ""; - var value = field.val(); - if (value == null || value.length == 0) { - errMsg = label + " is a required value. "; - isValid = false; - } - showError2(isValid, field, errMsgField, errMsg, appendErrMsg); - return isValid; -} - -function validateNumber(label, field, errMsgField, min, max, isOptional) { - var isValid = true; - var errMsg = ""; - var value = field.val(); - if (value != null && value.length != 0) { - if(isNaN(value)) { - errMsg = label + " must be a number"; - isValid = false; - } else { - if (min != null && value < min) { - errMsg = label + " must be a value greater than or equal to " + min; - isValid = false; - } - if (max != null && value > max) { - errMsg = label + " must be a value less than or equal to " + max; - isValid = false; - } - } - } else if(isOptional!=true){ //required field - errMsg = label + " is a required value. "; - isValid = false; - } - showError(isValid, field, errMsgField, errMsg); - return isValid; -} - -function validateString(label, field, errMsgField, isOptional) { - var isValid = true; - var errMsg = ""; - var value = field.val(); - if (isOptional!=true && (value == null || value.length == 0)) { //required field - errMsg = label + " is a required value. "; - isValid = false; - } - else if (value!=null && value.length >= 255) { - errMsg = label + " must be less than 255 characters"; - isValid = false; - } - else if(value!=null && value.indexOf('"')!=-1) { - errMsg = "Double quotes are not allowed."; - isValid = false; - } - showError(isValid, field, errMsgField, errMsg); - return isValid; -} - -function validateIp(label, field, errMsgField, isOptional) { - if(validateString(label, field, errMsgField, isOptional) == false) - return; - var isValid = true; - var errMsg = ""; - var value = field.val(); - if(value!=null && value.length>0) { - myregexp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; - var isMatch = myregexp.test(value); - if(!isMatch) { - errMsg = label + " should be like 75.52.126.11"; - isValid = false; - } - } - showError(isValid, field, errMsgField, errMsg); - return isValid; -} - -function validateCIDR(label, field, errMsgField, isOptional) { - if(validateString(label, field, errMsgField, isOptional) == false) - return; - var isValid = true; - var errMsg = ""; - var value = field.val(); - if(value!=null && value.length>0) { - myregexp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}$/; - var isMatch = myregexp.test(value); - if(!isMatch) { - errMsg = label + " should be like 10.1.1.0/24"; - isValid = false; - } - } - showError(isValid, field, errMsgField, errMsg); - return isValid; -} - -function validatePath(label, field, errMsgField, isOptional) { - if(validateString(label, field, errMsgField, isOptional) == false) - return; - var isValid = true; - var errMsg = ""; - var value = field.val(); - if(value!=null && value.length>0) { - myregexp = /^\//; - var isMatch = myregexp.test(value); - if(!isMatch) { - errMsg = label + " should be like /aaa/bbb/ccc"; - isValid = false; - } - } - showError(isValid, field, errMsgField, errMsg); - return isValid; -} - -function cleanErrMsg(field, errMsgField) { - showError(true, field, errMsgField); -} - -// setter -function setGridRowsTotal(field, gridRowsTotal) { - if(gridRowsTotal==null) { - field.text(""); - return; - } - - if(gridRowsTotal==1) - field.text(gridRowsTotal + " item"); - else - field.text(gridRowsTotal + " items"); -} - -function changeGridRowsTotal(field, difference) { - var t = field.text(); - var oldTotal = 0; - if(t.length>0 && t.indexOf(" item")!=-1) { - var s = t.substring(0, t.indexOf(" item")); - if(!isNaN(s)) - oldTotal = parseInt(s); - } - var newTotal = oldTotal + difference; - setGridRowsTotal(field, newTotal); -} - - -// others -function trim(val) { - if(val == null) - return null; - return val.replace(/^\s*/, "").replace(/\s*$/, ""); -} - -function noNull(val) { - if(val == null) - return ""; - else - return val; -} - -// Prevent cross-site-script(XSS) attack. -// used right before adding user input to the DOM tree. e.g. DOM_element.html(sanitizeXSS(user_input)); -function sanitizeXSS(val) { - if(val == null) - return val; - val = val.replace(//g, ">"); //replace > whose unicode is \u003e - return val; -} - -function getVmName(p_vmName, p_vmDisplayname) { - if(p_vmDisplayname == null) - return sanitizeXSS(p_vmName); - var vmName = null; - if (isAdmin()) { - if (p_vmDisplayname != p_vmName) { - vmName = p_vmName + "(" + sanitizeXSS(p_vmDisplayname) + ")"; - } else { - vmName = p_vmName; - } - } else { - vmName = sanitizeXSS(p_vmDisplayname); - } - return vmName; -} - -// FUNCTION: Handles AJAX error callbacks. You can pass in an optional function to -// handle errors that are not already handled by this method. -function handleError(xmlHttp, handleErrorCallback) { - // User Not authenticated - if (xmlHttp.status == ERROR_ACCESS_DENIED_DUE_TO_UNAUTHORIZED) { - $("#dialog_session_expired").dialog("open"); - } - else if (xmlHttp.status == ERROR_INTERNET_NAME_NOT_RESOLVED) { - $("#dialog_error").text("Internet name can not be resolved").dialog("open"); - } - else if (xmlHttp.status == ERROR_INTERNET_CANNOT_CONNECT) { - $("#dialog_error").text("Management server is not accessible").dialog("open"); - } - else if (xmlHttp.status == ERROR_VMOPS_ACCOUNT_ERROR && handleErrorCallback != undefined) { - handleErrorCallback(); + dataType: "json", + success: function(json) { + var items = json.listvirtualmachinesresponse.virtualmachine; + if (items != null && items.length > 0) { + for (var i = 0; i < items.length; i++) { + vmSelect.append(""); + } + } + } + }); + } +} + +// Validation functions +function showError(isValid, field, errMsgField, errMsg) { + if(isValid) { + errMsgField.text("").hide(); + field.addClass("text").removeClass("error_text"); + } + else { + errMsgField.text(errMsg).show(); + field.removeClass("text").addClass("error_text"); + } +} + +function showError2(isValid, field, errMsgField, errMsg, appendErrMsg) { + if(isValid) { + errMsgField.text("").hide(); + field.addClass("text2").removeClass("error_text2"); + } + else { + if(appendErrMsg) //append text + errMsgField.text(errMsgField.text()+errMsg).show(); + else //reset text + errMsgField.text(errMsg).show(); + field.removeClass("text2").addClass("error_text2"); + } +} + +function validateDropDownBox(label, field, errMsgField, appendErrMsg) { + var isValid = true; + var errMsg = ""; + var value = field.val(); + if (value == null || value.length == 0) { + errMsg = label + " is a required value. "; + isValid = false; + } + showError2(isValid, field, errMsgField, errMsg, appendErrMsg); + return isValid; +} + +function validateNumber(label, field, errMsgField, min, max, isOptional) { + var isValid = true; + var errMsg = ""; + var value = field.val(); + if (value != null && value.length != 0) { + if(isNaN(value)) { + errMsg = label + " must be a number"; + isValid = false; + } else { + if (min != null && value < min) { + errMsg = label + " must be a value greater than or equal to " + min; + isValid = false; + } + if (max != null && value > max) { + errMsg = label + " must be a value less than or equal to " + max; + isValid = false; + } + } + } else if(isOptional!=true){ //required field + errMsg = label + " is a required value. "; + isValid = false; + } + showError(isValid, field, errMsgField, errMsg); + return isValid; +} + +function validateString(label, field, errMsgField, isOptional) { + var isValid = true; + var errMsg = ""; + var value = field.val(); + if (isOptional!=true && (value == null || value.length == 0)) { //required field + errMsg = label + " is a required value. "; + isValid = false; + } + else if (value!=null && value.length >= 255) { + errMsg = label + " must be less than 255 characters"; + isValid = false; + } + else if(value!=null && value.indexOf('"')!=-1) { + errMsg = "Double quotes are not allowed."; + isValid = false; + } + showError(isValid, field, errMsgField, errMsg); + return isValid; +} + +function validateIp(label, field, errMsgField, isOptional) { + if(validateString(label, field, errMsgField, isOptional) == false) + return; + var isValid = true; + var errMsg = ""; + var value = field.val(); + if(value!=null && value.length>0) { + myregexp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; + var isMatch = myregexp.test(value); + if(!isMatch) { + errMsg = label + " should be like 75.52.126.11"; + isValid = false; + } + } + showError(isValid, field, errMsgField, errMsg); + return isValid; +} + +function validateCIDR(label, field, errMsgField, isOptional) { + if(validateString(label, field, errMsgField, isOptional) == false) + return; + var isValid = true; + var errMsg = ""; + var value = field.val(); + if(value!=null && value.length>0) { + myregexp = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}$/; + var isMatch = myregexp.test(value); + if(!isMatch) { + errMsg = label + " should be like 10.1.1.0/24"; + isValid = false; + } + } + showError(isValid, field, errMsgField, errMsg); + return isValid; +} + +function validatePath(label, field, errMsgField, isOptional) { + if(validateString(label, field, errMsgField, isOptional) == false) + return; + var isValid = true; + var errMsg = ""; + var value = field.val(); + if(value!=null && value.length>0) { + myregexp = /^\//; + var isMatch = myregexp.test(value); + if(!isMatch) { + errMsg = label + " should be like /aaa/bbb/ccc"; + isValid = false; + } + } + showError(isValid, field, errMsgField, errMsg); + return isValid; +} + +function cleanErrMsg(field, errMsgField) { + showError(true, field, errMsgField); +} + +// setter +function setGridRowsTotal(field, gridRowsTotal) { + if(gridRowsTotal==null) { + field.text(""); + return; + } + + if(gridRowsTotal==1) + field.text(gridRowsTotal + " item"); + else + field.text(gridRowsTotal + " items"); +} + +function changeGridRowsTotal(field, difference) { + var t = field.text(); + var oldTotal = 0; + if(t.length>0 && t.indexOf(" item")!=-1) { + var s = t.substring(0, t.indexOf(" item")); + if(!isNaN(s)) + oldTotal = parseInt(s); + } + var newTotal = oldTotal + difference; + setGridRowsTotal(field, newTotal); +} + + +// others +function trim(val) { + if(val == null) + return null; + return val.replace(/^\s*/, "").replace(/\s*$/, ""); +} + +function noNull(val) { + if(val == null) + return ""; + else + return val; +} + +// Prevent cross-site-script(XSS) attack. +// used right before adding user input to the DOM tree. e.g. DOM_element.html(sanitizeXSS(user_input)); +function sanitizeXSS(val) { + if(val == null) + return val; + val = val.replace(//g, ">"); //replace > whose unicode is \u003e + return val; +} + +function getVmName(p_vmName, p_vmDisplayname) { + if(p_vmDisplayname == null) + return sanitizeXSS(p_vmName); + var vmName = null; + if (isAdmin()) { + if (p_vmDisplayname != p_vmName) { + vmName = p_vmName + "(" + sanitizeXSS(p_vmDisplayname) + ")"; + } else { + vmName = p_vmName; + } + } else { + vmName = sanitizeXSS(p_vmDisplayname); + } + return vmName; +} + +// FUNCTION: Handles AJAX error callbacks. You can pass in an optional function to +// handle errors that are not already handled by this method. +function handleError(xmlHttp, handleErrorCallback) { + // User Not authenticated + if (xmlHttp.status == ERROR_ACCESS_DENIED_DUE_TO_UNAUTHORIZED) { + $("#dialog_session_expired").dialog("open"); + } + else if (xmlHttp.status == ERROR_INTERNET_NAME_NOT_RESOLVED) { + $("#dialog_error").text("Internet name can not be resolved").dialog("open"); + } + else if (xmlHttp.status == ERROR_INTERNET_CANNOT_CONNECT) { + $("#dialog_error").text("Management server is not accessible").dialog("open"); + } + else if (xmlHttp.status == ERROR_VMOPS_ACCOUNT_ERROR && handleErrorCallback != undefined) { + handleErrorCallback(); } else if (handleErrorCallback != undefined) { handleErrorCallback(); - } - else { - var start = xmlHttp.responseText.indexOf("h1") + 3; - var end = xmlHttp.responseText.indexOf("Encountered an error:


"+sanitizeXSS(errorMsg)+"

").dialog("open"); - } -} - -// FUNCTION: Adds a Dialog to the list of active Dialogs so that -// when you shift from one tab to another, we clean out the dialogs -var activeDialogs = new Array(); -function activateDialog(dialog) { - activeDialogs[activeDialogs.length] = dialog; - - //bind Enter-Key-pressing event handler to the dialog - dialog.keypress(function(event) { - if(event.keyCode == keycode_Enter) { - $('[aria-labelledby$='+dialog.attr("id")+']').find(":button:first").click(); - return false; //event.preventDefault() + event.stopPropagation() - } - }); -} -function removeDialogs() { - for (var i = 0; i < activeDialogs.length; i++) { - activeDialogs[i].remove(); - } - activeDialogs = new Array(); -} - -function convertBytes(bytes) { - if (bytes < 1024 * 1024) { - return (bytes / 1024).toFixed(2) + " KB"; - } else if (bytes < 1024 * 1024 * 1024) { - return (bytes / 1024 / 1024).toFixed(2) + " MB"; - } else if (bytes < 1024 * 1024 * 1024 * 1024) { - return (bytes / 1024 / 1024 / 1024).toFixed(2) + " GB"; - } else { - return (bytes / 1024 / 1024 / 1024 / 1024).toFixed(2) + " TB"; - } -} - -function convertHz(hz) { - if (hz < 1000) { - return hz + " MHZ"; - } else { - return (hz / 1000).toFixed(2) + " GHZ"; - } -} - -function toDayOfMonthDesp(dayOfMonth) { - return "Day "+dayOfMonth +" of Month"; -} - -function toDayOfWeekDesp(dayOfWeek) { - if (dayOfWeek == "1") - return "Sunday"; - else if (dayOfWeek == "2") - return "Monday"; - else if (dayOfWeek == "3") - return "Tuesday"; - else if (dayOfWeek == "4") - return "Wednesday"; - else if (dayOfWeek == "5") - return "Thursday" - else if (dayOfWeek == "6") - return "Friday"; - else if (dayOfWeek == "7") - return "Saturday"; -} - -function toBooleanText(booleanValue) { - if(booleanValue == "true") - return "Yes"; - else if(booleanValue == "false") - return "No"; -} - -function toBooleanValue(booleanText) { - if(booleanText == "Yes") - return "true"; - else if(booleanText == "No") - return "false"; -} - -function toNetworkType(usevirtualnetwork) { - if(usevirtualnetwork == "true") - return "Public"; - else - return "Direct"; -} - -var roleTypeUser = "0"; -var roleTypeAdmin = "1"; -var roleTypeDomainAdmin = "2"; -function toRole(type) { - if (type == roleTypeUser) { - return "User"; - } else if (type == roleTypeAdmin) { - return "Admin"; - } else if (type == roleTypeDomainAdmin) { - return "Domain-Admin"; - } -} - -function toAlertType(alertCode) { - switch (alertCode) { - case "0" : return "Capacity Threshold - Memory"; - case "1" : return "Capacity Threshold - CPU"; - case "2" : return "Capacity Threshold - Storage Used"; - case "3" : return "Capacity Threshold - Storage Allocated"; - case "4" : return "Capacity Threshold - Public IP"; - case "5" : return "Capacity Threshold - Private IP"; - case "6" : return "Monitoring - Host"; - case "7" : return "Monitoring - VM"; - case "8" : return "Monitoring - Domain Router"; - case "9" : return "Monitoring - Console Proxy"; - case "10" : return "Monitoring - Routing Host"; - case "11" : return "Monitoring - Storage"; - case "12" : return "Monitoring - Usage Server"; - case "13" : return "Monitoring - Management Server"; - case "14" : return "Migration - Domain Router"; - case "15" : return "Migration - Console Proxy"; - case "16" : return "Migration - User VM"; - case "17" : return "VLAN"; - case "18" : return "Monitoring - Secondary Storage VM"; - } + } + else { + var start = xmlHttp.responseText.indexOf("h1") + 3; + var end = xmlHttp.responseText.indexOf("Encountered an error:


"+sanitizeXSS(errorMsg)+"

").dialog("open"); + } +} + +// FUNCTION: Adds a Dialog to the list of active Dialogs so that +// when you shift from one tab to another, we clean out the dialogs +var activeDialogs = new Array(); +function activateDialog(dialog) { + activeDialogs[activeDialogs.length] = dialog; + + //bind Enter-Key-pressing event handler to the dialog + dialog.keypress(function(event) { + if(event.keyCode == keycode_Enter) { + $('[aria-labelledby$='+dialog.attr("id")+']').find(":button:first").click(); + return false; //event.preventDefault() + event.stopPropagation() + } + }); +} +function removeDialogs() { + for (var i = 0; i < activeDialogs.length; i++) { + activeDialogs[i].remove(); + } + activeDialogs = new Array(); +} + +function convertBytes(bytes) { + if (bytes < 1024 * 1024) { + return (bytes / 1024).toFixed(2) + " KB"; + } else if (bytes < 1024 * 1024 * 1024) { + return (bytes / 1024 / 1024).toFixed(2) + " MB"; + } else if (bytes < 1024 * 1024 * 1024 * 1024) { + return (bytes / 1024 / 1024 / 1024).toFixed(2) + " GB"; + } else { + return (bytes / 1024 / 1024 / 1024 / 1024).toFixed(2) + " TB"; + } +} + +function convertHz(hz) { + if (hz < 1000) { + return hz + " MHZ"; + } else { + return (hz / 1000).toFixed(2) + " GHZ"; + } +} + +function toDayOfMonthDesp(dayOfMonth) { + return "Day "+dayOfMonth +" of Month"; +} + +function toDayOfWeekDesp(dayOfWeek) { + if (dayOfWeek == "1") + return "Sunday"; + else if (dayOfWeek == "2") + return "Monday"; + else if (dayOfWeek == "3") + return "Tuesday"; + else if (dayOfWeek == "4") + return "Wednesday"; + else if (dayOfWeek == "5") + return "Thursday" + else if (dayOfWeek == "6") + return "Friday"; + else if (dayOfWeek == "7") + return "Saturday"; +} + +function toBooleanText(booleanValue) { + if(booleanValue == "true") + return "Yes"; + else if(booleanValue == "false") + return "No"; +} + +function toBooleanValue(booleanText) { + if(booleanText == "Yes") + return "true"; + else if(booleanText == "No") + return "false"; +} + +function toNetworkType(usevirtualnetwork) { + if(usevirtualnetwork == "true") + return "Public"; + else + return "Direct"; +} + +var roleTypeUser = "0"; +var roleTypeAdmin = "1"; +var roleTypeDomainAdmin = "2"; +function toRole(type) { + if (type == roleTypeUser) { + return "User"; + } else if (type == roleTypeAdmin) { + return "Admin"; + } else if (type == roleTypeDomainAdmin) { + return "Domain-Admin"; + } +} + +function toAlertType(alertCode) { + switch (alertCode) { + case "0" : return "Capacity Threshold - Memory"; + case "1" : return "Capacity Threshold - CPU"; + case "2" : return "Capacity Threshold - Storage Used"; + case "3" : return "Capacity Threshold - Storage Allocated"; + case "4" : return "Capacity Threshold - Public IP"; + case "5" : return "Capacity Threshold - Private IP"; + case "6" : return "Monitoring - Host"; + case "7" : return "Monitoring - VM"; + case "8" : return "Monitoring - Domain Router"; + case "9" : return "Monitoring - Console Proxy"; + case "10" : return "Monitoring - Routing Host"; + case "11" : return "Monitoring - Storage"; + case "12" : return "Monitoring - Usage Server"; + case "13" : return "Monitoring - Management Server"; + case "14" : return "Migration - Domain Router"; + case "15" : return "Migration - Console Proxy"; + case "16" : return "Migration - User VM"; + case "17" : return "VLAN"; + case "18" : return "Monitoring - Secondary Storage VM"; + } } // Timezones