From 26684a2dd9b12dcc7377afd79e9fe5c142d26ebd Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 2 Sep 2018 15:18:56 +0200 Subject: [PATCH] Fixed lock version update (#26 #28) - custom issue url support (#29) --- README.md | 1 + assets/javascripts/issue_dynamic_edit.js | 44 ++++++++++++++++++++---- init.rb | 2 +- lib/details_issue_hooks.rb | 2 +- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d2a9ce8..4db6259 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ This plugin uses [FontAwesome icons](http://fontawesome.io/) ### Changelog +* **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) * **v.0.6.4** : version field with checkbox display is now supported, Target version and Assignee fields are also supported (Github request #24) * **v 0.6.3** : fixed Github issue #22 : DatepickerFallback raised an error * **v 0.6.2** : fixed Github issue #22 : long description is now supported (no more 414 errors) diff --git a/assets/javascripts/issue_dynamic_edit.js b/assets/javascripts/issue_dynamic_edit.js index 915b4b0..0413c4e 100644 --- a/assets/javascripts/issue_dynamic_edit.js +++ b/assets/javascripts/issue_dynamic_edit.js @@ -1,3 +1,6 @@ +/* Allow inclusion from other page */ +var LOCATION_HREF = typeof custom_location_href !== 'undefined' ? custom_location_href : window.location.href; + /* FontAwesome inclusion */ var cssId = 'fontAwesome'; if (!document.getElementById(cssId)) @@ -155,7 +158,8 @@ function initEditFields() if(info.field_format == "date") { if( $('body').find('#dynamic_issue_custom_field_values_' + info.id).length - && $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback instanceof Function) + && $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback instanceof Function + && typeof datepickerOptions !== 'undefined') { $('body').find('#dynamic_issue_custom_field_values_' + info.id).datepickerFallback(datepickerOptions); } @@ -176,7 +180,9 @@ function updateRequiredFields(reqFieldsArray) } } -updateRequiredFields(JSON.parse($('#required_field_array').html())); +if($('#required_field_array').length) { + updateRequiredFields(JSON.parse($('#required_field_array').html())); +} $('body.controller-issues.action-show').on('click', '.btn.close', function(e){ @@ -185,6 +191,26 @@ $('body.controller-issues.action-show').on('click', '.btn.close', function(e){ return false; }); +function getLastLockVersion() { + var token = $("meta[name=csrf-token]").attr('content'); + var lock_version = $('#issue_lock_version').val(); + jQuery.ajax({ + type: 'GET', + url: LOCATION_HREF, + data: { "authenticity_token" : token }, + crossDomain: true, + async: false, + beforeSend: function(xhr) { + xhr.setRequestHeader("authenticity_token", token); + }, + success: function(msg) { + parsed = $.parseHTML(msg); + lock_version = $(parsed).find('#issue_lock_version').val(); + } + }); + return lock_version; +} + function issueDynamicUpdate(field_name, field_value, type, cssClass){ /* hide edit field */ @@ -219,11 +245,14 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){ var token = $("meta[name=csrf-token]").attr('content'); $('#issue-form').find("#issue_" + field_name).val(field_value).css({"display": "inline-block"}); + // avoid conflict revision + var lastLockVersion = getLastLockVersion(); + $('#issue_lock_version').val(lastLockVersion); var formData = $('#issue-form').serialize(); jQuery.ajax({ type: 'POST', - url: _BASE_REDMINE_PATH + '/issues/' + _ISSUE_ID, + url: LOCATION_HREF, data: formData, beforeSend: function(xhr) { xhr.setRequestHeader("authenticity_token", token); @@ -254,7 +283,7 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){ jQuery.ajax({ type: 'GET', - url: window.location.href, + url: LOCATION_HREF, data: { "authenticity_token" : token }, crossDomain: true, async: false, @@ -287,7 +316,9 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){ initEditFields(); initEditFieldListeners(); - updateRequiredFields(JSON.parse($(parsed).find('#required_field_array').html())); + if($(parsed).find('#required_field_array').length) { + updateRequiredFields(JSON.parse($(parsed).find('#required_field_array').html())); + } /* we update the history list */ $('#history').append($(parsed).find('#history .journal.has-details:last-child')); @@ -302,7 +333,8 @@ function issueDynamicUpdate(field_name, field_value, type, cssClass){ //set datepicker fallback for input type date if( $('body').find('input[type=date]').length - && $('body').find('input[type=date]').datepickerFallback instanceof Function) + && $('body').find('input[type=date]').datepickerFallback instanceof Function + && typeof datepickerOptions !== 'undefined') { $('body').find('input[type=date]').datepickerFallback(datepickerOptions); } diff --git a/init.rb b/init.rb index d6dfa93..0fe2267 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.4' + version '0.6.5' 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 cfdca7e..a914c78 100644 --- a/lib/details_issue_hooks.rb +++ b/lib/details_issue_hooks.rb @@ -5,7 +5,7 @@ class DetailsIssueHooks < Redmine::Hook::ViewListener end def current_is_detail_page(context) - ret = context[:controller] && context[:controller].is_a?(IssuesController) && context[:request].original_url.rindex(/\/issues\/\d+/) + ret = context[:controller] && context[:controller].is_a?(IssuesController) && context[:request].original_url.rindex(/\/issues\/\S+/) end def view_layouts_base_html_head(context)