text: var slide={init:function(){this.loadData();this.registerEvents()},registerEvents:function(){var n=$("#frm-slide").validate({errorClass:"red",rules:{txtslideName:"required",txtSlideUrl:"required",txtSliderOrder:{required:!0,number:!0,min:1},txtSlideDescription:"required",txtGroupAlias:"required",txtSlideImage:"required"},messages:{txtslideName:{required:"Slide name is required"},txtSlideUrl:{required:"Url is required"},txtSliderOrder:{required:"Order is required",number:"Please enter correct slide order"},txtSlideDescription:{required:"Description is required"},txtGroupAlias:{required:"Alias is required"},txtSlideImage:{required:"Slide image is required"}},showErrors:function(t,i){if(n.submitted){var r="";$.each(i,function(){r+="* "+this.message+"\n"});common.notify(r,"warn");submitted=!1}}});$("#btn-search-slide").on("click",function(){$("#pagination-slide").twbsPagination("destroy");common.config.pageIndex=1;slide.loadData()});$("#txt-slide-keyword").on("keypress",function(n){n.which==13&&($("#pagination-slide").twbsPagination("destroy"),common.config.pageIndex=1,slide.loadData())});$("#btn-create-slide").off("click").on("click",function(){$("#add_edit_slide").modal("show");slide.clearForm();n.resetForm()});$("#btn-slide-image").off("click").on("click",function(){$("#btn-file-slide").val("");$("#btn-file-slide").click()});$("#btn-file-slide").on("change",function(){var n=$(this)[0].files[0],t,i;slide.imageData=n;$("#txt-slide-image").val("/admin-side/images/"+n.name);t=window.URL||window.webkitURL;i=t.createObjectURL(n);$("#blob-slide-img").attr("src",i);$("#blob-slide-img").attr("alt",n.name)});$("#btn-save-slide").off("click").on("click",function(){var i,t,r,f,u;if(n.form()){i=new FormData;i.append("files",slide.imageData);t={};r=$("#hidSlideId").val();r!=""&&(f=$("#hidCreatedDate").val(),t.Id=r,t.CreatedDate=f);t.Name=$("#txt-slide-name").val();t.Url=$("#txt-slide-url").val();t.Image=$("#txt-slide-image").val();t.Text=$("#txt-slide-description").val();t.SortOrder=$("#txt-slide-order").val();t.Status=$("#ck-slide-status").is(":checked")?1:0;t.GroupAlias=$("#txt-slide-alias").val();for(u in t)i.append(u,t[u]);$.ajax({type:"POST",url:"/Admin/Slide/SaveSlide",data:i,processData:!1,contentType:!1,beforeSend:common.runLoadingIndicator(),success:function(){common.notify("Save slide success","success");$("#add_edit_slide").modal("hide");slide.loadData()},error:function(n){console.log(n);common.notify("Error: "+n,"error");common.stopLoadingIndicator()}})}});$("body").on("click",".btnUpdateSlide",function(){var n=$(this).attr("data-id");$("#hidSlideId").val(n);$.ajax({type:"GET",url:"/Admin/Slide/GetSlideDetail",data:{id:n},beforeSend:common.runLoadingIndicator(),success:function(n){$("#add_edit_slide").modal("show");$("#txt-slide-name").val(n.Name);$("#txt-slide-url").val(n.Url);$("#txt-slide-image").val(n.Image);$("#blob-slide-img").attr("src",n.Image);$("#blob-slide-img").attr("alt",n.Name);$("#txt-slide-description").val(n.Text);$("#txt-slide-order").val(n.SortOrder);$("#ck-slide-status").prop("checked",n.Status);$("#txt-slide-alias").val(n.GroupAlias);$("#hidCreatedDate").val(n.CreatedDate);common.stopLoadingIndicator()},error:function(n){console.log(n);common.notify("Error: "+n,"error");common.stopLoadingIndicator()}})});$("body").on("click",".btnDeleteSlide",function(){var n=$(this).data("id");common.confirm("Are you sure to remove this slide?",function(){$.ajax({type:"POST",url:"/Admin/Slide/DeleteSlide",data:{id:n},success:function(){common.notify("Removed success","success");slide.loadData()},error:function(n){console.log(n);common.notify("Error: "+n,"error");common.stopLoadingIndicator()}})})})},imageData:[],loadData:function(){var n="",t=$("#table-slide-template").html();$.ajax({type:"GET",url:"/Admin/Slide/GetAllPaging",data:{page:common.config.pageIndex,keyword:$("#txt-slide-keyword").val(),pageSize:common.config.pageSizeSmall},beforeSend:common.runLoadingIndicator(),dataType:"json",success:function(i){$.each(i.Results,function(i,r){var u={};u.Id=r.Id;u.CreatedDate=common.formatDateTime(r.CreatedDate);u.Name=r.Name;u.Url=r.Url;u.Image=common.formatImageWithSize(r.Image,r.Name,100);u.Description=r.Text;u.Status=common.getStatusLabel(r.Status);n+=Mustache.render(t,u)});$("#lbl-total-slide").text(i.RowCount);$("#tbl-slide-content").html(n);i.RowCount>0&&(slide.configPaging(i.RowCount),slide.bindSlideToTree(i.Results));common.stopLoadingIndicator()},error:function(n){console.log(n);common.notify("Error: "+n,"error");common.stopLoadingIndicator()}})},sliderGlobal:[],bindSlideToTree:function(n){slide.sliderGlobal.length>0&&slide.sliderGlobal.destroySlider();var t="",i=$("#ul-slide-template").html();$.each(n,function(n,r){if(r.Status!==0){var u={};u.Src=r.Image;u.Title="Name: "+r.Name+" - Created date: "+common.formatDate(r.CreatedDate);u.Name=r.Name;t+=Mustache.render(i,u)}});$(".slide-bxslider").html(t);slide.sliderGlobal=$(".slide-bxslider").bxSlider({auto:!0,mode:"fade",captions:!0,slideWidth:800})},configPaging:function(n){var t=Math.ceil(n/common.config.pageSizeSmall);$("#pagination-slide").twbsPagination({totalPages:t,visiblePages:5,onPageClick:function(n,t){t!=common.config.pageIndex&&(common.config.pageIndex=t,slide.loadData())}})},clearForm:function(){$("#txt-slide-name").val("");$("#txt-slide-url").val("");$("#txt-slide-description").val("");$("#txt-slide-order").val(1);$("#txt-slide-image").val("");$("#blob-slide-img").attr("src","/admin-side/images/default-image.png");$("#blob-slide-img").attr("alt","default-image")}};slide.init();