From 103c06da3938a78a1badc35a051fad4998ac7274 Mon Sep 17 00:00:00 2001 From: Austin Schaffer Date: Tue, 14 Jan 2020 12:59:00 -0500 Subject: [PATCH] [DEV-6730] Post whether or not a save step will conclude the process --- src/client/Client.js | 19 +++++++++++----- src/client/ClientDependencyFactory.js | 10 +++++++-- src/client/transport/XhttpQuoteTransport.js | 22 ++++++++++++++----- src/ui/Ui.js | 21 +++++++++++------- .../transport/XhttpQuoteTransportTest.js | 7 +++++- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index cc5be28..416e973 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -1563,7 +1563,11 @@ module.exports = Class( 'Client' ) // transport used to transfer the bucket data to the server, prohibiting // callback aborts (to ensure that we can handle failures ourselves) - var transport = this._createBucketTransport( step_id, true ); + var transport = this._createBucketTransport( + step_id, + true, + event.concluding_save + ); var finish, timeout; function dosave() @@ -1712,11 +1716,16 @@ module.exports = Class( 'Client' ) }, - 'private _createBucketTransport': function( step_id, prohibit_abort ) - { + 'private _createBucketTransport': function( + step_id, + prohibit_abort, + concluding_save + ){ return this._factory.createDataBucketTransport( - this._quote.getId(), step_id, - this._createDataProxy( jQuery, prohibit_abort ) + this._quote.getId(), + step_id, + this._createDataProxy( jQuery, prohibit_abort ), + concluding_save ); }, diff --git a/src/client/ClientDependencyFactory.js b/src/client/ClientDependencyFactory.js index 9e23f15..955ee14 100644 --- a/src/client/ClientDependencyFactory.js +++ b/src/client/ClientDependencyFactory.js @@ -162,11 +162,17 @@ module.exports = Class( 'ClientDependencyFactory', createStagingBucketDiscard: StagingBucketAutoDiscard, - createDataBucketTransport: function ( quote_id, step_id, proxy ) + createDataBucketTransport: function ( + quote_id, + step_id, + proxy, + concluding_save + ) { return XhttpQuoteTransport( ( quote_id + '/step/' + step_id + '/post' ), - proxy + proxy, + concluding_save ); }, diff --git a/src/client/transport/XhttpQuoteTransport.js b/src/client/transport/XhttpQuoteTransport.js index c2084b2..0506738 100644 --- a/src/client/transport/XhttpQuoteTransport.js +++ b/src/client/transport/XhttpQuoteTransport.js @@ -42,19 +42,27 @@ module.exports = Class( 'XhttpQuoteTransport' ) */ 'private _url': '', + /** + * Indicates a concluding save + * @type {boolean} + */ + 'private _concluding_save': false, + /** * Constructs a new quote transport with the destination URL and proxy * - * @param {string} url destination URL - * @param {HttpDataProxy} proxy proxy to use for transfer + * @param {string} url destination URL + * @param {HttpDataProxy} proxy proxy to use for transfer + * @param {boolean} concluding_save concluding save * * @return {undefined} */ - 'public __construct': function( url, proxy ) + 'public __construct': function( url, proxy, concluding_save ) { - this._url = ''+( url ); - this._proxy = proxy; + this._url = ''+( url ); + this._proxy = proxy; + this._concluding_save = concluding_save; }, @@ -80,7 +88,9 @@ module.exports = Class( 'XhttpQuoteTransport' ) var data = _self.getBucketDataJson( bucket ); // post the data - _self._proxy.post( _self._url, { data: data }, + _self._proxy.post( + _self._url, + { data: data, concluding_save: _self._concluding_save }, function( data, error ) { if ( typeof callback === 'function' ) diff --git a/src/ui/Ui.js b/src/ui/Ui.js index 5547db1..421bd2c 100644 --- a/src/ui/Ui.js +++ b/src/ui/Ui.js @@ -934,7 +934,8 @@ module.exports = Class( 'Ui' ).extend( EventEmitter, }, // no UI update (IE will display a security warning // otherwise) - ( ( last_step ) ? true : false ) + last_step, + last_step ); }); @@ -1128,20 +1129,24 @@ module.exports = Class( 'Ui' ).extend( EventEmitter, return this; } - var len = this.saveStepHooks.length, - step = arguments[0] || this.getCurrentStep(), - callback = arguments[1] || function() {}, - fail_callback = arguments[2] || function() {}, - immediate = ( ( arguments[3] !== undefined ) + var len = this.saveStepHooks.length, + step = arguments[0] || this.getCurrentStep(), + callback = arguments[1] || function() {}, + fail_callback = arguments[2] || function() {}, + immediately_save = ( ( arguments[3] !== undefined ) ? arguments[3] : false ), + concluding_save = ( ( arguments[4] !== undefined ) + ? !!arguments[4] + : false + ), abort = false; var event = { forceCallback: false, errors: [], - + concluding_save: concluding_save, aborted: false, abort: function() { @@ -1285,7 +1290,7 @@ module.exports = Class( 'Ui' ).extend( EventEmitter, } }; - if ( immediate ) + if ( immediately_save ) { doSave(); } diff --git a/test/client/transport/XhttpQuoteTransportTest.js b/test/client/transport/XhttpQuoteTransportTest.js index 0401d24..0bfdd7f 100644 --- a/test/client/transport/XhttpQuoteTransportTest.js +++ b/test/client/transport/XhttpQuoteTransportTest.js @@ -58,6 +58,8 @@ describe( "XhttpQuoteTransport", () => bs: [ null ], }; + const concluding_save = true; + const stub_quote = { visitData: c => c( bucket ) }; const mock_proxy = { @@ -66,10 +68,13 @@ describe( "XhttpQuoteTransport", () => expect( JSON.parse( data.data ) ) .to.deep.equal( expected_data ); + expect( JSON.parse( data.concluding_save ) ) + .to.deep.equal( concluding_save ); + done(); }, }; - Sut( '', mock_proxy ).send( stub_quote ); + Sut( '', mock_proxy, concluding_save ).send( stub_quote ); } ); } );