|
97 | 97 | } |
98 | 98 | } |
99 | 99 |
|
100 | | - if (saveChanges === null || saveChanges === undefined) { |
101 | | - saveChanges = function() { |
102 | | - const data = schemaManager.data; |
103 | | - // The following is required to remove all null values from the data object |
104 | | - // We suppose that null values are not valid, hence we remove them |
105 | | - // Deep copy the data object |
106 | | - const toStripData = JSON.parse(JSON.stringify(data)); |
107 | | - const strippedNullData = stripNullAndEmptyObjectsAndArrays(toStripData); |
108 | | - const isDataValid = validator.isValid(strippedNullData); |
109 | | - if (!isDataValid) { |
110 | | - if (handleValidationErrors !== null && handleValidationErrors !== undefined) { |
111 | | - handleValidationErrors(validator.getErrors()); |
112 | | - } |
113 | | - console.error('Could not save changes. Data is invalid', validator.getErrors()); |
114 | | - return; |
115 | | - } |
116 | | -
|
117 | | - if (handleSaveChanges !== null && handleSaveChanges !== undefined) { |
118 | | - handleSaveChanges(strippedNullData) |
119 | | - .then((updated_args) => { |
120 | | - schemaManager.data = updated_args; |
121 | | - schemaManager.changesSaved(); |
122 | | - }) |
123 | | - .catch((err) => { |
124 | | - console.error(err); |
125 | | - }); |
126 | | - } |
127 | | - } |
128 | | - } |
| 100 | + saveChanges = function() { |
| 101 | + const data = schemaManager.data; |
| 102 | + // The following is required to remove all null values from the data object |
| 103 | + // We suppose that null values are not valid, hence we remove them |
| 104 | + // Deep copy the data object |
| 105 | + const toStripData = JSON.parse(JSON.stringify(data)); |
| 106 | + const strippedNullData = stripNullAndEmptyObjectsAndArrays(toStripData); |
| 107 | + const isDataValid = validator.isValid(strippedNullData); |
| 108 | + if (!isDataValid) { |
| 109 | + if (handleValidationErrors !== null && handleValidationErrors !== undefined) { |
| 110 | + handleValidationErrors(validator.getErrors()); |
| 111 | + } |
| 112 | + console.error('Could not save changes. Data is invalid', validator.getErrors()); |
| 113 | + return; |
| 114 | + } |
| 115 | +
|
| 116 | + if (handleSaveChanges !== null && handleSaveChanges !== undefined) { |
| 117 | + handleSaveChanges(strippedNullData) |
| 118 | + .then((updated_args) => { |
| 119 | + schemaManager.data = updated_args; |
| 120 | + schemaManager.changesSaved(); |
| 121 | + }) |
| 122 | + .catch((err) => { |
| 123 | + console.error(err); |
| 124 | + }); |
| 125 | + } |
| 126 | + } |
129 | 127 |
|
130 | 128 | export function discardChanges(args) { |
131 | 129 | // Set schemaData to incoming args value |
|
0 commit comments