Commit 725a4fef authored by Jacob Schatz's avatar Jacob Schatz Committed by Mike Greiling

Add thenable ajax calls.

parent 91d3e6d9
...@@ -99,15 +99,13 @@ const Api = { ...@@ -99,15 +99,13 @@ const Api = {
commitMultiple(id, data, callback) { commitMultiple(id, data, callback) {
const url = Api.buildUrl(Api.commitPath) const url = Api.buildUrl(Api.commitPath)
.replace(':id', id); .replace(':id', id);
return $.ajax({ return this.wrapAjaxCall({
url, url,
type: 'POST', type: 'POST',
contentType: 'application/json; charset=utf-8', contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data), data: JSON.stringify(data),
dataType: 'json', dataType: 'json',
}) });
.done(commitData => callback(commitData))
.fail(message => callback(message.responseJSON));
}, },
// Return text for a specific license // Return text for a specific license
......
...@@ -42,10 +42,11 @@ export default { ...@@ -42,10 +42,11 @@ export default {
actions, actions,
}; };
Store.submitCommitsLoading = true; Store.submitCommitsLoading = true;
Service.commitFiles(payload, this.resetCommitState); Service.commitFiles(payload)
.then(this.resetCommitState);
}, },
resetCommitState() { resetCommitState(data) {
this.submitCommitsLoading = false; this.submitCommitsLoading = false;
this.changedFiles = []; this.changedFiles = [];
this.commitMessage = ''; this.commitMessage = '';
......
...@@ -65,14 +65,14 @@ const RepoService = { ...@@ -65,14 +65,14 @@ const RepoService = {
return urlArray.join('/'); return urlArray.join('/');
}, },
commitFiles(payload, cb) { commitFiles(payload) {
Api.commitMultiple(Store.projectId, payload, (data) => { return Api.commitMultiple(Store.projectId, payload)
.then((data) => {
if (data.short_id && data.stats) { if (data.short_id && data.stats) {
Flash(`Your changes have been committed. Commit ${data.short_id} with ${data.stats.additions} additions, ${data.stats.deletions} deletions.`, 'notice'); Flash(`Your changes have been committed. Commit ${data.short_id} with ${data.stats.additions} additions, ${data.stats.deletions} deletions.`, 'notice');
} else { } else {
Flash(data.message); Flash(data.message);
} }
cb();
}); });
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment