"use strict";function refreshCate(){$.ajax({url:"/admin/getCategories",type:"Post",success:function(e){$("#Categorylist ul").html(""),$.each(e,function(e,t){t.Link||$("#Categorylist ul").append('<li data-value="'+t._id+'"><a href="#">'+t.CateName+"</a></li>")}),$("#Categorylist ul").append('<li data-value="other"><a href="#">未分类</a></li>'),$("#Categorylist").selectlist("enable"),$("#Categorylist").selectlist("selectByValue","other"),$("#Categorylist li[data-value=other]").addClass("active")}})}$(function(){var a,i;function t(){var e,t=$("#postForm").serialize();return e="markdown"===$("[name=ContentType]:checked").val()?i.value():a.getContent(),t+="&Content="+(e=encodeURIComponent(e))}$("#side-menu>li:eq(2)").addClass("active").find("ul").addClass("in").find("li:eq(0)").addClass("active"),$("#Title").focus(),refreshCate(),$("[name=ContentType]").on("change",function(e){"markdown"===e.currentTarget.value?($("#editor").hide(),$("#mdEditor").show(),i.value(a.getContentTxt())):($("#mdEditor").hide(),$("#editor").show(),a.setContent(i.value()))}),(a=UE.getEditor("editor",{allowDivTransToP:!1,initialFrameHeight:300,initialContent:"请输入文章正文",autoClearinitialContent:!0,textarea:"no-use"})).ready(function(){$("[data-toggle=tooltip]").tooltip({container:"body"})}),i=new SimpleMDE({element:document.querySelector("#mdEditor textarea"),status:!1,renderingConfig:{codeSyntaxHighlighting:!0},toolbar:["bold","italic","strikethrough","heading","code","quote","unordered-list","ordered-list","link","image","table","horizontal-rule","preview"],spellChecker:!1}),"markdown"===editorType?($("#mdRadio").radio("check"),$("#mdEditor").show()):($("#ueRadio").radio("check"),$("#editor").css("display","block")),$(".btn-alias").on("click",function(){var e,t,a,i,o=$("#Title").val();if(o){var l=this;if($(l).addClass("disabled"),e="20151219000008011",t=translateKey,!translateKey)return void swal({title:"生成失败",text:"请先在系统设置中配置百度翻译key",type:"error"});a=(new Date).getTime(),"zh","en",i=md5(e+o+a+t),$.ajax({url:"https://api.fanyi.baidu.com/api/trans/vip/translate",type:"get",dataType:"jsonp",data:{q:o,appid:e,salt:a,from:"zh",to:"en",sign:i},success:function(e){if(e.error_code)swal({title:"生成失败",text:e.error_msg,type:"error"});else{var t=e.trans_result[0].dst.trim().toLowerCase().split(" ").join("-");$("#Alias").val(t).focus(),$("#postForm").formValidation("revalidateField","Alias")}},complete:function(){$(l).removeClass("disabled")}})}}),$("#postForm").on("init.field.fv",function(e,t){var a=t.element.parents(".form-group").find('.form-control-feedback[data-fv-icon-for="'+t.field+'"]');a.on("click.clearing",function(){a.hasClass("fa-remove")&&t.fv.resetField(t.element)})}).formValidation({framework:"bootstrap",icon:{valid:"fa fa-check",invalid:"fa fa-remove",validating:"fa fa-refresh"},err:{container:"tooltip"},fields:{Title:{validators:{notEmpty:{message:"标题不能为空"}}},Alias:{validators:{notEmpty:{message:"Alias不能为空"},remote:{url:"/admin/checkArticleAlias",type:"POST",data:'{"uid":"'+$("#UniqueId").val()+'"}',delay:1e3,message:"Alias不唯一"}}},Summary:{validators:{notEmpty:{message:"摘要不能为空"}}},Url:{validators:{notEmpty:{message:"Url不能为空"},uri:{message:"Url地址不正确"}}}}}).on("err.field.fv",function(e,t){t.fv.disableSubmitButtons(!1)}).on("success.field.fv",function(e,t){t.fv.disableSubmitButtons(!1)}).on("success.form.fv",function(e){e.preventDefault(),$("#Labels").val(JSON.stringify($("#myPillbox").pillbox("items"))),$("#IsDraft").val("False"),swal({title:"确定要发布该文章吗？",text:"other"===$("#CategoryId").val()?"<span style='color:#d9534f;'>注意：当前未选择文章分类</span>":null,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"),$.ajax({url:$("#postForm")[0].action,type:$("#postForm")[0].method,data:t(),success:function(){swal({title:"发布成功！",type:"success",showConfirmButton:!1,timer:2e3},function(){window.location.href="/admin/articlemanage"})},error:function(){swal({title:"发布失败！",type:"error",showConfirmButton:!1,timer:2e3})},complete:function(){$(".sweet-alert .confirm").removeAttr("disabled")}})})}),$("#btnSave").on("click",function(){var e=$(this);$("#Labels").val(JSON.stringify($("#myPillbox").pillbox("items"))),$("#IsDraft").val("True"),e.attr("disabled","disabled"),$.ajax({url:$("#postForm")[0].action,type:$("#postForm")[0].method,data:t(),success:function(){swal({title:"草稿保存成功！",type:"success",showConfirmButton:!1,timer:2e3},function(){window.location.href="/admin/editarticle/"+$("#UniqueId").val()})},error:function(){swal({title:"草稿保存失败！",type:"error",showConfirmButton:!1,timer:2e3})},complete:function(){e.removeAttr("disabled")}})}),$(".selectlist").on("changed.fu.selectlist",function(e,t){$(this).find("li").removeClass("active"),$(this).find("li[data-value="+t.value+"]").addClass("active")})});