"use strict";var $table=$("#articles"),$remove=$("#remove"),selections=[];function deleteArticle(e){$remove.prop("disabled",!0),$.ajax({url:"/admin/deleteArticles",type:"post",data:"ids="+e,complete:function(){selections=[],$table.bootstrapTable("selectPage",1),$remove.find(".badge").html(""),$remove.find(".badge").hide(),$(".sweet-alert .confirm").removeAttr("disabled"),swal({title:"删除成功！",type:"success",showConfirmButton:!1,timer:1e3})}})}function undoArticle(e){$.ajax({url:"/admin/undoArticle",type:"post",data:"id="+e,complete:function(){$table.bootstrapTable("selectPage",1),$(".sweet-alert .confirm").removeAttr("disabled"),swal({title:"恢复成功！",type:"success",showConfirmButton:!1,timer:1e3})}})}function responseHandler(e){return $.each(e.rows,function(e,t){t.state=-1!==$.inArray(t.UniqueId,selections)}),e}$(function(){$("#side-menu>li:eq(2)").addClass("active").find("ul").addClass("in").find("li:eq(2)").addClass("active"),0==selections.length&&$remove.attr("disabled","disabled"),$table.bootstrapTable({url:"/admin/getArticles",method:"post",pagination:!0,paginationFirstText:'<i class="fa fa-angle-double-left"></i>',paginationPreText:'<i class="fa fa-angle-left"></i>',paginationNextText:'<i class="fa fa-angle-right"></i>',paginationLastText:'<i class="fa fa-angle-double-right"></i>',queryParamsType:"pageIndex",sidePagination:"server",pageList:[10,25,50,100,"All"],search:!0,sortName:"CreateTime",sortOrder:"desc",toolbar:"#toolbar",showRefresh:!0,showColumns:!0,iconsPrefix:"fa",icons:{refresh:"fa-sync",columns:"fa-th-list"},idField:"UniqueId",filterControl:!0,responseHandler:responseHandler,columns:[{field:"state",checkbox:!0,align:"center",valign:"middle"},{field:"CateName",title:"分类",halign:"center",valign:"middle",width:"140px",filterControl:"select",filterData:"url:/admin/getCateFilter",formatter:function(e,t){if(t.CategoryAlias)return'<a href="/blog/'+t.CategoryAlias+'" target="_blank">'+e+"</a>"}},{field:"UniqueId",title:"ID",align:"center",valign:"middle",width:"180px",filterControl:"input",visible:!1},{field:"Title",title:"标题",halign:"center",valign:"middle",formatter:function(e,t){var i=t.IsActive?"":'<span class="label label-danger" title="该文章已删除">已删除</span> ';return i+=t.IsDraft?'<span class="label label-primary" title="这是一篇草稿">草稿</span> ':"","1"===t.Source?i+='<a href="'+t.Url+'" target="_blank"><i class="fa fa-link"></i> '+e+"</a>":t.CategoryAlias&&(i+='<a href="/blog/'+t.CategoryAlias+"/"+t.Alias+'" target="_blank">'+e+"</a>"),i},filterControl:"input"},{field:"CreateTime",title:"发布时间",align:"center",valign:"middle",width:"180px",sortable:!0},{field:"ModifyTime",title:"修改时间",align:"center",valign:"middle",width:"180px",sortable:!0},{field:"ViewCount",title:"浏览次数",align:"center",valign:"middle",width:"120px",sortable:!0,formatter:function(e,t){return 1==t.Source?"-":e}},{field:"operate",title:"操作",align:"center",valign:"middle",width:"120px",events:{"click .remove":function(e,t,i,l){swal({title:"确定要删除该文章吗？",text:"文章标题："+i.Title,html:!0,type:"warning",allowOutsideClick:!0,showCancelButton:!0,cancelButtonText:"取消",confirmButtonColor:"#d9534f",confirmButtonText:"确认删除",closeOnConfirm:!1},function(){$(".sweet-alert .confirm").text("提交中..."),$(".sweet-alert .confirm").attr("disabled","disabled"),deleteArticle(i.UniqueId)})},"click .undo":function(e,t,i,l){swal({title:"确定要恢复该文章吗？",text:"文章标题："+i.Title,html:!0,type:"warning",allowOutsideClick:!0,showCancelButton:!0,cancelButtonText:"取消",confirmButtonText:"确认恢复",closeOnConfirm:!1},function(){$(".sweet-alert .confirm").text("提交中..."),$(".sweet-alert .confirm").attr("disabled","disabled"),undoArticle(i.UniqueId)})}},formatter:function(e,t){return t.IsActive?'<a class="edit btn btn-white" title="编辑" href="/admin/editarticle/'+t.UniqueId+'"><i class="fa fa-pencil-alt"></i></a> <button type="button" class="remove btn btn-white" title="删除"><i class="far fa-trash-alt"></i></button>':'<a class="edit btn btn-white" title="编辑" href="/admin/editarticle/'+t.UniqueId+'"><i class="fa fa-pencil-alt"></i></a> <button type="button" class="undo btn btn-white" title="恢复"><i class="fa fa-undo"></i></button>'}}]}),$table.on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table",function(e,t){var i=$.map($.isArray(t)?t:[t],function(e){if(e.IsActive)return e.UniqueId}),l=-1<$.inArray(e.type,["check","check-all"])?"union":"difference",a=(selections=_[l](selections,i)).length;0<a?($remove.find(".badge").html(a),$remove.find(".badge").show()):($remove.find(".badge").html(""),$remove.find(".badge").hide()),$remove.prop("disabled",!a)}),$remove.click(function(){swal({title:"确定要删除这 "+selections.length+" 篇文章吗？",html:!0,type:"warning",allowOutsideClick:!0,showCancelButton:!0,cancelButtonText:"取消",confirmButtonColor:"#d9534f",confirmButtonText:"确认删除",closeOnConfirm:!1},function(){$(".sweet-alert .confirm").text("提交中..."),$(".sweet-alert .confirm").attr("disabled","disabled"),deleteArticle(selections.join(","))})})});