summaryrefslogtreecommitdiff
blob: 0e9999e46e9effd7bc84b1fecea221ab307aa4e1 (plain)
1
function WMP_EDIT_CATEGORIES(){var e=this;this.type="wmp_editcategories",this.form,this.DOMDoc,this.changingStatus=!1,this.init=function(){WMPJSInterface=window.parent.WMPJSInterface,this.form=this.DOMDoc.getElementById(this.type+"_form"),null!=this.form&&(this.initCategories(),this.initListActions())},this.initListActions=function(){jQuery("ul.categories",this.form).sortable({update:function(t,a){e.changeOrder()}}),this.update()},this.initCategories=function(){jQuery("li",this.form).on("click",function(){var t=confirm("Are you sure you want to change the status for this category?");if(t){var a,r=jQuery(".status",this),i=jQuery(this).attr("data-category-id");a=0==r.hasClass("active")?"active":"inactive",0==e.changingStatus&&(WMPJSInterface.Preloader.start(),jQuery.post(ajaxurl,{action:"wmp_content_status",id:i,status:a,type:"category"},function(t){e.changingStatus=!1,WMPJSInterface.Preloader.remove(100);var t=Boolean(Number(String(t)));if(1==t){r.addClass(a),r.removeClass("active"==a?"inactive":"active"),r.text(a);var i="The status of this category has been changed.";WMPJSInterface.Loader.display({message:i});var s=jQuery("li span.active",e.form).length;s>0?jQuery("#"+e.type+"_warning",e.DOMDoc).hide():jQuery("#"+e.type+"_warning",e.DOMDoc).show()}else{var i="There was an error. Please reload the page and try again in few seconds or contact the plugin administrator if the problem persists.";WMPJSInterface.Loader.display({message:i})}}))}}),jQuery("#"+e.type+"_warning a.close-x",this.form).on("click",function(){jQuery("#"+e.type+"_warning",e.DOMDoc).hide()})},this.changeOrder=function(){if(1!=e.changingStatus){var t="";jQuery("ul.categories li",e.form).each(function(e,a){t+=jQuery(this).attr("data-category-id")+",";var r=e+1;jQuery(this).attr("data-order",r)}),WMPJSInterface.Preloader.start(),e.changingStatus=!0,jQuery.post(ajaxurl,{action:"wmp_content_order",type:"categories",ids:t},function(t){WMPJSInterface.Preloader.remove(100),e.changingStatus=!1;var t=Boolean(Number(String(t)));if(1==t){var a="The order of the categories has been successfully changed.";WMPJSInterface.Loader.display({message:a})}else{var a="There was an error. Please reload the page and try again in few seconds or contact the plugin administrator if the problem persists.";WMPJSInterface.Loader.display({message:a})}})}},this.update=function(){var t=jQuery("ul.categories li",this.form).length;t>1?jQuery("ul.categories",e.form).sortable("enable"):jQuery("ul.categories",e.form).sortable("disable")}}