var Tags_opt=new Class({initialize:function(a,b){this.finderTag=a.finderTag;if(!this.finderTag){return}this.tagEvent();this.sigId=b;this.applyObj=$E(".btn-apply",$("finder-tag"));this.createObj=$E(".btn-create-tag",$("finder-tag"));this.manage=$E(".btn-tag-manage",$("finder-tag"));this.taginput=$E(".tag-editor-value",$("finder-tag"));this.tagmain=$E(".tag-editor-group",$("finder-tag"));this.url=a.url;this.bindEvent()},filterUrl:function(a){if(!this.url){return"index.php"+location.search.split("&")[0]+"&act="+a}return this.url+"&act="+a},bindEvent:function(){if(this.taginput){this.taginput.addEvent("click",function(a){a.stopPropagation()})}if(this.applyObj){this.applyObj.addEvent("click",function(a){this.finderTag.fireEvent("apply")}.bind(this))}if(this.createObj){this.createObj.addEvent("click",function(a){this.newDialog()}.bind(this))}},bindTagEvent:function(a){a.addEvent("click",function(c){c.stop();if(!this.hasClass("selected_all")){var b=$E("ul[class=theme_tag] li[class=selected_all]").clone();b.getFirst().replaces(this.getFirst());this.removeClass("selected_none");this.removeClass("selected_part");this.addClass("selected_all")}else{var b=$E("ul[class=theme_tag] li[class=selected_none]").clone();b.getFirst().replaces(this.getFirst());this.removeClass("selected_all");this.addClass("selected_none")}})},newDialog:function(){var a=this;new Dialog(this.finderTag.getElement(".dialogTag").clone(),{width:350,height:200,title:"新建标签",onLoad:function(){this.dialog.getElement(".dialogTag").setStyle("display","block");this.dialog.getElement(".btnSmt").addEvent("click",function(){if($type(a.finderTag.fireEvent)!="function"){this.close();return}a.finderTag.fireEvent("createTag",this)}.bind(this));this.dialog.getElement(".btnCancel").addEvent("click",function(){this.close()}.bind(this));this.dialog.getElement(".tag-editor-value").addEvent("keydown",function(b){if(b.code==13){this.getElement(".btnSmt").fireEvent("click")}}.bind(this.dialog))}})},selectedRow:function(){if($("headBar")&&$("headBar").getChildren("form")[0]&&$("headBar").getChildren("form")[0].retrieve("rowselected")){this.key=$H($("headBar").getChildren("form")[0].retrieve("rowselected")).getKeys()[0];this.value=$H($("headBar").getChildren("form")[0].retrieve("rowselected")).getValues()[0]}if(this.value&&this.value.length<1){this.value=null;this.key=null}},filterParam:function(){var b=new String;var a=/\w+(?=\/)/.exec(location.search);if(this.sigId){b="&"+a+"_id[]="+this.sigId}else{if(this.value&&this.value.contains("_ALL_")){return b="&"+this.key+"=_ALL_"}if(this.value){this.value.each(function(c){b+="&"+this.key+"="+c}.bind(this))}}return b},toQueryString:function(){var d=this.finderTag.getElement("ul[class=tag-editor-group]").getElements("li");var c=[],b=[];d.each(function(e){if(e.hasClass("selected_all")){c.include(e)}if(e.hasClass("selected_part")){b.include(e)}});var a="_SET_TAGS_=";c.each(function(f){var e=f.get("text").trim();a+="_S_ALL"+e+" "});b.each(function(f){var e=f.get("text").trim();a+="_S_PAR"+e+" "});return a},tagEvent:function(){var a=this;this.finderTag.addEvents({show:function(){a.tagmain.setStyle("overflow","hidden");this.setStyle("overflow","hidden");a.selectedRow();var c=a.filterParam();thistag=this;var b=a.filterUrl("tagList");if(!c.length){c=null}new Request({method:"post",url:b,onSuccess:function(f){var h=JSON.decode(f);if(!h){return}thistag.getElement("ul[class=tag-editor-group]").empty();if(h.length>10){a.tagmain.setStyles({"overflow-y":"auto",height:"200px"})}for(var g=0;g<h.length;g++){var e=h[g]["status"];var d=$E("ul[class=theme_tag] li[class=selected_"+e+"]").clone();d.appendText(h[g]["tag_name"]);d.inject(thistag.getElement("ul[class=tag-editor-group]"))}var j=thistag.getElement("ul[class=tag-editor-group]").getElements("li");a.bindTagEvent(j)}}).send(c)},apply:function(d){var c=a.filterUrl("setTag");a.selectedRow();if(!a.url&&!a.sigId&&!d){return}if(!a.value&&a.url){MessageBox.error("请选择要操作的项");return}var b=a.toQueryString();if(d){a.sigId=d}var e=a.filterParam();b+=e;W.page(c,{update:"messagebox",method:"post",data:b,onComplete:function(){if(a.url){for(var g in finderGroup){finderGroup[g].refresh()}}$("loadMask").hide()}})},createTag:function(c){var e=c.dialog.getElement(".tag-editor-value").get("value").trim();if(e.contains(" ")||e.length==0){MessageBox.error("标签名不能为空且其中不能有空格符号!");return}var d=this.getElement("ul[class=tag-editor-group]").getElements("li");if(d.some(function(f){return f.get("text").trim()==e})){MessageBox.error("此标签已存在");return}var b=a.filterUrl("newTag");thistag=this;W.page(b,{update:"messagebox",method:"post",data:"tag_name="+e,onComplete:function(g){c.close();a.selectedRow();var f=(a.sigId||a.value&&a.value.length>0)?$E("ul[class=theme_tag] li[class=selected_all]").clone():$E("ul[class=theme_tag] li[class=selected_none]").clone();f.appendText(e);f.inject(thistag.getElement("ul[class=tag-editor-group]"));a.bindTagEvent(f);if(a.value&&a.value.length||a.sigId){a.finderTag.fireEvent("apply")}}})}})}});