$(document).ready((function(){var e;(e=$(".wrap-posts-relations")).length&&(Botble.blockUI({target:e,iconOnly:!0,overlayColor:"none"}),$.ajax({url:e.data("target"),type:"GET",success:function(t){t.error?Botble.showError(t.message):(e.html(t.data),Botble.unblockUI(e))},error:function(t){Botble.handleError(t),Botble.unblockUI(e)}})),$(document).on("click",".list-search-data .selectable-item",(function(e){e.preventDefault();var t=$(e.currentTarget),a=t.closest(".form-group").find("input[type=hidden]"),r=!1;"single"===a.data("type")&&(r=!0);var o=a.val().split(",");if($.each(o,(function(e,t){o[e]=parseInt(t)})),$.inArray(t.data("id"),o)<0){a.val()?r?a.val(t.data("id")):a.val(a.val()+","+t.data("id")):a.val(t.data("id"));var l=$(document).find("#selected_post_list_template").html().replace(/__name__/gi,t.data("name")).replace(/__id__/gi,t.data("id")).replace(/__url__/gi,t.data("url")).replace(/__image__/gi,t.data("image")).replace(/__attributes__/gi,t.find("a span").text());t.closest(".form-group").find(".list-selected-posts").removeClass("hidden"),r?t.closest(".form-group").find(".list-selected-posts table tbody").html(l):t.closest(".form-group").find(".list-selected-posts table tbody").append(l)}t.closest(".panel").addClass("hidden")})),$(document).on("click",".textbox-advancesearch",(function(e){var t=$(e.currentTarget),a=t.closest(".box-search-advance").find(".panel");a.removeClass("hidden"),a.addClass("active"),0===a.find(".panel-body").length&&(Botble.blockUI({target:a,iconOnly:!0,overlayColor:"none"}),$.ajax({url:t.data("target"),type:"GET",success:function(e){e.error?Botble.showError(e.message):(a.html(e.data),Botble.unblockUI(a))},error:function(e){Botble.handleError(e),Botble.unblockUI(a)}}))})),$(document).on("keyup",".textbox-advancesearch",(function(e){var t=$(e.currentTarget),a=t.closest(".box-search-advance").find(".panel");t.val().length<3?a.html(""):setTimeout((function(){Botble.blockUI({target:a,iconOnly:!0,overlayColor:"none"}),$.ajax({url:t.data("target")+"?keyword="+t.val(),type:"GET",success:function(e){e.error?Botble.showError(e.message):(a.html(e.data),Botble.unblockUI(a))},error:function(e){Botble.handleError(e),Botble.unblockUI(a)}})}),500)})),$(document).on("click",".btn-trigger-remove-selected-post",(function(e){e.preventDefault();var t=$(e.currentTarget).closest(".form-group").find("input[type=hidden]"),a=t.val().split(",");$.each(a,(function(e,t){t=t.trim(),_.isEmpty(t)||(a[e]=parseInt(t))}));var r=a.indexOf($(e.currentTarget).data("id"));r>-1&&a.splice(r,1),t.val(a.join(",")),$(e.currentTarget).closest("tbody").find("tr").length<2&&$(e.currentTarget).closest(".list-selected-posts").addClass("hidden"),$(e.currentTarget).closest("tr").remove()})),$(document).on("click",".box-search-advance .page-link",(function(e){e.preventDefault();var t=$(e.currentTarget);if(!t.closest(".page-item").hasClass("disabled")&&t.prop("href")){var a=t.closest(".box-search-advance").find(".panel");Botble.blockUI({target:a,iconOnly:!0,overlayColor:"none"}),$.ajax({url:t.prop("href")+"&keyword="+t.val(),type:"GET",success:function(e){e.error?Botble.showError(e.message):(a.html(e.data),Botble.unblockUI(a))},error:function(e){Botble.handleError(e),Botble.unblockUI(a)}})}}))}));