jQuery(document).ready(function($) { /* Private Page PRO functions */ jQuery(".wppcp-private-page-tab").click(function(){ var tab_class = "."+$(this).attr('data-tab-id')+"-tab-content"; $(this).closest('.wppcp-private-page-single').find('.wppcp-private-page-tab-content').hide(); $(this).closest('.wppcp-private-page-single').find(tab_class).show(); $(".wppcp-private-page-tab").removeClass('wppcp-private-page-active-tab'); $(this).addClass('wppcp-private-page-active-tab'); }); $('.wppcp-private-page-disscussion-tab-submit').click(function(){ var post_message_container = $(this).closest('.wppcp-private-page-disscussion-tab-post'); var discussion_container = $(this).closest('.wppcp-private-page-disscussion-tab-content'); post_message_container.find('.wppcp-private-page-disscussion-tab-msg').removeClass('wppcp-message-info-error').removeClass('wppcp-message-info-success').hide(); var post_message = post_message_container.find('.wppcp-private-page-disscussion-tab-editor textarea').val(); if($.trim(post_message) === ''){ post_message_container.find('.wppcp-private-page-disscussion-tab-msg').html(WPPCPPage.Messages.messageEmpty).addClass('wppcp-message-info-error').show(); }else{ $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_add_private_page_post_message', 'verify_nonce': WPPCPPage.nonce, 'message' : post_message, 'type' : 'message', }, function(response){ post_message_container.find('.wppcp-private-page-disscussion-tab-editor textarea').val(""); if(response.status == 'success'){ discussion_container.find('.wppcp-private-page-messages-list').prepend(response.data.messages_html); } },"json" ); } }); $('.wppcp-private-page-admin-disscussion-tab-submit').click(function(){ var post_message_container = $(this).closest('.wppcp-private-page-disscussion-tab-post'); var discussion_container = $(this).closest('.wppcp-private-page-disscussion-tab-content'); var user_id = $(this).attr('data-user-id'); post_message_container.find('.wppcp-private-page-disscussion-tab-msg').removeClass('wppcp-message-info-error').removeClass('wppcp-message-info-success').hide(); var post_message = post_message_container.find('.wppcp-private-page-disscussion-tab-editor textarea').val(); if($.trim(post_message) === ''){ post_message_container.find('.wppcp-private-page-disscussion-tab-msg').html(WPPCPPage.Messages.messageEmpty).addClass('wppcp-message-info-error').show(); }else{ $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_add_private_page_post_message', 'verify_nonce': WPPCPPage.nonce, 'message' : post_message, 'type' : 'message', 'admin_status': 'ACTIVE', 'user_id' : user_id, }, function(response){ post_message_container.find('.wppcp-private-page-disscussion-tab-editor textarea').val(""); if(response.status == 'success'){ discussion_container.find('.wppcp-private-page-messages-list').prepend(response.data.messages_html); } },"json" ); } }); $('.wppcp-private-page-tab-content').on("click",".wppcp-private-page-messages-single-comment-save", function(){ $(this).removeClass('wppcp-error-outline'); var message_container = $(this).closest('.wppcp-private-page-messages-single-block-add-comments') var message = message_container.find('.wppcp-private-page-messages-single-comment').val(); var single_message_block = $(this).closest('.wppcp-private-page-messages-single-block'); if(message == ''){ $(this).closest('.wppcp-private-page-messages-single-block-add-comments').find('.wppcp-private-page-messages-single-comment').addClass('wppcp-error-outline'); }else{ $(this).removeClass('wppcp-error-outline'); var message_id = $(this).attr('data-message-id'); // console.log(group_id+" "+ message_id); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_add_private_page_comment_message', 'verify_nonce': WPPCPPage.nonce, 'message_id' : message_id, 'message' : message, }, function(response){ message_container.find('.wppcp-private-page-messages-single-comment').val(""); if(response.status == 'success'){ var comments_container = single_message_block.find('.wppcp-private-page-messages-single-block-comments'); //console.log(comments_container.html()); var new_comment_block = $("#wppcp-private-page-messages-single-block-comment").clone().removeClass('wppcp-group-messages-single-block-comment-template').prependTo(comments_container); new_comment_block.find('.wppcp-comment-name').html(response.data.current_user_display_name); new_comment_block.find('.wppcp-comment-date').html(response.data.message_date); new_comment_block.find('.wppcp-comment-message').html(response.data.message); new_comment_block.find('.wppcp-private-page-messages-single-comment-avatar').html(''); new_comment_block.find('.wppcp-private-page-messages-single-comment-avatar').html(response.data.avatar); console.log(response.data.avatar); new_comment_block.removeClass('wppcp-private-page-messages-single-block-comment-template'); new_comment_block.attr('data-private-page-id',response.data.group_id); new_comment_block.attr('data-message-id',response.data.message_id); // console.log(response.data); // var group_messages_list = discussion_container.find(".wppcp-group-messages-list"); } },"json" ); } }); $('.wppcp-private-page-tab-content').on("click",".wppcp-private-page-messages-pagination", function(){ var pagination_button = $(this); var data_page = $(this).attr("data-pagination-page"); var discussion_container = $(this).closest('.wppcp-private-page-disscussion-tab-content'); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_load_private_page_paginated_messages', 'verify_nonce': WPPCPPage.nonce, 'data_page' : data_page }, function(response){ if(response.status == 'success'){ if(response.message_pagination_status == '0'){ pagination_button.hide(); }else{ pagination_button.attr('data-pagination-page', response.data_page ); } discussion_container.find('.wppcp-private-page-messages-list').append(response.messages_html); } },"json" ); }); $("body").on("click",".wppcp-private-page-messages-single-comment-delete", function(){ var comment_block = $(this).closest('.wppcp-private-page-messages-single-block-comment'); var comment_id = comment_block.attr('data-message-id'); if(confirm(WPPCPPage.Messages.confirmDelete)){ $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_delete_private_page_comment', 'verify_nonce': WPPCPPage.nonce, 'comment_id': comment_id }, function(response){ if(response.status == 'success'){ comment_block.before('
' + response.msg + '
'); comment_block.remove(); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); }else if(response.status == 'error'){ comment_block.before('
' + response.msg + '
'); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); } },"json" ); } }); $("body").on("click",".wppcp-private-page-messages-single-message-delete", function(){ var message_block = $(this).closest('.wppcp-private-page-messages-single-block'); var message_id = message_block.attr('data-message-id'); if(confirm(WPPCPPage.Messages.confirmDelete)){ $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_delete_private_page_message', 'verify_nonce': WPPCPPage.nonce, 'message_id': message_id }, function(response){ if(response.status == 'success'){ message_block.before('
' + response.msg + '
'); message_block.remove(); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); }else if(response.status == 'error'){ message_block.before('
' + response.msg + '
'); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); } },"json" ); } }); $('.wppcp-private-page-tab-content').on("click",".wppcp-private-page-admin-messages-single-comment-save", function(){ $(this).removeClass('wppcp-error-outline'); var message_container = $(this).closest('.wppcp-private-page-messages-single-block-add-comments') var message = message_container.find('.wppcp-private-page-messages-single-comment').val(); var single_message_block = $(this).closest('.wppcp-private-page-messages-single-block'); var user_id = $(this).attr('data-user-id'); if(message == ''){ $(this).closest('.wppcp-private-page-messages-single-block-add-comments').find('.wppcp-private-page-messages-single-comment').addClass('wppcp-error-outline'); }else{ $(this).removeClass('wppcp-error-outline'); var message_id = $(this).attr('data-message-id'); // console.log(group_id+" "+ message_id); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_add_private_page_comment_message', 'verify_nonce': WPPCPPage.nonce, 'message_id' : message_id, 'message' : message, 'admin_status' : 'ACTIVE', 'user_id' : user_id, }, function(response){ message_container.find('.wppcp-private-page-messages-single-comment').val(""); if(response.status == 'success'){ var comments_container = single_message_block.find('.wppcp-private-page-messages-single-block-comments'); console.log(comments_container.html()); var new_comment_block = $("#wppcp-private-page-messages-single-block-comment").clone().removeClass('wppcp-group-messages-single-block-comment-template').prependTo(comments_container); new_comment_block.find('.wppcp-comment-name').html(response.data.current_user_display_name); new_comment_block.find('.wppcp-comment-date').html(response.data.message_date); new_comment_block.find('.wppcp-comment-message').html(response.data.message); new_comment_block.find('.wppcp-private-page-messages-single-comment-avatar').html(response.data.avatar); new_comment_block.removeClass('wppcp-private-page-messages-single-block-comment-template'); new_comment_block.attr('data-private-page-id',response.data.group_id); new_comment_block.attr('data-message-id',response.data.message_id); console.log(response.data); // var group_messages_list = discussion_container.find(".wppcp-group-messages-list"); } },"json" ); } }); $(".wppcp-private-page-files-add-btn").click(function(){ $(this).closest('.wppcp-private-page-files-create').find('.wppcp-private-page-files-add-form').show(); }); $(".wppcp-private-page-file-upload-form").submit(function(e){ e.preventDefault(); var file_form = $(this); file_form.find(".wppcp-private-page-file-nonce").val(WPPCPPage.nonce); var file_name = file_form.find(".wppcp-private-page-file-name").val(); var file_desc = file_form.find(".wppcp-private-page-file-desc").val(); var file = file_form.find(".wppcp-private-page-file").val(); var msg_container = file_form.find(".wppcp-private-page-files-msg"); msg_container.removeClass('wppcp-message-info-error').removeClass('wppcp-message-info-success'); file_form.find(".wppcp-private-page-file-name").removeClass("wppcp-error-outline"); file_form.find(".wppcp-private-page-file").removeClass("wppcp-error-outline"); var err = 0; var err_msg = ''; if(file_name == ''){ err_msg += "" + WPPCPPage.Messages.fileNameRequired + "
"; file_form.find(".wppcp-private-page-file-name").addClass("wppcp-error-outline"); err++; } if(file == ''){ err_msg += "" + WPPCPPage.Messages.fileRequired + "
"; file_form.find(".wppcp-private-page-file").addClass("wppcp-error-outline"); err++; } if(err != 0){ msg_container.html(err_msg).addClass('wppcp-message-info-error').show(); }else{ msg_container.html("").hide(); var formObj = file_form; var formURL = WPPCPPage.AdminAjax+'?action=wppcp_save_private_page_files'; var formData = new FormData(this); console.log(formData); jQuery.ajax({ url: formURL, type: 'POST', data: formData, mimeType:"multipart/form-data", contentType: false, cache: false, dataType : "json", processData:false, success: function(data, textStatus, jqXHR) { if(data.status == 'success'){ msg_container.html(data.msg).removeClass('wppcp-message-info-error').addClass('wppcp-message-info-success').show(); file_form.closest('.wppcp-private-page-files-tab-content').find('.wppcp-private-page-files-list').prepend(data.files_html); }else if(data.status == 'error'){ msg_container.html(data.msg).removeClass('wppcp-message-info-success').addClass('wppcp-message-info-error').show(); } }, error: function(jqXHR, textStatus, errorThrown) { msg_container.html(err_msg).addClass('wppcp-message-info-error').show(); } }); } }); $("body").on("click",".wppcp-private-page-file-item-view", function(){ var file_item = $(this).closest('.wppcp-private-page-file-item'); var file_item_data = file_item.find('.wppcp-private-page-file-item-data'); if(file_item_data.hasClass('wppcp-private-page-file-item-data-closed')){ file_item_data.removeClass('wppcp-private-page-file-item-data-closed').addClass('wppcp-private-page-file-item-data-open'); }else if(file_item_data.hasClass('wppcp-private-page-file-item-data-open')){ file_item_data.removeClass('wppcp-private-page-file-item-data-open').addClass('wppcp-private-page-file-item-data-closed'); }else{ file_item_data.removeClass('wppcp-private-page-file-item-data-open').addClass('wppcp-private-page-file-item-data-closed'); } }); $("body").on("click",".wppcp-private-page-file-item-delete", function(){ var file_item = $(this).closest('.wppcp-private-page-file-item'); var file_id = file_item.attr('data-file-id'); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_delete_private_page_file', 'verify_nonce': WPPCPPage.nonce, 'file_id' : file_id }, function(response){ if(response.status == 'success'){ file_item.closest('.wppcp-private-page-files-tab-content').find('.wppcp-private-page-files-list-msg').removeClass('wppcp-message-info-error').addClass('wppcp-message-info-success').html(""+response.msg+"
").show(); file_item.remove(); }else if(response.status == 'error'){ file_item.closest('.wppcp-private-page-files-tab-content').find('.wppcp-private-page-files-list-msg').removeClass('wppcp-message-info-success').addClass('wppcp-message-info-error').html(""+response.msg+"
").show(); } },"json" ); }); $('.wppcp-private-page-files-pagination').click(function(){ var pagination_button = $(this); var data_page = $(this).attr("data-pagination-page"); var files_container = $(this).closest('.wppcp-private-page-files-tab-content'); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_load_private_page_paginated_files', 'verify_nonce': WPPCPPage.nonce, 'data_page' : data_page }, function(response){ if(response.status == 'success'){ if(response.file_pagination_status == '0'){ pagination_button.hide(); }else{ pagination_button.attr('data-pagination-page', response.data_page ); } files_container.find('.wppcp-private-page-files-list').append(response.files_html); } },"json" ); }); // Admin functions of private page $("body").on("click",".wppcp-private-page-admin-messages-single-message-delete", function(){ var message_block = $(this).closest('.wppcp-private-page-messages-single-block'); var message_id = message_block.attr('data-message-id'); var user_id = $(this).attr('data-user-id'); if(confirm(WPPCPPage.Messages.confirmDelete)){ $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_delete_private_page_message', 'verify_nonce': WPPCPPage.nonce, 'message_id': message_id, 'user_id' : user_id }, function(response){ if(response.status == 'success'){ message_block.before('
' + response.msg + '
'); message_block.remove(); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); }else if(response.status == 'error'){ message_block.before('
' + response.msg + '
'); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); } },"json" ); } }); $("body").on("click",".wppcp-private-page-admin-messages-single-comment-delete", function(){ var comment_block = $(this).closest('.wppcp-private-page-messages-single-block-comment'); var comment_id = comment_block.attr('data-message-id'); var user_id = $(this).attr('data-user-id'); if(confirm(WPPCPPage.Messages.confirmDelete)){ $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_delete_private_page_comment', 'verify_nonce': WPPCPPage.nonce, 'comment_id': comment_id, 'user_id' : user_id }, function(response){ if(response.status == 'success'){ comment_block.before('
' + response.msg + '
'); comment_block.remove(); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); }else if(response.status == 'error'){ comment_block.before('
' + response.msg + '
'); setTimeout(function(){ $('#wppcp-private-page-disscussion-delete-error').remove(); }, 3000); } },"json" ); } }); $('.wppcp-private-page-tab-content').on("click",".wppcp-private-page-admin-messages-pagination", function(){ var pagination_button = $(this); var data_page = $(this).attr("data-pagination-page"); var discussion_container = $(this).closest('.wppcp-private-page-disscussion-tab-content'); var user_id = $(this).attr('data-user-id'); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_load_private_page_paginated_messages', 'verify_nonce': WPPCPPage.nonce, 'data_page' : data_page, 'user_id' : user_id }, function(response){ if(response.status == 'success'){ if(response.message_pagination_status == '0'){ pagination_button.hide(); }else{ pagination_button.attr('data-pagination-page', response.data_page ); } discussion_container.find('.wppcp-private-page-messages-list').append(response.messages_html); } },"json" ); }); $(".wppcp-private-page-admin-file-upload-form").submit(function(e){ e.preventDefault(); var file_form = $(this); file_form.find(".wppcp-private-page-file-nonce").val(WPPCPPage.nonce); var file_name = file_form.find(".wppcp-private-page-file-name").val(); var file_desc = file_form.find(".wppcp-private-page-file-desc").val(); var file = file_form.find(".wppcp-private-page-file").val(); var user_id = $(this).attr('data-user-id'); var msg_container = file_form.find(".wppcp-private-page-files-msg"); msg_container.removeClass('wppcp-message-info-error').removeClass('wppcp-message-info-success'); file_form.find(".wppcp-private-page-file-name").removeClass("wppcp-error-outline"); file_form.find(".wppcp-private-page-file").removeClass("wppcp-error-outline"); var err = 0; var err_msg = ''; if(file_name == ''){ err_msg += "" + WPPCPPage.Messages.fileNameRequired + "
"; file_form.find(".wppcp-private-page-file-name").addClass("wppcp-error-outline"); err++; } if(file == ''){ err_msg += "" + WPPCPPage.Messages.fileRequired + "
"; file_form.find(".wppcp-private-page-file").addClass("wppcp-error-outline"); err++; } if(err != 0){ msg_container.html(err_msg).addClass('wppcp-message-info-error').show(); }else{ msg_container.html("").hide(); var formObj = file_form; var formURL = WPPCPPage.AdminAjax+'?action=wppcp_save_private_page_files'; var formData = new FormData(this); formData.append("user_id", user_id); formData.append("admin_status", "ACTIVE"); console.log(formData); jQuery.ajax({ url: formURL, type: 'POST', data: formData, mimeType:"multipart/form-data", contentType: false, cache: false, dataType : "json", processData:false, success: function(data, textStatus, jqXHR) { if(data.status == 'success'){ msg_container.html(data.msg).removeClass('wppcp-message-info-error').addClass('wppcp-message-info-success').show(); file_form.closest('.wppcp-private-page-files-tab-content').find('.wppcp-private-page-files-list').prepend(data.files_html); }else if(data.status == 'error'){ msg_container.html(data.msg).removeClass('wppcp-message-info-success').addClass('wppcp-message-info-error').show(); } }, error: function(jqXHR, textStatus, errorThrown) { msg_container.html(err_msg).addClass('wppcp-message-info-error').show(); } }); } }); $("body").on("click",".wppcp-private-page-admin-file-item-delete", function(){ var file_item = $(this).closest('.wppcp-private-page-file-item'); var file_id = file_item.attr('data-file-id'); var user_id = $(this).attr('data-user-id'); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_delete_private_page_file', 'verify_nonce': WPPCPPage.nonce, 'file_id' : file_id, 'user_id' : user_id }, function(response){ if(response.status == 'success'){ file_item.closest('.wppcp-private-page-files-tab-content').find('.wppcp-private-page-files-list-msg').removeClass('wppcp-message-info-error').addClass('wppcp-message-info-success').html(""+response.msg+"
").show(); file_item.remove(); }else if(response.status == 'error'){ file_item.closest('.wppcp-private-page-files-tab-content').find('.wppcp-private-page-files-list-msg').removeClass('wppcp-message-info-success').addClass('wppcp-message-info-error').html(""+response.msg+"
").show(); } },"json" ); }); $('.wppcp-private-page-admin-files-pagination').click(function(){ var pagination_button = $(this); var data_page = $(this).attr("data-pagination-page"); var files_container = $(this).closest('.wppcp-private-page-files-tab-content'); var user_id = $(this).attr('data-user-id'); $.post( WPPCPPage.AdminAjax, { 'action': 'wppcp_load_private_page_paginated_files', 'verify_nonce': WPPCPPage.nonce, 'data_page' : data_page, 'user_id' : user_id }, function(response){ if(response.status == 'success'){ if(response.file_pagination_status == '0'){ pagination_button.hide(); }else{ pagination_button.attr('data-pagination-page', response.data_page ); } files_container.find('.wppcp-private-page-files-list').append(response.files_html); } },"json" ); }); var url = window.location.href; if(url.indexOf('wppcp_pp_file_id') != -1){ jQuery('.wppcp-private-page-files-tab').trigger('click'); } if(url.indexOf('wppcp_pp_message_id') != -1){ jQuery('.wppcp-private-page-disscussion-tab').trigger('click'); } if(url.indexOf('wppcp_pp_content') != -1){ jQuery('.wppcp-private-page-content-tab').trigger('click'); } });