Add controller logic for subscription#create
This commit is contained in:
@ -1,20 +0,0 @@
|
||||
class SubscriptionController < ApplicationController
|
||||
|
||||
def authorize!
|
||||
authorize(@submission || @submissions)
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def set_subscription
|
||||
@subscription = Subscription.find(params[:id])
|
||||
authorize!
|
||||
end
|
||||
private :set_subscription
|
||||
|
||||
def subscription_params
|
||||
current_user_id = current_user.try(:id)
|
||||
current_user_class_name = current_user.try(:class).try(:name)
|
||||
params[:subscription].permit(:request_for_comment, :type).merge(user_id: current_user_id, user_type: current_user_class_name)
|
||||
end
|
||||
private :subscription_params
|
||||
end
|
33
app/controllers/subscriptions_controller.rb
Normal file
33
app/controllers/subscriptions_controller.rb
Normal file
@ -0,0 +1,33 @@
|
||||
class SubscriptionsController < ApplicationController
|
||||
|
||||
def authorize!
|
||||
authorize(@subscription || @subscriptions)
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
# POST /subscriptions.json
|
||||
def create
|
||||
@subscription = Subscription.new(subscription_params)
|
||||
respond_to do |format|
|
||||
if @subscription.save
|
||||
format.json { render json: @subscription, status: :created }
|
||||
else
|
||||
format.json { render json: @subscription.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
authorize!
|
||||
end
|
||||
|
||||
def set_subscription
|
||||
@subscription = Subscription.find(params[:id])
|
||||
authorize!
|
||||
end
|
||||
private :set_subscription
|
||||
|
||||
def subscription_params
|
||||
current_user_id = current_user.try(:id)
|
||||
current_user_class_name = current_user.try(:class).try(:name)
|
||||
params[:subscription].permit(:request_for_comments, :subscription_type).merge(user_id: current_user_id, user_type: current_user_class_name)
|
||||
end
|
||||
private :subscription_params
|
||||
end
|
@ -312,6 +312,24 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
jqxhr.fail(ajaxError);
|
||||
}
|
||||
|
||||
function subscribeToRFC(subscriptionType, checkbox){
|
||||
var jqxhr = $.ajax({
|
||||
data: {
|
||||
subscription: {
|
||||
request_for_comments_id: $('h4#exercise_caption').data('rfc-id'),
|
||||
subscription_type: subscriptionType
|
||||
}
|
||||
},
|
||||
dataType: 'json',
|
||||
method: 'POST',
|
||||
url: "/subscriptions.json"
|
||||
});
|
||||
jqxhr.fail(function() {
|
||||
checkbox.prop('checked', false);
|
||||
ajaxError(arguments);
|
||||
});
|
||||
}
|
||||
|
||||
function handleSidebarClick(e) {
|
||||
var target = e.domEvent.target;
|
||||
var editor = e.editor;
|
||||
@ -377,6 +395,16 @@ also, all settings from the rails model needed for the editor configuration in t
|
||||
otherComments.hide();
|
||||
}
|
||||
|
||||
var subscribeCheckbox = commentModal.find('#subscribe');
|
||||
subscribeCheckbox.off('change');
|
||||
subscribeCheckbox.on('change', function() {
|
||||
if (this.checked) {
|
||||
subscribeToRFC('author', $(this));
|
||||
} else {
|
||||
// unsubscribe
|
||||
}
|
||||
});
|
||||
|
||||
var addCommentButton = commentModal.find('#addCommentButton');
|
||||
addCommentButton.off('click');
|
||||
addCommentButton.on('click', function(){
|
||||
|
Reference in New Issue
Block a user