From a80623ace83e10142d322c0a330a5d82323feec4 Mon Sep 17 00:00:00 2001 From: phamt Date: Tue, 17 Apr 2012 03:03:25 +0000 Subject: [PATCH] Added configure profile panel for self-service page. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12248 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-UI/js/custom/zvm.js | 1 - xCAT-UI/js/custom/zvmUtils.js | 182 ++++++++++++++++++++++++++++++++-- xCAT-UI/xcat/plugins/web.pm | 25 ++++- 3 files changed, 199 insertions(+), 9 deletions(-) diff --git a/xCAT-UI/js/custom/zvm.js b/xCAT-UI/js/custom/zvm.js index 6cda7adde..97b5d708b 100644 --- a/xCAT-UI/js/custom/zvm.js +++ b/xCAT-UI/js/custom/zvm.js @@ -35,7 +35,6 @@ zvmPlugin.prototype.loadConfigPage = function(tabId) { // Create accordion panel for profiles var profileSection = $('
'); - profileSection.append(createInfoBar('Create, edit, and delete virtual machine profiles used in the self-service portal')); var profileLnk = $('

Profiles

').click(function () { // Do not load panel again if it is already loaded if ($('#zvmConfigProfile').find('.dataTables_wrapper').length) diff --git a/xCAT-UI/js/custom/zvmUtils.js b/xCAT-UI/js/custom/zvmUtils.js index a991dd7be..4ab401a9b 100644 --- a/xCAT-UI/js/custom/zvmUtils.js +++ b/xCAT-UI/js/custom/zvmUtils.js @@ -3402,22 +3402,25 @@ function queryProfiles(panelId) { success : function(data) { var panelId = data.msg; setOSImageCookies(data); - loadConfigProfilePanel(panelId); + configProfilePanel(panelId); } }); } /** - * Load the profiles panel to configure directory entries and disks for a profile + * Panel to configure directory entries and disks for a profile * * @param panelId * Panel ID * @return Nothing */ -function loadConfigProfilePanel(panelId) { - // Remove loader - $('#' + panelId).find('img[src="images/loader.gif"]').remove(); +function configProfilePanel(panelId) { + // Wipe panel clean + $('#' + panelId).empty(); + // Add info bar + $('#' + panelId).append(createInfoBar('Create, edit, and delete profiles for the self-service portal. Double-click on a cell to edit a users properties. Click outside the table to save changes. Hit the Escape key to ignore changes.')); + // Create table var tableId = 'zvmProfileTable'; var table = new DataTable(tableId); @@ -3425,6 +3428,7 @@ function loadConfigProfilePanel(panelId) { // Insert profiles into table var profiles = $.cookie('profiles').split(','); + profiles.push('default'); // Add default profile for (var i in profiles) { if (profiles[i]) { // Columns are: profile, disk pool, disk size, and directory entry @@ -3454,7 +3458,7 @@ function loadConfigProfilePanel(panelId) { var createLnk = $('Create'); createLnk.click(function() { - + profileDialog(); }); var deleteLnk = $('Delete'); @@ -3464,7 +3468,7 @@ function loadConfigProfilePanel(panelId) { var refreshLnk = $('Refresh'); refreshLnk.click(function() { - + queryProfiles(panelId); }); // Create an action menu @@ -3488,4 +3492,168 @@ function loadConfigProfilePanel(panelId) { // Resize accordion $('#zvmConfigAccordion').accordion('resize'); + + // Query directory entries and disk pool/size for each profile + for (var i in profiles) { + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'getdefaultuserentry;' + profiles[i], + msg : 'out=' + panelId + ';profile=' + profiles[i] + }, + + success: insertDirectoryentry + }); + + $.ajax({ + url : 'lib/cmd.php', + dataType : 'json', + data : { + cmd : 'webrun', + tgt : '', + args : 'getzdiskinfo;' + profiles[i], + msg : 'out=' + panelId + ';profile=' + profiles[i] + }, + + success: insertDiskInfo + }); + } +} + +/** + * Insert the directory entry into the profile table + * + * @param data + * Data from HTTP request + * @return Nothing + */ +function insertDirectoryentry(data) { + var tableId = 'zvmProfileTable'; + var args = data.msg.split(';'); + + var panelId = args[0].replace('out=', ''); + var profile = args[1].replace('profile=', ''); + + // Do not continue if there is nothing + if (!data.rsp.length) + return; + + var entry = data.rsp[0].replace(new RegExp('\n', 'g'), '
'); + + // Get the row containing the profile + var rowPos = findRow(profile, '#' + tableId, 1); + if (rowPos < 0) + return; + + // Update the directory entry column + var dTable = $('#' + tableId).dataTable(); + dTable.fnUpdate(entry, rowPos, 4, false); + + // Adjust table styling + $('#' + tableId + ' td:nth-child(5)').css({ + 'text-align': 'left' + }); + adjustColumnSize(tableId); +} + +/** + * Insert the disk info into the profile table + * + * @param data + * Data from HTTP request + * @return Nothing + */ +function insertDiskInfo(data) { + var tableId = 'zvmProfileTable'; + var args = data.msg.split(';'); + + var panelId = args[0].replace('out=', ''); + var profile = args[1].replace('profile=', ''); + + // Do not continue if there is nothing + if (!data.rsp.length) + return; + + // Get the row containing the profile + var rowPos = findRow(profile, '#' + tableId, 1); + if (rowPos < 0) + return; + + // Update the disk info columns + var dTable = $('#' + tableId).dataTable(); + + var tmp = ""; + var pool = ""; + var eckdSize = 0; + var info = data.rsp[0].split('\n'); + for (var i in info) { + if (info[i].indexOf('diskpool') > -1) { + tmp = info[i].split('='); + pool = jQuery.trim(tmp[1]); + + dTable.fnUpdate(pool, rowPos, 2, false); + } if (info[i].indexOf('eckd_size') > -1) { + tmp = info[i].split('='); + eckdSize = jQuery.trim(tmp[1]); + + dTable.fnUpdate(eckdSize, rowPos, 3, false); + } + } + + // Adjust table styling + adjustColumnSize(tableId); +} + +/** + * Open profile dialog + */ +function profileDialog() { + // Create form to add profile + var profileForm = $('
'); + + // Create info bar + var info = createInfoBar('Configure the default settings for a profile'); + profileForm.append(info); + + profileForm.append('
'); + profileForm.append('
'); + profileForm.append('
'); + profileForm.append('