On 04/08/2014 11:53 PM, Rodrigo Trujillo wrote:
This patch changes edit template window to fix consistence:
- Show storagepool + volume name correctly in storagepool field after
saving
- Show disk size according to storagepool or storagepool/volume selected
- Block disk size input box when disk is type volume (iscsi/scsi volumes
cannot be changed)
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.template_edit_main.js | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/ui/js/src/kimchi.template_edit_main.js
b/ui/js/src/kimchi.template_edit_main.js
index 386095b..c96021f 100644
--- a/ui/js/src/kimchi.template_edit_main.js
+++ b/ui/js/src/kimchi.template_edit_main.js
@@ -30,6 +30,11 @@ kimchi.template_edit_main = function() {
}
var disks = template.disks;
$('input[name="disks"]').val(disks[0].size);
+ if (disks[0].volume) {
+ var spool_value = $('#form-template-edit
[name="storagepool"]').val();
+ $('input[name="storagepool"]',
templateEditForm).val(spool_value + '/' + disks[0].volume);
+ $('input[name="disks"]',
templateEditForm).attr('disabled','disabled');
+ }
var options = [{label: 'VNC', value: 'vnc'}];
kimchi.getCapabilities(function(result) {
@@ -37,7 +42,7 @@ kimchi.template_edit_main = function() {
options.push({label: 'Spice', value: 'spice'})
}
}, function() {
- }, function(){
+ }, function() {
kimchi.select('template-edit-graphics-list', options);
});
@@ -101,6 +106,29 @@ kimchi.template_edit_main = function() {
kimchi.window.close();
});
+ $('input[name="storagepool"]', templateEditForm).change(function()
{
+ var storagepool = $('#form-template-edit
[name="storagepool"]').val();
+ var storageArray = storagepool.split("/");
+ if (storageArray.length > 3) {
+ volumeName = storageArray.pop();
+ poolName = storageArray.pop();
+ kimchi.getStoragePoolVolume(poolName, volumeName, function(result) {
+ $('input[name="disks"]',
templateEditForm).val(result.capacity / Math.pow(1024,3));
+ $('input[name="disks"]',
templateEditForm).attr('disabled','disabled');
+ return false;
+ }, function (err) {
+ kimchi.message.error(err.responseJSON.reason);
+ });
+ } else if (origDisks[0].volume) {
+ // Set default value when original disk was a volume
+ $('input[name="disks"]', templateEditForm).val(10);
+ $('input[name="disks"]',
templateEditForm).removeAttr('disabled');
+ } else {
If 'disks' has 'volume' field it is a iSCSI or SCSI volume so the size
is the volume size, right?
This 'if' statement is not needed in my perspective as this is handled
by the first "if" (if (storageArray.length > 3) {)
+ $('input[name="disks"]',
templateEditForm).val(origDisks[0].size);
+ $('input[name="disks"]',
templateEditForm).removeAttr('disabled');
+ }
+ });
+
$('#tmpl-edit-button-save').on('click', function() {
var editableFields = [ 'name', 'cpus', 'memory',
'storagepool', 'disks', 'graphics'];
var data = {};
@@ -124,9 +152,10 @@ kimchi.template_edit_main = function() {
storageArray = storagepool.split("/");
if (storageArray.length > 3){
/* Support only 1 disk at this moment */
- delete data["disks"][0].size;
data["disks"][0].volume = storageArray.pop();
data['storagepool'] = storageArray.join("/");
+ } else if (data["disks"][0].volume) {
+ delete data["disks"][0].volume;
}
var networks = templateEditForm.serializeObject().networks;
if (networks instanceof Array) {