From 925895b51418b8394cc0be329c3367a71d6019f5 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 20 Oct 2019 14:28:51 +0200 Subject: [PATCH] Checkboxes custom fields fixed (#53) --- README.md | 1 + assets/javascripts/issue_dynamic_edit.js | 40 ++++++++++++++++------- assets/stylesheets/issue_dynamic_edit.css | 5 +++ init.rb | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 68d95fc..a16e817 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ This plugin uses [FontAwesome icons](http://fontawesome.io/) ### 🆕 Changelog +* **v 0.6.8** : Checkboxes custom fields fixed (#53) * **v 0.6.7** : fixed Github issue #46 : text field focus issue * **v 0.6.6** : New configuration file + Multiple fixes (#30 #31 #35 #36 #37 #38 #41) * **v 0.6.5** : Checklists plugin support (and all other plugins that compute fields when there's an issue update) (Github requests #26 and #28) + custom url support (Github request #29) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 8ed5002..28440a9 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -183,11 +183,16 @@ function initEditFields() { if (info.visible && info.editable && !isExcluded("issue_custom_field_values_" + info.id)) { if ( $('.details .attributes .cf_' + info.id + '.attribute .value').length && - $('#issue_custom_field_values_' + info.id).length + ( + $('#issue_custom_field_values_' + info.id).length || + $('input[name=issue\\[custom_field_values\\]\\[' + info.id + '\\]\\[\\]]').length + ) ) { - var htmlCopy = $('#issue_custom_field_values_' + info.id).get(0).outerHTML; - if (info.field_format == "version" && info.format_store.edit_tag_style == "check_box") { - htmlCopy = $('#issue_custom_field_values_' + info.id).parents('span').html(); + // if single input first case, else checkboxes second case + if($('#issue_custom_field_values_' + info.id).length) { + var htmlCopy = $('#issue_custom_field_values_' + info.id).get(0).outerHTML; + } else { + var htmlCopy = $('input[name=issue\\[custom_field_values\\]\\[' + info.id + '\\]\\[\\]]').parents('.check_box_group').get(0).outerHTML; } // 2 technics with simple or double quote (safety first) @@ -309,7 +314,18 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass) { // avoid conflict revision var lastLockVersion = getLastLockVersion(); $('#issue_lock_version').val(lastLockVersion); - var formData = $('#issue-form').serialize(); + 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,''); + $('input[name=issue\\[custom_field_values\\]\\[' + cf_id + '\\]\\[\\]]').each(function(){ + $(this).prop('checked', false); + }); + } + + formData += $('#issue-form').serialize(); jQuery.ajax({ @@ -597,18 +613,20 @@ function initEditFieldListeners() { break; } - // Specific case : version field with checkboxes - if (info.field_format == "version" && info.format_store.edit_tag_style == "check_box") { - inputType = "version"; - $('body').find('#dynamic_edit_cf_' + info.id + ' input').on('click', function(e) { - $('label[for=issue_custom_field_values_' + info.id + ']').next().find('input[value=' + $(this).val() + ']').click(); - }); + if(info.format_store.edit_tag_style == "check_box"){ + inputType = "checkbox"; } var domInputField = $('body').find('#dynamic_issue_custom_field_values_' + info.id); $('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').on('click', function(e) { var new_value = domInputField.val(); + // Specific case with checkboxes + if(typeof new_value === 'undefined'){ + var new_value = $('body').find('#dynamic_edit_cf_' + info.id + " :input").serialize(); + console.log(new_value); + } + issueDynamicUpdate('custom_field_values_' + info.id , new_value, inputType, 'cf_' + info.id); return false; diff --git a/assets/stylesheets/issue_dynamic_edit.css b/assets/stylesheets/issue_dynamic_edit.css index d669f0d..00e536b 100644 --- a/assets/stylesheets/issue_dynamic_edit.css +++ b/assets/stylesheets/issue_dynamic_edit.css @@ -109,4 +109,9 @@ div.issue div.subject h3 { body.controller-issues.action-show .dynamicEdit input[type="text"] { width: auto !important; +} + +body.controller-issues.action-show .dynamicEdit .check_box_group { + border: 0px !important; + margin-bottom: 10px; } \ No newline at end of file diff --git a/init.rb b/init.rb index 65af94e..f44d30c 100644 --- a/init.rb +++ b/init.rb @@ -6,7 +6,7 @@ Redmine::Plugin.register :redmine_issue_dynamic_edit do name 'Redmine Dynamic edit Issue plugin' author 'Hugo Zilliox' description 'Allows users to dynamically update issue attributes in detailed view without refreshing the page (JIRA style)' - version '0.6.7' + version '0.6.8' url 'https://github.com/ilogeek/redmine_issue_dynamic_edit' author_url 'https://hzilliox.fr' end