diff --git a/README.md b/README.md index f738908..10a45bd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # redmine_issue_dynamic_edit -Add new elements on detailed issue page to dynamically update issue's title, status, assignee, priority, start and due dates, ratio and estimated time fields, directly in the details block of the issue without any page refresh (JIRA style). +Add new elements on detailed issue page to **dynamically update issue's attributes and custom fields**, directly in the details block of the issue **without any page refresh** (*JIRA style*). -### 🔴 What info should you provide when opening an issue + +### 🔴 What info you should provide when opening an issue >This plugin use JS a lot. Could you then please check your JS console from your web browser ( [HowTo](https://webmasters.stackexchange.com/a/77337) ) and try again your issue. You'll see some information about what goes wrong. > >Could you copy / paste it in your issue and expand all possible object (error data for example) so we can look if there's a problem with the ajax call the plugin performs to update the issue or if there's any JS error. @@ -24,6 +25,7 @@ This plugin uses [FontAwesome icons](http://fontawesome.io/) ### Changelog +* **v 0.6.0** : NOW WITH CUSTOM FIELDS SUPPORT ! (Github #19) * **v 0.5.0** : fixed Github issue #18 : textarea fixed (jstoolbar or ckeditor) * **v 0.4.9** : fixed Github issue #17 : Datepicker fallback added for date fields * **v 0.4.8** : fixed Github issues #15 and #16 diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index ddb86d1..89a1804 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -91,6 +91,37 @@ function initEditFields() $('div.description .wiki').html(' ' + $('div.description .wiki').html() + '' + htmlCopy).addClass('value'); } + + for(var i = 0 ; i < CF_VALUE_JSON.length ; i++) + { + var info = CF_VALUE_JSON[i].custom_field; + var value = CF_VALUE_JSON[i].value; + if(info.visible && info.editable) + { + if($('.details .attributes .cf_' + info.id + '.attribute .value').length) + { + var htmlCopy = $('#issue_custom_field_values_' + info.id).get(0).outerHTML; + // 2 technics with simple or double quote (safety first) + htmlCopy = htmlCopy.replace('id="', 'id="dynamic_').replace("id='", "id='dynamic_"); + htmlCopy = htmlCopy.replace('class="', 'class="cf_' + info.id + ' ').replace("class='", "class='cf_" + info.id + " "); + + var editHTML = ""; + editHTML += htmlCopy; + editHTML += " "; + editHTML += " "; + editHTML += ""; + + $('.details .attributes .cf_' + info.id + '.attribute .value').html('' + + $('.details .attributes .cf_' + info.id + '.attribute .value').html() + ' ' + + editHTML); + + if(info.field_format == "date") + { + $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback(datepickerOptions); + } + } + } + } } initEditFields(); @@ -152,7 +183,6 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){ url: _BASE_REDMINE_PATH + '/issues/bulk_update?back_url=' + prepareReturnUrl + '&ids%5B%5D=' + _ISSUE_ID + '&issue%5B' + field_name + '%5D=' + field_value, data: { "authenticity_token" : token }, crossDomain: true, - async: false, beforeSend: function(xhr) { xhr.setRequestHeader("authenticity_token", token); }, @@ -205,14 +235,14 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){ $('div.issue.details').html($(parsed).find('div.issue.details').html()); $('body').find('.details .' + cssClass + ' .value').append(' '); + /* we update issue properties edit block */ + $('#all_attributes').html($(parsed).find('#all_attributes').html()); + /* we init edit fields */ initEditFields(); initEditFieldListeners(); updateRequiredFields(JSON.parse($(parsed).find('#required_field_array').html())); - - /* we update issue properties edit block */ - $('#all_attributes').html($(parsed).find('#all_attributes').html()); /* we update the history list */ $('#history').append($(parsed).find('#history .journal.has-details:last-child')); @@ -387,6 +417,59 @@ function initEditFieldListeners() } /* end Description */ + + /* Custom fields */ + for(var i = 0 ; i < CF_VALUE_JSON.length ; i++) + { + (function() { + var info = CF_VALUE_JSON[i].custom_field; + var value = CF_VALUE_JSON[i].value; + if(info.visible && info.editable) + { + var inputType = "input"; + switch (info.field_format) + { + case "bool": + case "user": + case "list": + case "enumeration": + case "version": + inputType = "select"; + break; + case "text": + inputType = "textarea"; + break; + + } + + 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) + { + issueDynamicUpdate('custom_field_values%5D%5B' + info.id , domInputField.val(), inputType, 'cf_' + info.id); + + return false; + }); + + domInputField.on('keyup', function(e){ + if (e.keyCode == 13 && inputType != "textarea") { + $('body').find('#dynamic_edit_cf_' + info.id + ' a.btn.validate').click(); + } + }); + + if(inputType == "textarea") + { + if(typeof(jsToolBar) === typeof(Function)) + { + var wikiToolbar = new jsToolBar(domInputField); wikiToolbar.setHelpLink('/help/fr/wiki_syntax_textile.html'); wikiToolbar.draw(); + } else if(typeof(CKEDITOR) === "object" && typeof(CKEDITOR.replace) === typeof(Function)) { + CKEDITOR.replace('dynamic_issue_custom_field_values_' + info.id, { height: 100 }); + } + } + + } + }()); // closure FTW + } + } initEditFieldListeners(); \ No newline at end of file diff --git a/assets/stylesheets/issue_dynamic_edit.css b/assets/stylesheets/issue_dynamic_edit.css index aeaa7d1..9ef5286 100644 --- a/assets/stylesheets/issue_dynamic_edit.css +++ b/assets/stylesheets/issue_dynamic_edit.css @@ -101,4 +101,8 @@ body.controller-issues.action-show div.issue.details .splitcontent { div.issue div.subject h3 { position:relative; display: inline-block; +} + +body.controller-issues.action-show .dynamicEdit input[type="text"] { + width: auto !important; } \ No newline at end of file diff --git a/init.rb b/init.rb index 1c5b702..80e10b1 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.5.0' + version '0.6.0' url 'https://github.com/ilogeek/redmine_issue_dynamic_edit' author_url 'https://hzilliox.fr' end diff --git a/lib/details_issue_hooks.rb b/lib/details_issue_hooks.rb index 8f93573..b896fdf 100644 --- a/lib/details_issue_hooks.rb +++ b/lib/details_issue_hooks.rb @@ -159,12 +159,16 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener end o << "