
From: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> Edit Guest does not work the same way as the Edit Template dialog - each tab has its own submit function and it is not possible to submit multiple tabs in the same dialog. This patch splits the logic to update the CPU configuration that was contained in the 'generalSubmit' function and put it into a new function called 'processorSubmit'. This function will be fired when the 'Save' button is pressed when the 'Processor' tab is active. This patch also further enhances the control of the 'Save' button state in the 'init_processor_tab' JS function by making it always enabled when there is no topology being set. If current CPU is set to a value above max CPU it will be rewrite to be equal to max CPU; if max CPU is set to a value below current CPU, current CPU is set to max CPU. Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- ui/js/src/kimchi.guest_edit_main.js | 83 +++++++++++++++++----------------- ui/js/src/kimchi.template_edit_main.js | 10 ++++ ui/pages/i18n.json.tmpl | 1 - 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/ui/js/src/kimchi.guest_edit_main.js b/ui/js/src/kimchi.guest_edit_main.js index 91e5b13..f06e0fa 100644 --- a/ui/js/src/kimchi.guest_edit_main.js +++ b/ui/js/src/kimchi.guest_edit_main.js @@ -48,7 +48,8 @@ kimchi.guest_edit_main = function() { // tap map, "general": 0, "storage": 1, "interface": 2, "permission": 3, "password": 4 var submit_map = { 0: generalSubmit, - 3: permissionSubmit + 3: permissionSubmit, + 6: processorSubmit }; var currentTab = $('#guest-edit-window li.active a[data-toggle="tab"]').data('id'); var toSubmit = parseInt($('#'+currentTab).index()); @@ -60,7 +61,6 @@ kimchi.guest_edit_main = function() { $(guestEditForm).on('submit', submitForm); $(saveButton).on('click', submitForm); - $('#guest-edit-window a[data-toggle="tab"]').on('shown.bs.tab', function(e) { var target = $(this).attr('href'); $(target).css('left', '-' + $(window).width() + 'px'); @@ -1053,41 +1053,14 @@ kimchi.guest_edit_main = function() { var data = $('#form-guest-edit-general').serializeObject(); data['memory'] = {current: Number(data['memory-ui']), maxmemory: Number(data['max-memory'])}; - var cpu = parseInt($('#vcpus').val()); - var maxCpu = parseInt($('#guest-edit-max-processor-textbox').val()); - var maxCpuFinal = cpu; - if (maxCpu >= cpu) { - maxCpuFinal = maxCpu; - } - if ($("input:checkbox", "#form-edit-processor").prop("checked")) { - data['cpu_info'] = { - vcpus: cpu, - maxvcpus: maxCpuFinal, - topology: { - sockets: parseInt($("#sockets").val()), - cores: parseInt($("#cores").val()), - threads: parseInt($("#threads").val()) - } - }; - } else { - data['cpu_info'] = { - vcpus: cpu, - maxvcpus: maxCpuFinal, - topology: {} - }; - } - var changedFields = {}; for (var key in data) { valueFromUI = data[key]; if (valueFromUI instanceof Object) { // Compare if Objects of original and data are identical // Handle special case when key is memory and guest is running as valueFromUI will return a null for max mem - // since it is disabled; for cpu_info, when guest is running, just skip it since no processing is required + // since it is disabled; if (kimchi.thisVMState === 'running' || kimchi.thisVMState === 'paused') { - if (key === 'cpu_info') { - continue; - } if (key === 'memory') { // Replace valueFromUI of max mem with one from original as otherwise the value is undefined data['memory']['maxmemory'] = org.memory.maxmemory; @@ -1137,17 +1110,6 @@ kimchi.guest_edit_main = function() { } } - if ('cpu_info' in changedFields) { - var currentCpu = data['cpu_info'].vcpus; - var currentMaxCpu = data['cpu_info'].maxvcpus; - - if (currentCpu > currentMaxCpu) { - wok.message.error(i18n['KCHVM0003E'], '#alert-modal-container'); - $(saveButton).prop('disabled', false); - return; - } - } - kimchi.updateVM(kimchi.selectedGuest, changedFields, function() { kimchi.listVmsAuto(); wok.window.close(); @@ -1203,6 +1165,45 @@ kimchi.guest_edit_main = function() { } }; + var processorSubmit = function(event) { + kimchi.retrieveVM(kimchi.selectedGuest, function(org) { + $(saveButton).prop('disabled', true); + var data = {}; + + var cpu = parseInt($('#vcpus').val()); + var maxCpu = parseInt($('#guest-edit-max-processor-textbox').val()); + var maxCpuFinal = cpu; + if (maxCpu >= cpu) { + maxCpuFinal = maxCpu; + } + if ($("input:checkbox", "#form-edit-processor").prop("checked")) { + data['cpu_info'] = { + vcpus: cpu, + maxvcpus: maxCpuFinal, + topology: { + sockets: parseInt($("#sockets").val()), + cores: parseInt($("#cores").val()), + threads: parseInt($("#threads").val()) + } + }; + } else { + data['cpu_info'] = { + vcpus: cpu, + maxvcpus: maxCpuFinal, + topology: {} + }; + } + + kimchi.updateVM(kimchi.selectedGuest, data, function() { + kimchi.listVmsAuto(); + wok.window.close(); + }, function(err) { + wok.message.error(err.responseJSON.reason, '#alert-modal-container'); + $(saveButton).prop('disabled', false); + }); + }); + }; + if(kimchi.hostarch === s390xArch){ $('#guest-edit-window ul li a[data-id="form-guest-edit-pci"],a[data-id="form-guest-edit-snapshot"]').parent().hide(); } diff --git a/ui/js/src/kimchi.template_edit_main.js b/ui/js/src/kimchi.template_edit_main.js index ecce151..f82b615 100644 --- a/ui/js/src/kimchi.template_edit_main.js +++ b/ui/js/src/kimchi.template_edit_main.js @@ -77,6 +77,15 @@ kimchi.init_processor_tab = function(cpu_info, save_form_button) { setCPUValue(); }); + $("#guest-edit-max-processor-textbox").change(function() { + save_form_button.prop('disabled', false); + var vcpus = parseInt($('#vcpus').val()); + var maxCpu = parseInt($("#guest-edit-max-processor-textbox").val()); + if (vcpus > maxCpu) { + $("#vcpus").val(maxCpu); + } + }); + $('#vcpus').change(function() { var computedCpu = getMaxVCpus(); var vcpus = parseInt($('#vcpus').val()); @@ -87,6 +96,7 @@ kimchi.init_processor_tab = function(cpu_info, save_form_button) { $(this).toggleClass("invalid-field", invalid_vcpu); save_form_button.prop('disabled', invalid_vcpu); } else { + save_form_button.prop('disabled', false); var maxCpu = parseInt($("#guest-edit-max-processor-textbox").val()); if (vcpus > maxCpu) { $("#vcpus").val(maxCpu); diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl index 9580be1..0e644ed 100644 --- a/ui/pages/i18n.json.tmpl +++ b/ui/pages/i18n.json.tmpl @@ -71,7 +71,6 @@ "KCHVM0001E": "$_("Input is not a number")", "KCHVM0002E": "$_("Memory value cannot be higher than Max Memory value")", - "KCHVM0003E": "$_("Current CPUs value cannot be higher than Max CPU value")", "KCHVMCD6001M": "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", "KCHVMCD6002M": "$_("Attach")", -- 2.7.4