Implement subscribe and unsubscribe
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
h5 =t('exercises.implement.comment.others')
|
||||
.container
|
||||
label
|
||||
input#subscribe type='checkbox' title=t('request_for_comments.subscribe_to_author')
|
||||
input#subscribe type='checkbox' title=t('request_for_comments.subscribe_to_author') data-subscription=Subscription.where(user: current_user, request_for_comment_id: @request_for_comment.id).try(:first).try(:id)
|
||||
= t('request_for_comments.subscribe_to_author')
|
||||
|
||||
#myComment
|
||||
|
@ -313,6 +313,7 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
}
|
||||
|
||||
function subscribeToRFC(subscriptionType, checkbox){
|
||||
checkbox.attr("disabled", true);
|
||||
var jqxhr = $.ajax({
|
||||
data: {
|
||||
subscription: {
|
||||
@ -324,9 +325,33 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
method: 'POST',
|
||||
url: "/subscriptions.json"
|
||||
});
|
||||
jqxhr.fail(function() {
|
||||
jqxhr.done(function(subscription) {
|
||||
checkbox.data('subscription', subscription.id);
|
||||
checkbox.attr("disabled", false);
|
||||
});
|
||||
jqxhr.fail(function(response) {
|
||||
checkbox.prop('checked', false);
|
||||
ajaxError(arguments);
|
||||
checkbox.attr("disabled", false);
|
||||
ajaxError(response);
|
||||
});
|
||||
}
|
||||
|
||||
function unsubscribeFromRFC(checkbox) {
|
||||
checkbox.attr("disabled", true);
|
||||
var subscriptionId = checkbox.data('subscription');
|
||||
var jqxhr = $.ajax({
|
||||
url: '/subscriptions/' + subscriptionId + '/unsubscribe.json'
|
||||
});
|
||||
jqxhr.done(function(response) {
|
||||
checkbox.prop('checked', false);
|
||||
checkbox.data('subscription', null);
|
||||
checkbox.attr("disabled", false);
|
||||
$.flash.success({text: response.message});
|
||||
});
|
||||
jqxhr.fail(function(response) {
|
||||
checkbox.prop('checked', true);
|
||||
checkbox.attr("disabled", false);
|
||||
ajaxError(response);
|
||||
});
|
||||
}
|
||||
|
||||
@ -396,12 +421,13 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
}
|
||||
|
||||
var subscribeCheckbox = commentModal.find('#subscribe');
|
||||
subscribeCheckbox.prop('checked', subscribeCheckbox.data('subscription'));
|
||||
subscribeCheckbox.off('change');
|
||||
subscribeCheckbox.on('change', function() {
|
||||
if (this.checked) {
|
||||
subscribeToRFC('author', $(this));
|
||||
} else {
|
||||
// unsubscribe
|
||||
unsubscribeFromRFC($(this));
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user