From c995e93bc1c3b527bbf2fa457608b2d6cfa9780b Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Fri, 2 May 2014 18:01:16 -0700 Subject: [PATCH] Transactions - make ctrl + enter submit ajax-style Summary: We were correctly invoked a didSyntheticSubmit event on the form, but nothing was listening to it. Re-jigger the workflow submit code a tad so an onsyntheticsubmit event handler can be written to fill this gap. Fixes T4669. Test Plan: edited comments, submitting both via clicking the button and apple + enter LIKE A BOSS Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T4669 Differential Revision: https://secure.phabricator.com/D8961 --- resources/celerity/map.php | 28 +++++----- .../rsrc/externals/javelin/lib/Workflow.js | 54 ++++++++++++------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 58f33f94f2..79b17b0394 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -14,7 +14,7 @@ return array( 'differential.pkg.js' => '11a5b750', 'diffusion.pkg.css' => '3783278d', 'diffusion.pkg.js' => '5b4010f4', - 'javelin.pkg.js' => '0452e69d', + 'javelin.pkg.js' => '9f6d38c7', 'maniphest.pkg.css' => 'f1887d71', 'maniphest.pkg.js' => '2fe8af22', 'rsrc/css/aphront/aphront-bars.css' => '231ac33c', @@ -208,7 +208,7 @@ return array( 'rsrc/externals/javelin/lib/Resource.js' => '356de121', 'rsrc/externals/javelin/lib/URI.js' => 'd9a9b862', 'rsrc/externals/javelin/lib/Vector.js' => '039fb90d', - 'rsrc/externals/javelin/lib/Workflow.js' => 'f28bf201', + 'rsrc/externals/javelin/lib/Workflow.js' => 'ff8091f7', 'rsrc/externals/javelin/lib/__tests__/Cookie.js' => '5ed109e8', 'rsrc/externals/javelin/lib/__tests__/DOM.js' => 'c984504b', 'rsrc/externals/javelin/lib/__tests__/JSON.js' => '2295d074', @@ -668,7 +668,7 @@ return array( 'javelin-view-interpreter' => '0c33c1a0', 'javelin-view-renderer' => '6c2b09a2', 'javelin-view-visitor' => 'efe49472', - 'javelin-workflow' => 'f28bf201', + 'javelin-workflow' => 'ff8091f7', 'lightbox-attachment-css' => '7acac05d', 'maniphest-batch-editor' => '8f380ebc', 'maniphest-report-css' => '6fc16517', @@ -1883,17 +1883,6 @@ return array( 4 => 'javelin-request', 5 => 'javelin-workflow', ), - 'f28bf201' => - array( - 0 => 'javelin-stratcom', - 1 => 'javelin-request', - 2 => 'javelin-dom', - 3 => 'javelin-vector', - 4 => 'javelin-install', - 5 => 'javelin-util', - 6 => 'javelin-mask', - 7 => 'javelin-uri', - ), 'f42bb8c6' => array( 0 => 'javelin-stratcom', @@ -1985,6 +1974,17 @@ return array( 2 => 'javelin-workflow', 3 => 'javelin-dom', ), + 'ff8091f7' => + array( + 0 => 'javelin-stratcom', + 1 => 'javelin-request', + 2 => 'javelin-dom', + 3 => 'javelin-vector', + 4 => 'javelin-install', + 5 => 'javelin-util', + 6 => 'javelin-mask', + 7 => 'javelin-uri', + ), 28497740 => array( 0 => 'javelin-behavior', diff --git a/webroot/rsrc/externals/javelin/lib/Workflow.js b/webroot/rsrc/externals/javelin/lib/Workflow.js index 0a1bfdb617..4e83c02a0e 100644 --- a/webroot/rsrc/externals/javelin/lib/Workflow.js +++ b/webroot/rsrc/externals/javelin/lib/Workflow.js @@ -107,26 +107,39 @@ JX.install('Workflow', { JX.Workflow._pop(); } else { var form = event.getNode('jx-dialog'); + JX.Workflow._dosubmit(form, t); + } + }, + _onsyntheticsubmit : function(e) { + if (JX.Stratcom.pass()) { + return; + } + if (JX.Workflow._disabled) { + return; + } + e.prevent(); + var form = e.getNode('jx-dialog'); + var button = JX.DOM.find(form, 'button', '__default__'); + JX.Workflow._dosubmit(form, button); + }, + _dosubmit : function(form, button) { + // Issue a DOM event first, so form-oriented handlers can act. + var dom_event = JX.DOM.invoke(form, 'didWorkflowSubmit'); + if (dom_event.getPrevented()) { + return; + } - // Issue a DOM event first, so form-oriented handlers can act. - var dom_event = JX.DOM.invoke(form, 'didWorkflowSubmit'); - if (dom_event.getPrevented()) { - return; - } + var data = JX.DOM.convertFormToListOfPairs(form); + data.push([button.name, button.value || true]); - var data = JX.DOM.convertFormToListOfPairs(form); - - data.push([t.name, t.value || true]); - - var active = JX.Workflow._getActiveWorkflow(); - var e = active.invoke('submit', {form: form, data: data}); - if (!e.getStopped()) { - active._destroy(); - active - .setURI(form.getAttribute('action') || active.getURI()) - .setDataWithListOfPairs(data) - .start(); - } + var active = JX.Workflow._getActiveWorkflow(); + var e = active.invoke('submit', {form: form, data: data}); + if (!e.getStopped()) { + active._destroy(); + active + .setURI(form.getAttribute('action') || active.getURI()) + .setDataWithListOfPairs(data) + .start(); } }, _getActiveWorkflow : function() { @@ -155,6 +168,11 @@ JX.install('Workflow', { 'click', [['jx-workflow-button'], ['tag:button']], JX.Workflow._onbutton); + JX.DOM.listen( + this._root, + 'didSyntheticSubmit', + [], + JX.Workflow._onsyntheticsubmit); document.body.appendChild(this._root); var d = JX.Vector.getDim(this._root); var v = JX.Vector.getViewport();