2016-07-26 06:56:36 -04:00
|
|
|
((w) => {
|
|
|
|
w.ResolveBtn = Vue.extend({
|
2016-07-26 08:44:51 -04:00
|
|
|
mixins: [
|
|
|
|
ButtonMixins
|
|
|
|
],
|
2016-07-26 06:56:36 -04:00
|
|
|
props: {
|
|
|
|
noteId: Number,
|
|
|
|
discussionId: String,
|
|
|
|
resolved: Boolean,
|
2016-07-26 08:44:51 -04:00
|
|
|
namespacePath: String,
|
|
|
|
projectPath: String,
|
2016-07-26 10:47:19 -04:00
|
|
|
canResolve: Boolean,
|
|
|
|
resolvedBy: String
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
data: function () {
|
|
|
|
return {
|
2016-07-26 12:49:49 -04:00
|
|
|
discussions: CommentsStore.state,
|
2016-07-26 06:56:36 -04:00
|
|
|
loading: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
buttonText: function () {
|
|
|
|
if (this.isResolved) {
|
2016-07-26 10:47:19 -04:00
|
|
|
return `Resolved by ${this.resolvedByName}`;
|
2016-07-26 10:57:14 -04:00
|
|
|
} else if (this.canResolve) {
|
2016-07-26 10:47:19 -04:00
|
|
|
return 'Mark as resolved';
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
},
|
2016-07-26 10:47:19 -04:00
|
|
|
isResolved: function () { return CommentsStore.get(this.discussionId, this.noteId).resolved; },
|
|
|
|
resolvedByName: function () { return CommentsStore.get(this.discussionId, this.noteId).user; },
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateTooltip: function () {
|
2016-07-26 10:57:14 -04:00
|
|
|
$(this.$els.button)
|
|
|
|
.tooltip('hide')
|
|
|
|
.tooltip('fixTitle');
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
resolve: function () {
|
2016-07-26 10:57:14 -04:00
|
|
|
if (!this.canResolve) return;
|
2016-07-26 12:49:49 -04:00
|
|
|
|
2016-07-26 08:44:51 -04:00
|
|
|
let promise;
|
2016-07-26 06:56:36 -04:00
|
|
|
this.loading = true;
|
2016-07-26 08:44:51 -04:00
|
|
|
|
|
|
|
if (this.isResolved) {
|
|
|
|
promise = ResolveService
|
|
|
|
.unresolve(this.namespace, this.noteId);
|
|
|
|
} else {
|
|
|
|
promise = ResolveService
|
|
|
|
.resolve(this.namespace, this.noteId);
|
|
|
|
}
|
|
|
|
|
|
|
|
promise.then((response) => {
|
2016-07-26 10:47:19 -04:00
|
|
|
const data = response.data;
|
|
|
|
const user = data ? data.resolved_by : null;
|
2016-07-26 08:44:51 -04:00
|
|
|
this.loading = false;
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
2016-07-26 10:47:19 -04:00
|
|
|
CommentsStore.update(this.discussionId, this.noteId, !this.isResolved, user);
|
2016-07-27 13:34:04 -04:00
|
|
|
|
|
|
|
ResolveService.updateUpdatedHtml(this.discussionId, data);
|
2016-07-26 08:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$nextTick(this.updateTooltip);
|
|
|
|
});
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
compiled: function () {
|
2016-07-26 10:57:14 -04:00
|
|
|
$(this.$els.button).tooltip({
|
|
|
|
container: 'body'
|
|
|
|
});
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
destroyed: function () {
|
2016-07-26 10:47:19 -04:00
|
|
|
CommentsStore.delete(this.discussionId, this.noteId);
|
2016-07-26 06:56:36 -04:00
|
|
|
},
|
|
|
|
created: function () {
|
2016-07-26 10:47:19 -04:00
|
|
|
CommentsStore.create(this.discussionId, this.noteId, this.resolved, this.resolvedBy);
|
2016-07-26 06:56:36 -04:00
|
|
|
}
|
|
|
|
});
|
2016-07-28 10:07:47 -04:00
|
|
|
})(window);
|