Sindbad~EG File Manager
jQuery(document).ready(function($){function recalculateIndexes(container){var key,fieldsName=["tiered_price_percent_quantity","tiered_price_percent_discount","tiered_price_fixed_quantity","tiered_price_fixed_price"];for(key in fieldsName)fieldsName.hasOwnProperty(key)&&jQuery.each(jQuery(container.find('input[name^="'+fieldsName[key]+'"]')),function(index,el){index=jQuery(el).attr("name").replace(/\[\d*\]$/,"["+index+"]");jQuery(el).attr("name",index)})}jQuery(document).on("click","[data-add-new-price-rule]",function(e){e.preventDefault();var newRuleInputs=jQuery(e.target).parent().find("[data-price-rules-input-wrapper]").first().clone();jQuery("<span data-price-rules-container></span>").insertBefore(jQuery(e.target)).append(newRuleInputs).append('<span class="notice-dismiss remove-price-rule" data-remove-price-rule style="vertical-align: middle"></span>').append("<br><br>"),newRuleInputs.children("input").val(""),recalculateIndexes(jQuery(e.target).closest("[data-price-rules-wrapper]"))}),jQuery("body").on("click",".remove-price-rule",function(e){e.preventDefault();var e=jQuery(e.target.parentElement),wrapper=e.parent("[data-price-rules-wrapper]"),containers=wrapper.find("[data-price-rules-container]");containers.length<2?containers.find("input").val(""):(jQuery("[data-price-rules-wrapper] .wc_input_price").trigger("change"),e.remove(),recalculateIndexes(wrapper))});function RoleBasedBlock(){this.$block=null,this.initializedBlocks=[],this.init=function(id){this.variationCanBeChangedAlreadyTriggered=!1,this.id=id,this.$block=jQuery("#"+id),void 0!==this.initializedBlocks[id]&&this.unbindEvents(),this.bindEvents(),this.initializedBlocks[id]=this},this.bindEvents=function(){$("body").on("click","#"+this.id+" .tpt-role-based-role-action--delete",this.removeRole.bind(this)),$("body").on("click","#"+this.id+" .tpt-role-based-role__header",this.toggleRoleView.bind(this)),$("body").on("click","#"+this.id+" .tpt-role-based-adding-form__add-button",this.addRole.bind(this))},this.unbindEvents=function(){$("body").off("click","#"+this.id+" .tpt-role-based-role-action--delete"),$("body").off("click","#"+this.id+" .tpt-role-based-role__header"),$("body").off("click","#"+this.id+" .tpt-role-based-adding-form__add-button")},this.toggleRoleView=function(event){var event=$(event.target);event.hasClass("tpt-role-based-role-action--delete")||((event=event.closest(".tpt-role-based-role")).data("visible")?this.hideRole(event):this.showRole(event))},this.showRole=function($role){$role.find(".tpt-role-based-role__content").stop().slideDown(400),$role.find(".tpt-role-based-role__action-toggle-view").removeClass("tpt-role-based-role__action-toggle-view--open").addClass("tpt-role-based-role__action-toggle-view--close"),$role.data("visible",!0)},this.hideRole=function($role){$role.find(".tpt-role-based-role__content").stop().slideUp(400),$role.find(".tpt-role-based-role__action-toggle-view").removeClass("tpt-role-based-role__action-toggle-view--close").addClass("tpt-role-based-role__action-toggle-view--open"),$role.data("visible",!1)},this.removeRole=function(e){var $roleToRemove;e.preventDefault(),confirm("Are you sure?")&&(e=($roleToRemove=$(e.target).closest(".tpt-role-based-role")).data("role-slug"),this.$block.find(".tpt-role-based-adding-form__role-selector").append('<option value="'+e+'">'+$roleToRemove.data("role-name")+"</option>"),this.$block.find(".tiered_price_rules_roles_to_delete").find("[value="+e+"]").prop("selected",!0),$roleToRemove.slideUp(400,function(){$roleToRemove.remove()}),this.triggerVariationCanBeUpdated())},this.block=function(){this.$block.block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},this.unblock=function(){this.$block.unblock()},this.addRole=function(event){event.preventDefault();var nonce,productId,loop,selectedRole=this.$block.find(".tpt-role-based-adding-form__role-selector").val();selectedRole&&(event=this.$block.data("add-action"),nonce=this.$block.data("add-action-nonce"),productId=this.$block.data("product-id"),loop=this.$block.data("loop"),$.ajax({method:"GET",url:ajaxurl,data:{action:event,nonce:nonce,role:selectedRole,product_id:productId,loop:loop},beforeSend:function(){this.block()}.bind(this)}).done(function(response){response.success&&response.role_row_html?(this.$block.find(".tpt-role-based-roles").append(response.role_row_html),this.$block.find(".tpt-role-based-no-roles").css("display","none"),$.each(this.$block.find(".tpt-role-based-role"),function(i,el){this.hideRole($(el))}.bind(this)),this.showRole(this.$block.find(".tpt-role-based-role").last()),this.$block.find(".tpt-role-based-adding-form__role-selector").find("[value="+selectedRole+"]").remove(),this.$block.find(".tiered_price_rules_roles_to_delete").find("[value="+selectedRole+"]").prop("selected",!1),$(".woocommerce-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200}),this.triggerVariationCanBeUpdated()):response.error_message&&alert(response.error_message),this.unblock()}.bind(this)))},this.triggerVariationCanBeUpdated=function(){this.variationCanBeChangedAlreadyTriggered||(this.$block.closest(".woocommerce_variation").addClass("variation-needs-update"),jQuery("button.cancel-variation-changes, button.save-variation-changes").removeAttr("disabled"),jQuery("#variable_product_options").trigger("woocommerce_variations_defaults_changed"),this.variationCanBeChangedAlreadyTriggered=!0)}}jQuery.each($(".tpt-role-based-block"),function(i,el){(new RoleBasedBlock).init(jQuery(el).attr("id"))}),jQuery(document).on("woocommerce_variations_loaded",function($){jQuery.each(jQuery(".tpt-role-based-block"),function(i,el){el=jQuery(el);"variation"===el.data("product-type")&&(new RoleBasedBlock).init(el.attr("id"))})}),jQuery(".tpt-select-woo").length&&jQuery(".tpt-select-woo").selectWoo(),jQuery(".tiered_pricing_tab_product_advance_options__header").click(function(){jQuery(this).parent(".tiered_pricing_tab_product_advance_options").toggleClass("tiered_pricing_tab_product_advance_options--open")}),jQuery(document).on("change","[data-tiered-price-type-select]",function(){var $container=$(this).closest(".tpt_rules_form");$container.find("[data-tiered-price-type]").css("display","none"),$container.find("[data-tiered-price-type-"+this.value+"]").css("display","block")}),jQuery(document).on("change","[data-tiered-price-pricing-type-selector]",function(e){var $container=jQuery(this).closest(".tpt_regular_pricing_form");$container.find("[data-tiered-price-pricing-type]").css("display","none"),$container.find("[data-tiered-price-pricing-type-"+$(this).val()+"]").css("display","block")})}),jQuery(document).ready(function(){jQuery(document).on("click",".tiered-pricing-pricing-rules-form__add-new",function(e){e.preventDefault();var e=jQuery(this).closest(".tiered-pricing-pricing-rules-form"),rulesFieldsRow=e.find(".tiered-pricing-pricing-rules-form-row").first().clone();rulesFieldsRow.find("input").val(""),e.find(".tiered-pricing-pricing-rules-form__rules").append(rulesFieldsRow)}),jQuery(document).on("click",".tiered-pricing-pricing-rules-form__remove",function(e){e.preventDefault();var e=jQuery(this).closest(".tiered-pricing-pricing-rules-form"),currentRow=jQuery(this).closest(".tiered-pricing-pricing-rules-form-row");e.find(".tiered-pricing-pricing-rules-form__rules").children().length<2?currentRow.find("input").val(""):currentRow.remove(),e.find(".wc_input_price").trigger("change")}),jQuery(document).on("change",".tiered-pricing-rules-form__type select",function(e){e.preventDefault();var e=jQuery(this).val(),form=jQuery(this).closest(".tiered-pricing-rules-form");("fixed"===e?(form.find(".tiered-pricing-rules-form__fixed").show(),form.find(".tiered-pricing-rules-form__percentage")):(form.find(".tiered-pricing-rules-form__percentage").show(),form.find(".tiered-pricing-rules-form__fixed"))).hide()})});
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists