Patch #20180

Make the updateIssueFrom(url) function return the XMLHttpRequest object

Added by Vincent Robert over 2 years ago. Updated about 2 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Code cleanup/refactoring
Target version:3.1.0

Description

The current javascript function updateIssueFrom(url) does not return anything.
If we could just return the XMLHttpRequest object (as it is returned by the ajax() call), it would allow us to chain methods like this:

updateIssueFrom(url).done(function() {
  $( this ).addClass( "done" );
});

Here is the patch:

diff --git a/public/javascripts/application.js b/public/javascripts/application.js
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -471,7 +471,7 @@ function updateIssueFrom(url) {
   $('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
     $(this).data('valuebeforeupdate', $(this).val());
   });
-  $.ajax({
+  return $.ajax({
     url: url,
     type: 'post',
     data: $('#issue-form').serialize()

This simple patch could really help me to simplify my Redmine plugins. Thank you.

Associated revisions

Revision 14372
Added by Jean-Philippe Lang over 2 years ago

Make the updateIssueFrom(url) function return the XMLHttpRequest object (#20180).

Patch by Vincent Robert.

History

#1 Updated by Jean-Philippe Lang over 2 years ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Target version set to 3.1.0

Committed in r14372, thanks.

#2 Updated by Jean-Philippe Lang over 2 years ago

  • Category changed from Plugin Request to Code cleanup/refactoring

#3 Updated by Etienne Massip about 2 years ago

FTR the object returned by the function is not a XMLHttpRequest but a Promise.

Also available in: Atom PDF