(function(d,a){a.SlidesPageController=can.Control.extend({},{sliderId:null,table:null,updating:!1,init:function(e,c){this._super(e,c);this.sliderId=a.Vars.page.slider_id;this.table=this.element.find("table");this.setSlidesSortable()},disableActions:function(){this.table.sortable("disable");this.element.find(".mpsl_delete_slide, .mpsl_duplicate_slide, #create_slide").attr("disabled","disabled")},enableActions:function(){this.table.sortable("enable");this.element.find(".mpsl_delete_slide, .mpsl_duplicate_slide, #create_slide").removeAttr("disabled")},
setSlidesSortable:function(){var a=this;this.table.sortable({items:"tbody>tr",axis:"y",containment:"parent",cursor:"move",handle:".mpsl-slide-sort-handle",tolerance:"pointer",helper:"clone",start:function(c,b){a.updating=!1;a.disableActions()},stop:function(c,b){a.updating||a.enableActions()},update:function(c,b){a.updating=!0;a.updateSlidesOrder();a.enableActions()}})},updateSlidesOrder:function(){var e=this,c=this.table.find("tbody>tr"),b={};d.each(c,function(a,c){b[a]=d(c).attr("data-id")});d.ajax({type:"POST",
url:a.Vars.ajax_url,data:{action:"mpsl_update_slides_order",nonce:a.Vars.nonces.update_slides_order,order:b},success:function(b){a.Functions.showMessage(a.Vars.lang.slides_sorted,a.Functions.MSG_SUCCESS_TYPE)},error:function(b){b=d.parseJSON(b.responseText);b.debug?console.log(b.message):a.Functions.showMessage(b.message,a.Functions.MSG_ERROR_TYPE);e.enableActions()},dataType:"JSON"})},"#create_slide click":function(e){var c=this;this.disableActions();d.ajax({type:"POST",url:a.Vars.ajax_url,data:{action:"mpsl_create_slide",
nonce:a.Vars.nonces.create_slide,slider_id:this.sliderId},success:function(b){b.hasOwnProperty("result")?(a.Functions.showMessage(a.Vars.lang.slide_created,a.Functions.MSG_SUCCESS_TYPE),window.location.href=a.Vars.menu_url+"&view=slide&id="+b.id):(a.Functions.showMessage(a.Vars.lang.slider_created_error,a.Functions.MSG_ERROR_TYPE),c.enableActions())},error:function(b){b=d.parseJSON(b.responseText);b.debug?console.log(b.message):a.Functions.showMessage(b.message,a.Functions.MSG_ERROR_TYPE);c.enableActions()},
dataType:"JSON"})},".mpsl_delete_slide click":function(e){var c=this;this.disableActions();var b=e.attr("data-id");d.ajax({type:"POST",url:a.Vars.ajax_url,data:{action:"mpsl_delete_slide",nonce:a.Vars.nonces.delete_slide,id:b},success:function(c){a.Functions.showMessage(a.Vars.lang.slide_deleted.replace("%d",b),a.Functions.MSG_SUCCESS_TYPE);window.location.reload(!0)},error:function(b){b=d.parseJSON(b.responseText);b.debug?console.log(b.message):a.Functions.showMessage(b.message,a.Functions.MSG_ERROR_TYPE);
c.enableActions()},dataType:"JSON"})},".mpsl_duplicate_slide click":function(e){var c=this;c.disableActions();e=e.attr("data-id");d.ajax({type:"POST",url:a.Vars.ajax_url,data:{action:"mpsl_duplicate_slide",nonce:a.Vars.nonces.duplicate_slide,id:e},success:function(b){b.hasOwnProperty("result")&&(a.Functions.showMessage(a.Vars.lang.slide_duplicated,a.Functions.MSG_SUCCESS_TYPE),window.location.reload(!0));c.enableActions()},error:function(b){b=d.parseJSON(b.responseText);b.debug?console.log(b.message):
a.Functions.showMessage(b.message,a.Functions.MSG_ERROR_TYPE);c.enableActions()},dataType:"JSON"})}})})(jQuery,MPSL);jQuery(function(d){new MPSL.SlidesPageController(".mpsl-wrapper")});
