@@ -15,7 +15,7 @@ AutoForm.hooks({
1515 if ( proxyBackend && proxyBackend . proxyId === undefined ) {
1616 // Notify users about no selected proxy
1717 const message = TAPi18n . __ ( 'proxyBackendForm_informText_noOneSelectedProxy' ) ;
18- sAlert . info ( message )
18+ sAlert . info ( message ) ;
1919 return false ;
2020 }
2121
@@ -90,6 +90,8 @@ AutoForm.hooks({
9090 }
9191 } ,
9292 update ( updateDoc ) {
93+ // Get reference to autoform instance, for form submission callback
94+ const form = this ;
9395 // Get proxyBackend $set values
9496 const currentProxyBackend = updateDoc . $set ;
9597
@@ -103,7 +105,7 @@ AutoForm.hooks({
103105 // Then delete proxy backend information from api umbrella
104106 if ( currentProxyBackend . proxyId === undefined ) {
105107 // Delete proxy backend information from api umbrella
106- deleteProxyBackendConfig ( proxyBackendFromMongo )
108+ deleteProxyBackendConfig ( proxyBackendFromMongo ) ;
107109
108110 return false ;
109111 }
@@ -130,37 +132,41 @@ AutoForm.hooks({
130132 const previousProxyId = proxyBackendFromMongo . proxyId ;
131133 const currentProxyId = currentProxyBackend . proxyId ;
132134
133- // TODO: In multi-proxy case. After changing proxy, onSuccess hook happens faster then umbrella id is got.
134135 // Check: if user changed proxy
135- if ( previousProxyId !== currentProxyId ) {
136+ if ( previousProxyId === currentProxyId ) {
137+ // Case 1: Proxy not changed, return modifier
138+ updateDoc . $set = currentProxyBackend ;
139+ form . result ( updateDoc ) ;
140+ } else {
141+ // Case 2: Proxy changed
136142 // Delete information about proxy backend from the first proxy and insert in the
137143 Meteor . call ( 'deleteProxyBackend' ,
138144 proxyBackendFromMongo , false ,
139- function ( error ) {
145+ ( error ) => {
140146 if ( error ) {
141- this . result ( false ) ;
147+ form . result ( false ) ;
142148 }
143- } ) ;
149+ } ) ;
144150
145151 const convertedProxyBackend = convertToApiUmbrellaObject ( currentProxyBackend ) ;
146152
147153 // Create API backend on API Umbrella
148154 Meteor . call ( 'createApiBackendOnApiUmbrella' ,
149155 convertedProxyBackend . apiUmbrella , convertedProxyBackend . proxyId ,
150- function ( error , response ) {
156+ ( error , response ) => {
151157 if ( error ) {
152158 // Throw a Meteor error
153- sAlert . error ( error )
154- // sync return false;
155- return false ;
159+ sAlert . error ( error ) ;
160+ // async return false;
161+ form . result ( false ) ;
156162 }
157163
158164 // If response has errors object, notify about it
159165 if ( response . errors && response . errors . default ) {
160166 // Notify about error
161167 sAlert . error ( response . errors . default [ 0 ] ) ;
162- // sync return false;
163- return false ;
168+ // async return false;
169+ form . result ( false ) ;
164170 }
165171
166172 // If success, attach API Umbrella backend ID to API
@@ -174,22 +180,21 @@ AutoForm.hooks({
174180 // Publish the API Backend on API Umbrella
175181 Meteor . call ( 'publishApiBackendOnApiUmbrella' ,
176182 umbrellaBackendId , convertedProxyBackend . proxyId ,
177- function ( error ) {
178- if ( error ) {
179- sAlert . error ( error ) ;
180- // sync return false;
181- return false ;
183+ ( publishError ) => {
184+ if ( publishError ) {
185+ sAlert . error ( publishError ) ;
186+ // async return false;
187+ form . result ( false ) ;
182188 }
183- // sync return the Proxy Backend document
189+ // async return the Proxy Backend document
184190 updateDoc . $set = convertedProxyBackend ;
185- return updateDoc ;
191+ form . result ( updateDoc ) ;
186192 }
187193 ) ;
188194 }
189195 } ) ;
190196 }
191197 }
192- return updateDoc ;
193198 } ,
194199 } ,
195200 onSuccess ( formType , result ) {
0 commit comments