function moderationModalAttachEvents(type){$('[id^="moderation-'+type+'-show"]').off('click.moderation)').on('click.moderation',function(e){$('#moderation-'+type+'-form [id^="moderation-'+type+'-error"]').addClass('hidden').text('');$('#moderation-contenttype').html($(this).data('contenttype')+' ');$('#id_'+type+'_contenttype').val($(this).data('contenttype'));$('#id_'+type+'_identifier').val($(this).data('identifier'));if(typeof $(this).data('reason')!=='undefined')$('#id_'+type+'_reason').val($(this).data('reason'));else $('#id_'+type+'_reason').val($('#id_'+type+'_reason option:first').val());$('#id_'+type+'_comments').val('');$('#moderation-'+type+'-body').removeClass('hidden');$('#moderation-'+type+'-thanks').addClass('hidden');$('#moderation-'+type+'-modal').modal('show');});$('#moderation-'+type+'-submit').off('click.moderation').on('click.moderation',function(e){$('#moderation-'+type+'-submit').prop('disabled',true);$.ajax({type:'POST',url:'/api/moderation/request/create/',headers:{'X-CSRFToken':Cookies.get('csrftoken')},data:JSON.stringify({'contenttype':$('#id_'+type+'_contenttype').val(),'identifier':$('#id_'+type+'_identifier').val(),'reason':$('#id_'+type+'_reason').val(),'comments':$('#id_'+type+'_comments').val()}),contentType:'application/json'}).success(function(result){$('#moderation-'+type+'-form [id^="moderation-'+type+'-error"]').addClass('hidden').text('');if(result.success){$('#moderation-'+type+'-body').addClass('hidden');$('#moderation-'+type+'-thanks').removeClass('hidden');}else{toastr.error('Please resolve errors then resubmit');for(i=0;i<result.errors.length;i++){if(result.errors[i][0]=='__all__')$('#moderation-'+type+'-error').removeClass('hidden').text(result.errors[i][1]);else if(result.errors[i][0]=='contenttype'||result.errors[i][0]=='identifier')$('#moderation-'+type+'-error').removeClass('hidden').text('Invalid form structure detected. Please refresh the page and repeat the action. If the issue persists please raise a support ticket.');else $('#moderation-'+type+'-error-'+result.errors[i][0]).removeClass('hidden').text(result.errors[i][1]);}}}).fail(function(){toastr.error('Please refresh the page and repeat the action. If the issue persists please raise a support ticket.','Unexpected Error Occurred',{timeOut:2500});}).always(function(){$('#moderation-'+type+'-submit').prop('disabled',false);});});}