Completed
Push — master ( a84d89...a9842c )
by Fernando
02:35
created

assets/js/wetu-importer.min.js   B

Complexity

Total Complexity 51
Complexity/F 1.28

Size

Lines of Code 1
Function Count 40

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 51
dl 0
loc 1
rs 8.3206
c 1
b 0
f 0
cc 0
nc 1
mnd 3
bc 41
fnc 40
bpm 1.025
cpm 1.275
noi 11

How to fix   Complexity   

Complexity

Complex classes like assets/js/wetu-importer.min.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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(),this.watchCheckBoxes(),this.watchTourUpdate())},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(lsx_tour_importer_params.ajax_url),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;a.find("td.post-title strong").css("color","#555"),jQuery.ajax({url:lsx_tour_importer_params.ajax_url,data:t,method:"POST"}).always(function(t,e,a){r.importNext()}).done(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()})}).fail(function(t){a.find("td.post-title strong").css("color","red")})},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=jQuery(this).attr("data-identifier"),r=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:"connect_accommodation",wetu_id:e},function(t){"none"==jQuery(".completed-list-wrapper").css("display")&&jQuery(".completed-list-wrapper").fadeIn("fast"),jQuery(".completed-list-wrapper ul").append(t),r.fadeOut("fast",function(t){jQuery(this).fadeOut("fast").remove()})})})})},watchCheckBoxes:function(){jQuery('form#import-list .settings-all input[type="checkbox"]').on("change",function(t){var e=jQuery(this);"all"===e.val()&&e.parents("form").find('.settings-all input[type="checkbox"]:not([value="all"])').each(function(){"checked"===e.attr("checked")?jQuery(this).attr("checked","checked"):jQuery(this).removeAttr("checked")})});var t=null;jQuery('#the-list input[type="checkbox"], #import-list tbody input[type="checkbox"]').on("click",function(r){if(!t)return void(t=this);if(e.shiftKey){var a=$chkboxes.index(this),n=$chkboxes.index(t);$chkboxes.slice(Math.min(a,n),Math.max(a,n)+1).prop("checked",t.checked)}t=this})},watchTourUpdate:function(){jQuery(".wetu-status.tour-wetu-status h3 a").on("click",function(t){t.preventDefault(),jQuery(this).parents(".wetu-status.tour-wetu-status").find("form").submit()})}};jQuery(document).ready(function(){WETU_IMPORTER.init()});