1
|
|
|
var WETU_IMPORTER={init:function(){jQuery("body").hasClass("tour-operator_page_wetu-importer")&&(this.myAccommodationSearch(),this.watchSearch(),this.watchAdvancedSearch(),this.watchImportButton(),this.watchAddToListButton(),this.watchClearButton(),this.watchBannerButton(),this.watchConnectButton())},myAccommodationSearch:function(){jQuery("#wetu-importer-search-form").on("click",".search-toggle",function(t){t.preventDefault();var e="";jQuery(this).hasClass("published")?e="publish":jQuery(this).hasClass("pending")?e="pending":jQuery(this).hasClass("draft")?e="draft":jQuery(this).hasClass("import")&&(e="import"),jQuery(this).parents("#wetu-importer-search-form").find("input.keyword").val(e),jQuery("#wetu-importer-search-form").submit(),jQuery(this).parents("#wetu-importer-search-form").find("input.keyword").val("")})},watchSearch:function(){jQuery("#wetu-importer-search-form").on("submit",function(t){t.preventDefault(),jQuery("#posts-filter tbody").html('<tr><td style="text-align:center;" colspan="4">'+jQuery("#wetu-importer-search-form .ajax-loader").html()+"</td></tr>");var e=jQuery("#wetu-importer-search-form").attr("data-type"),r=[];if(""!=jQuery("#wetu-importer-search-form input.keyword").val()&&r.push(jQuery("#wetu-importer-search-form input.keyword").val()),void 0!=jQuery("#wetu-importer-search-form .advanced-search textarea").val())for(var a=jQuery("#wetu-importer-search-form .advanced-search textarea").val().split("\n"),n=a.length,o=0;o<n;o++)r.push(a[o]);return console.log(r),jQuery.post(lsx_tour_importer_params.ajax_url,{action:"lsx_tour_importer",type:e,keyword:r},function(t){jQuery("#posts-filter tbody").html(t)}),!1})},watchAdvancedSearch:function(){jQuery("#wetu-importer-search-form .advanced-search-toggle").on("click",function(t){t.preventDefault(),jQuery("#wetu-importer-search-form .advanced-search").hasClass("hidden")?(jQuery("#wetu-importer-search-form .advanced-search").fadeIn("fast").removeClass("hidden"),jQuery("#wetu-importer-search-form .normal-search").hide("fast"),jQuery("#wetu-importer-search-form .normal-search input.keyword").val("")):(jQuery("#wetu-importer-search-form .advanced-search").fadeOut("fast").addClass("hidden"),jQuery("#wetu-importer-search-form .advanced-search textarea").val(""),jQuery("#wetu-importer-search-form .normal-search").fadeIn("fast"))})},watchClearButton:function(){jQuery("#posts-filter input.button.clear").on("click",function(t){t.preventDefault(),jQuery("#posts-filter tbody").html(""),jQuery('#wetu-importer-search-form input[type="text"]').val("")})},watchAddToListButton:function(){jQuery("#posts-filter input.button.add").on("click",function(t){t.preventDefault(),jQuery(".import-list-wrapper").fadeIn("fast"),jQuery("#posts-filter tbody tr input:checked").each(function(){jQuery("#import-list tbody").append(jQuery(this).parent().parent())}),jQuery("#import-list tbody tr input:checked").each(function(){jQuery(this).parent().parent().fadeIn("fast")})})},importRow:function(t,e){var r=this,a=e;jQuery.ajax({url:lsx_tour_importer_params.ajax_url,data:t,method:"POST"}).always(function(t,e,r){"none"==jQuery(".completed-list-wrapper").css("display")&&jQuery(".completed-list-wrapper").fadeIn("fast"),jQuery(".completed-list-wrapper ul").append(t),a.fadeOut("fast",function(t){jQuery(this).fadeOut("fast").remove()})}).done(function(t){r.importNext()}).fail(function(t){console.debug(t)})},importNext:function(){var t=jQuery("#import-list tr input.queued:checked:not(.importing):first");if(1==t.length){t.addClass("importing");var e=(jQuery(".post_type").val(),jQuery("#wetu-importer-search-form").attr("data-type")),r=[];"undefined"!=jQuery("#import-list input.team").length&&jQuery("#import-list input.team").each(function(){jQuery(this).attr("checked")&&r.push(jQuery(this).val())});var a=[];"undefined"!=jQuery("#import-list input.content").length&&jQuery("#import-list input.content").each(function(){jQuery(this).attr("checked")&&a.push(jQuery(this).val())});var n=[];"undefined"!=jQuery("#import-list input.accommodation-brand").length&&jQuery("#import-list input.accommodation-brand").each(function(){jQuery(this).attr("checked")&&n.push(jQuery(this).val())});var o=t.attr("data-identifier"),i=t.val(),u=t.parents("tr"),s={action:"lsx_import_items",type:e,wetu_id:o,post_id:i,team_members:r,safari_brands:n,content:a};this.importRow(s,u)}},watchImportButton:function(){var t=this;jQuery('#import-list input[type="submit"]').on("click",function(e){e.preventDefault(),counter=0;var r=!0;jQuery("#import-list tr input:checked:not(.queued)").each(function(){jQuery(this).hide().addClass("queued"),jQuery(this).parents("tr").find(".check-column").append(jQuery("#wetu-importer-search-form .ajax-loader-small").html()),r=!1}),1!=r?t.importNext():alert("Make sure you have some items selected.")})},watchBannerButton:function(){jQuery("#banners-filter input.button.download").on("click",function(t){t.preventDefault(),jQuery("#banners-filter tbody tr input:checked").each(function(){var t=jQuery(this).val(),e=jQuery(this).parents("tr");jQuery(this).hide(),jQuery(this).parents("tr").find(".check-column").append(jQuery("#banners-filter .ajax-loader-small").html()),jQuery.post(lsx_tour_importer_params.ajax_url,{action:"lsx_import_sync_banners",post_id:t},function(t){e.fadeOut("fast",function(t){jQuery(this).fadeOut("fast").remove()})})})})},watchConnectButton:function(){jQuery("#connect-accommodation-filter input.button.connect").on("click",function(t){t.preventDefault(),jQuery("#connect-accommodation-filter tbody tr input:checked").each(function(){var t=jQuery(this).val(),e="connect_accommodation",r=jQuery(this).attr("data-identifier"),a=jQuery(this).parents("tr");jQuery(this).hide(),jQuery(this).parents("tr").find(".check-column").append(jQuery("#connect-accommodation-filter .ajax-loader-small").html()),jQuery.post(lsx_tour_importer_params.ajax_url,{action:"lsx_import_connect_accommodation",post_id:t,type:e,wetu_id:r},function(t){"none"==jQuery(".completed-list-wrapper").css("display")&&jQuery(".completed-list-wrapper").fadeIn("fast"),jQuery(".completed-list-wrapper ul").append(t),a.fadeOut("fast",function(t){jQuery(this).fadeOut("fast").remove()})})})})}};jQuery(document).ready(function(){WETU_IMPORTER.init()}); |