提交 725a4fef 编写于 作者: J Jacob Schatz 提交者: Mike Greiling

Add thenable ajax calls.

上级 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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册