diff --git a/README.md b/README.md index b7910b7..c9c1ffd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # redmine_issue_dynamic_edit -Add new dropdowns elements on detailed issue page to dynamically update issue's status, assignee and priority directly in the details block of the issue -**You have to enable Redmine REST API** (`Administration` > `Settings` > `API` > check **Enable REST web service**) +Add new dropdown elements on detailed issue page to dynamically update issue's status, assignee and priority fields, directly in the details block of the issue. ### Example @@ -9,11 +8,15 @@ Add new dropdowns elements on detailed issue page to dynamically update issue's ### Installation -* Enable REST API * Clone repo into plugins directory : `git clone https://github.com/Ilogeek/redmine_issue_dynamic_edit.git` * Restart your Redmine instance ### Customization -Feel free to edit `assets/stylesheets/issue_dynamic_edit.css` to update the look of your fields depending on your current Redmine Theme -This plugin uses [FontAwesome icons](http://fontawesome.io/) \ No newline at end of file +Feel free to edit `assets/stylesheets/issue_dynamic_edit.css` to update the look of your fields depending on your current Redmine Theme. +This plugin uses [FontAwesome icons](http://fontawesome.io/) + +### Changelog + +* **v 0.2.0** : fixed "conflict" when trying to add a note after an update from dropdowns. New method used, REST API is not required anymore +* **v 0.1.0** : initial commit \ No newline at end of file diff --git a/README.rdoc b/README.rdoc index 6bce2f5..e83982f 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,4 +1,3 @@ = redmine_issue_dynamic_edit Add new dropdowns elements on detailed issue page to dynamically update issue's status, assignee and priority directly in the details block of the issue -You have to enable Redmine REST API diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 8eca8e1..4857b14 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -1,3 +1,4 @@ +/* FontAwesome inclusion */ var cssId = 'fontAwesome'; if (!document.getElementById(cssId)) { @@ -10,7 +11,8 @@ var cssId = 'fontAwesome'; link.media = 'all'; head.appendChild(link); } - + +/* Put new dropdown lists in the detailed info block */ if($('#statusListDropdown').length > 0) { var htmlCopy = $('#statusListDropdown').get(0).outerHTML; $('#statusListDropdown').remove(); @@ -28,23 +30,18 @@ if($('#prioritiesListDropdown').length > 0) { $('#prioritiesListDropdown').remove(); $('.details .attributes .priority.attribute .value').html(htmlCopy); } - -function updateDataIssue(field_name, field_value, cssClass) { + +function issueDynamicUpdate(field_name, field_value, cssClass){ $('.details .attributes .' + cssClass + '.attribute .value').append(' '); - ticketData = ''; - ticketData += ''; - ticketData += '' + _ISSUE_ID + ''; - ticketData += '<' + field_name + '>'+ field_value +''; - ticketData += ''; + var token = $("meta[name=csrf-token]").attr('content'); jQuery.ajax({ - type: 'PUT', - url: '/issues/' + _ISSUE_ID + '.xml', - crossDomain: true, + type: 'POST', + url: '/issues/bulk_update?back_url=%2Fissues&ids%5B%5D=' + _ISSUE_ID + '&issue%5B' + field_name + '%5D=' + field_value, + data: { "authenticity_token" : token }, + crossDomain: true, async: false, - contentType: "application/xml", - data: ticketData, beforeSend: function(xhr) { - xhr.setRequestHeader("X-Redmine-API-Key", _USER_API_KEY); + xhr.setRequestHeader("authenticity_token", token); }, success: function(msg) { setTimeout(function(){ @@ -57,22 +54,28 @@ function updateDataIssue(field_name, field_value, cssClass) { $('.details .attributes .' + cssClass + '.attribute .value i.fa-check').remove(); }, 2000); }, 500); + + // update other fields to avoid conflict + $('#issue_lock_version').val(parseInt($('#issue_lock_version').val()) + 1 ); + $('#last_journal_id').val(parseInt($('#last_journal_id').val()) + 1 ); + $('#issue_' + field_name + ' option').removeAttr('selected').filter('[value=' + field_value + ']').prop('selected', true); }, error: function(xhr, msg, error) {} }); - } /* end function updateDataIssue */ - +}; + +/* Listeners foreach dropdown */ var domSelectStatus = $('body').find('#statusListDropdown select'); domSelectStatus.on('change', function(e){ - updateDataIssue('status_id', domSelectStatus.val(), 'status'); + issueDynamicUpdate('status_id', domSelectStatus.val(), 'status'); }); /* end on change domSelectStatus */ var domSelectPriorities = $('body').find('#prioritiesListDropdown select'); domSelectPriorities.on('change', function(e){ - updateDataIssue('priority_id', domSelectPriorities.val(), 'priority'); + issueDynamicUpdate('priority_id', domSelectPriorities.val(), 'priority'); }); /* end on change domSelectPriorities */ var domSelectUsers = $('body').find('#usersListDropdown select'); domSelectUsers.on('change', function(e){ - updateDataIssue('assigned_to_id', domSelectUsers.val(), 'assigned-to'); + issueDynamicUpdate('assigned_to_id', domSelectUsers.val(), 'assigned-to'); }); /* end on change domSelectUsers */ \ No newline at end of file diff --git a/init.rb b/init.rb index 8d10425..5eaeb33 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\'s status, assignee and priority in detailed view using REST API' - version '0.1.0' + version '0.2.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 9ff593a..46aa163 100644 --- a/lib/details_issue_hooks.rb +++ b/lib/details_issue_hooks.rb @@ -23,7 +23,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener if (issue) if (User.current.allowed_to?(:edit_issues, project)) o = '' - statuses = issue.new_statuses_allowed_to(User.current) + statuses = issue.new_statuses_allowed_to(User.current) if (!statuses.empty?) o << "" o << "
#{issue.status}
"