|
1 | 1 | AutoForm.hooks({ |
2 | 2 | apiBackends: { |
3 | | - beginSubmit: function () { |
4 | | - // Disable form elements while submitting form |
5 | | - $('[data-schema-key], button').attr("disabled", "disabled"); |
6 | | - }, |
7 | | - endSubmit: function () { |
8 | | - // Enable form elements after form submission |
9 | | - $('[data-schema-key], button').removeAttr("disabled"); |
10 | | - }, |
11 | | - before: { |
12 | | - // Replace `formType` with the form `type` attribute to which this hook applies |
13 | | - insert: function (apiBackendForm) { |
14 | | - // Keep the context to use inside the callback function |
15 | | - context = this; |
16 | | - |
17 | | - // Send the API Backend to API Umbrella |
18 | | - response = Meteor.call('createApiBackendOnApiUmbrella', apiBackendForm, function(error, apiUmbrellaWebResponse) { |
19 | | - |
20 | | - //apiUmbrellaWebResponse contents |
21 | | - // apiUmbrellaWebResponse = { |
22 | | - // result: {}, |
23 | | - // http_status: 200, |
24 | | - // errors: {} |
25 | | - // }; |
26 | | - |
27 | | - if (apiUmbrellaWebResponse.http_status === 200) { |
28 | | - //Return asynchronously |
29 | | - context.result(apiBackendForm); |
30 | | - } else { |
31 | | - // ex 1: |
32 | | - // {"default":'{"backend_protocol":["is not included in the list"]}}' |
33 | | - // ex 2: |
34 | | - // {"errors":{"frontend_host":["must be in the format of \"example.com\""], |
35 | | - // "backend_host":["must be in the format of \"example.com\""], |
36 | | - // "base":["must have at least one url_matches"], |
37 | | - // "servers[0].host":["must be in the format of \"example.com\"","Could not resolve host: no address for http://api.example.com"], |
38 | | - // "servers[0].port":["can't be blank","is not included in the list"]} |
39 | | - // } |
40 | | - |
41 | | - var errors = _.values(apiUmbrellaWebResponse.errors); |
42 | | - errors = _.flatten(errors); |
43 | | - _.each(errors, function(error) { |
44 | | - console.log(error); |
45 | | - //Display error to the user, keep the sAlert box visible. |
46 | | - sAlert.error(error, {timeout: 'none'}); |
47 | | - // Figure out a way to send the errors back to the autoform fields, as if it were client validation. |
48 | | - }); |
49 | | - |
50 | | - //Return error asynchronously |
51 | | - context.result(false); |
52 | | - } |
53 | | - }); |
54 | | - } |
55 | | - }, |
56 | | - onSuccess: function (formType, apiBackendId) { |
57 | | - //Redirect to the just created API Backend page |
58 | | - Router.go('viewApiBackend', {_id: apiBackendId}); |
| 3 | + onSuccess: function (formType, backendId) { |
| 4 | + // Send the API Backend to API Umbrella |
| 5 | + Meteor.call('createApiBackendOnApiUmbrella', backendId); |
| 6 | + // Redirect to the just created API Backend page |
| 7 | + Router.go('viewApiBackend', {_id: backendId}); |
59 | 8 | } |
60 | 9 | } |
61 | 10 | }); |
0 commit comments