From 2c0d240196be2673dcefa4f16babe6a217dd5b8d Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 16 Nov 2011 13:27:03 +0100 Subject: [PATCH] Task #983: Update Sunstone template creation to reference images and vnets by NAME and UNAME. Additionally, the select options are no longer stored in global variables. Select options should be dynamically generated when needed. In the template creation case, this is done when the dialog is opened. Also, increased width for the Vnet list and Image list, so more options can be seen. (cherry picked from commit 8c1eecfce4dc0d5b7153f3888df63684e8228fb1) --- src/sunstone/public/js/plugins/images-tab.js | 20 --------- .../public/js/plugins/templates-tab.js | 45 ++++++++++++++----- src/sunstone/public/js/plugins/vnets-tab.js | 20 --------- src/sunstone/public/js/sunstone-util.js | 18 +++++++- 4 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/sunstone/public/js/plugins/images-tab.js b/src/sunstone/public/js/plugins/images-tab.js index e42254b685..d8fd88bac8 100644 --- a/src/sunstone/public/js/plugins/images-tab.js +++ b/src/sunstone/public/js/plugins/images-tab.js @@ -203,7 +203,6 @@ var update_image_tmpl = \ '; -var images_select = ""; var dataTable_images; var $create_image_dialog; @@ -537,40 +536,22 @@ function imageInfoListener(){ }); } -//Updates the select input field with an option for each image -function updateImageSelect(){ - images_select = - makeSelectOptions(dataTable_images, - 1, - 4, - [9,9,9], - ["DISABLED","LOCKED","ERROR"] - ); - - //update static selectors: - //in the VM section - $('div.vm_section#disks select#IMAGE_ID', $create_template_dialog).html(images_select); -} - // Callback to update an element in the dataTable function updateImageElement(request, image_json){ var id = image_json.IMAGE.ID; var element = imageElementArray(image_json); updateSingleElement(element,dataTable_images,'#image_'+id); - updateImageSelect(); } // Callback to remove an element from the dataTable function deleteImageElement(req){ deleteElement(dataTable_images,'#image_'+req.request.data); - updateImageSelect(); } // Callback to add an image element function addImageElement(request, image_json){ var element = imageElementArray(image_json); addElement(element,dataTable_images); - updateImageSelect(); } // Callback to refresh the list of images @@ -582,7 +563,6 @@ function updateImagesView(request, images_list){ }); updateView(image_list_array,dataTable_images); - updateImageSelect(); updateDashboard("images",images_list); } diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index 82f91813dd..18c185f64a 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -195,9 +195,10 @@ var create_template_tmpl = '
\
\
\ \ - \ \
Name of the image to use
\ + \
\
\ \ @@ -267,7 +268,7 @@ var create_template_tmpl = '
\ \
\ \ - \ \
\
\ @@ -292,9 +293,10 @@ var create_template_tmpl = '
\
\
\ \ - \ \
Name of the network to attach this device
\ + \
\
\ \ @@ -378,7 +380,7 @@ var create_template_tmpl = '
\ \
\ \ - \ \
\ \ @@ -985,12 +987,6 @@ function setupCreateTemplateDialog(){ $(section_inputs).hide(); $(section_graphics).hide(); - //Repopulate images select - $('select#IMAGE_ID',section_disks).html(images_select); - //Repopulate network select - $('select#NETWORK_ID',section_networks).html(vnetworks_select); - - switch(ui.index){ case 0: enable_kvm(); @@ -1378,6 +1374,12 @@ function setupCreateTemplateDialog(){ return false; }); + //Auto-set IMAGE_UNAME hidden field value + $('#IMAGE', section_disks).change(function(){ + var uname = getValue($(this).val(),4,2,dataTable_images); + $('input#IMAGE_UNAME',section_disks).val(uname); + }); + //Depending on adding a disk or a image we need to show/hide //different options and make then mandatory or not $('#image_vs_disk input',section_disks).click(function(){ @@ -1531,6 +1533,12 @@ function setupCreateTemplateDialog(){ return false; }); + //Auto-set IMAGE_UNAME hidden field value + $('#NETWORK', section_networks).change(function(){ + var uname = getValue($(this).val(),4,2,dataTable_vNetworks); + $('input#NETWORK_UNAME',section_networks).val(uname); + }); + //Depending on adding predefined network or not we show/hide //some fields $('#network_vs_niccfg input',section_networks).click(function(){ @@ -1970,6 +1978,23 @@ function setupCreateTemplateDialog(){ } function popUpCreateTemplateDialog(){ + //Repopulate images select + var im_sel = makeSelectOptions(dataTable_images, + 4, //id col - trick -> reference by name! + 4, //name col + [10,10,10], + ["DISABLED","LOCKED","ERROR"] + ); + $('div#disks select#IMAGE',$create_template_dialog).html(im_sel); + //Repopulate network select + var vn_sel = makeSelectOptions(dataTable_vNetworks, + 4, //id col - trick -> reference by name! + 4, + [], + [] + ); + $('div#networks select#NETWORK',$create_template_dialog).html(vn_sel); + $create_template_dialog.dialog('open'); }; diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index 8523a961f5..e9b9dcfcfc 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -159,7 +159,6 @@ var update_vnet_tmpl = \ '; -var vnetworks_select=""; var dataTable_vNetworks; var $create_vn_dialog; var $lease_vn_dialog; @@ -451,40 +450,22 @@ function vNetworkInfoListener(){ }); } -//updates the vnet select different options -function updateNetworkSelect(){ - vnetworks_select= - makeSelectOptions(dataTable_vNetworks, - 1, - 4, - [], - [] - ); - - //update static selectors: - //in the VM creation dialog - $('div.vm_section#networks select#NETWORK_ID',$create_template_dialog).html(vnetworks_select); -} - //Callback to update a vnet element after an action on it function updateVNetworkElement(request, vn_json){ id = vn_json.VNET.ID; element = vNetworkElementArray(vn_json); updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); - updateNetworkSelect(); } //Callback to delete a vnet element from the table function deleteVNetworkElement(req){ deleteElement(dataTable_vNetworks,'#vnetwork_'+req.request.data); - updateNetworkSelect(); } //Callback to add a new element function addVNetworkElement(request,vn_json){ var element = vNetworkElementArray(vn_json); addElement(element,dataTable_vNetworks); - updateNetworkSelect(); } //updates the list of virtual networks @@ -496,7 +477,6 @@ function updateVNetworksView(request, network_list){ }); updateView(network_list_array,dataTable_vNetworks); - updateNetworkSelect(); //dependency with dashboard updateDashboard("vnets",network_list); diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 8918a8cb33..ee19881d77 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -420,8 +420,24 @@ function getName(id,dataTable){ } }); return name; -} +}; +//Search a datatable record matching the filter_str in the filter_col. Returns +//the value of that record in the desired value column. +function getValue(filter_str,filter_col,value_col,dataTable){ + var value=""; + if (typeof(dataTable) == "undefined") return value; + + var nodes = dataTable.fnGetData(); + + $.each(nodes,function(){ + if (filter_str == this[filter_col]){ + value = this[value_col]; + return false; + }; + }); + return value; +}; //Replaces all class"tip" divs with an information icon that //displays the tip information on mouseover.