From bd79cc4aebd2bfa5e5b4f575cac3f0d06711a846 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 7 Jan 2021 08:14:43 +1100 Subject: [PATCH 1/3] Only submit changed fields --- assets/javascripts/issue_dynamic_edit.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 428e302..112920d 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -49,6 +49,7 @@ function editActionHandler(e) { $(e.target).closest('span.dynamicEdit').length) ) { $(e.target).closest('.value').addClass('edited'); + $(e.target).addClass('modified'); } if ($(e.target).closest('a').length) { return; } if ($(e.target).closest('.' + _CONF_LISTENER_TARGET).length) { @@ -359,27 +360,32 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass) { // avoid conflict revision var lastLockVersion = getLastLockVersion(); $('#issue_lock_version').val(lastLockVersion); - var formData = ""; + var formData = {}; // If checkbox we have to uncheck everything in the issue-form and get data from dynamic edit if(type == "checkbox"){ - formData = field_value + "&"; var cf_id = field_name.replace(/\D/g,''); + var check_box_name= 'issue[custom_field_values][' + cf_id + '][]'; + var values = new Array(); + $('.dynamicEdit input[name=issue\\[custom_field_values\\]\\[' + 4 + '\\]\\[\\]]:checked').each(function(){ + values.push($(this).val()); + }); $('input[name=issue\\[custom_field_values\\]\\[' + cf_id + '\\]\\[\\]]').each(function(){ $(this).prop('checked', false); }); + formData[check_box_name] = values; + }else{ + formData['issue['+field_name+']'] = field_value; } - formData += $('#issue-form').serialize(); + formData['_method'] ='patch'; + formData['authenticity_token'] = token; jQuery.ajax({ type: 'POST', url: LOCATION_HREF, data: formData, - beforeSend: function(xhr) { - xhr.setRequestHeader("authenticity_token", token); - }, success: function(msg) { /* get result page content (updated issue detail page with new status) */ @@ -704,3 +710,4 @@ function initEditFieldListeners() { } initEditFieldListeners(); + From 002b04fae37167ef23b353d8e3f729c4570684a4 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 7 Jan 2021 08:20:51 +1100 Subject: [PATCH 2/3] remove unused line --- assets/javascripts/issue_dynamic_edit.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 112920d..6361759 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -49,7 +49,6 @@ function editActionHandler(e) { $(e.target).closest('span.dynamicEdit').length) ) { $(e.target).closest('.value').addClass('edited'); - $(e.target).addClass('modified'); } if ($(e.target).closest('a').length) { return; } if ($(e.target).closest('.' + _CONF_LISTENER_TARGET).length) { From f08b048882fe01cd34e009ed6a1164b11f0b051f Mon Sep 17 00:00:00 2001 From: Michael Mueller <52896557+michaelmueller-binary@users.noreply.github.com> Date: Thu, 14 Jan 2021 15:20:58 +1100 Subject: [PATCH 3/3] Fix Bug of hard coded cf_id and unable clear check boxes. --- assets/javascripts/issue_dynamic_edit.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 6361759..d481d31 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -366,13 +366,17 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass) { var cf_id = field_name.replace(/\D/g,''); var check_box_name= 'issue[custom_field_values][' + cf_id + '][]'; var values = new Array(); - $('.dynamicEdit input[name=issue\\[custom_field_values\\]\\[' + 4 + '\\]\\[\\]]:checked').each(function(){ + $('.dynamicEdit input[name=issue\\[custom_field_values\\]\\[' + cf_id + '\\]\\[\\]]:checked').each(function(){ values.push($(this).val()); }); $('input[name=issue\\[custom_field_values\\]\\[' + cf_id + '\\]\\[\\]]').each(function(){ $(this).prop('checked', false); }); - formData[check_box_name] = values; + if (values.length) { + formData[check_box_name] = values; + } else { + formData[check_box_name] = ['']; + } }else{ formData['issue['+field_name+']'] = field_value; }