Skip to content

Commit d9ac5ef

Browse files
committed
#28: Consolidated exporting messages to a single success response message.
1 parent 5f2d204 commit d9ac5ef

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

assets/js/export-to-dejacode.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,34 @@ function uploadComponents(host, components, apiKey, productNameVersion) {
9191
component['product'] = productNameVersion;
9292
})
9393

94-
$.each(dejaCodeComponents, function( index, component ) {
94+
var errorMessages = {};
95+
var requests = []
96+
$.each(dejaCodeComponents, function( index, component) {
97+
var request = $.Deferred();
98+
requests.push(request);
9599
createComponent(host, component, apiKey)
96100
.done(function (data) {
97101
console.log('Successfully exported: ' + JSON.stringify(data));
98-
alert("Components submitted to DejaCode");
99102
})
100103
.fail(function(error) {
101104
console.log(error);
102-
alert("An error occurred. DejaCode response: \n\n " + error.responseText);
105+
errorMessages[component.name] = error.responseText;
106+
})
107+
.complete(function () {
108+
request.resolve();
103109
});
104110
});
111+
112+
// This will be called when all requests finish.
113+
$.when.apply($, requests)
114+
.done(function () {
115+
if (Object.keys(errorMessages).length > 0) {
116+
var msg = $.map(errorMessages, function(errorMessage, component) {
117+
return component + ": " + errorMessage;
118+
});
119+
alert("The following errors occurred:\n" + msg.join("\n\n"));
120+
} else {
121+
alert("Components submitted to DejaCode");
122+
}
123+
});
105124
}

0 commit comments

Comments
 (0)