var Widgets=new Class({Extends:DragDropPlus,initialize:function(b,c,a){this.parent(b,c,a);this.drags.each(function(d){if(d.getProperty("ishtml")){$E(".content-html",d).setHTML($E(".content-textarea",d).getValue())}})},inject:function(a,b){this.addWidget(this.curEl,a,b?b:this.theme)},newWidget:function(a){this.curDrop=a;this.curdialog=new parent.Dialog(top.SHOPADMINDIR+"index.php?ctl=content/pages&act=widgets",{width:800,height:500,title:"增加页面版块",modal:true,resizeable:true,onShow:function(b){this.dialog_body.id="dialogContent"}})},htmlarea:function(a){},ghostDrop:function(a,c){var a=a;var c=c;this.drag_operate_box.setStyle("visibility","hidden").store("lock",true);$("tempDropBox")?$("tempDropBox").empty().remove():"";parent._showWidgets_tip("在您需要放入版块的蓝色区域点击鼠标左键即可添加版块。点击鼠标右键则取消添加版块操作。");this.tempDropBox=new Element("div",{id:"tempDropBox"}).inject(document.body);try{this.drops.each(function(h,e){if(!h){return}var i=this;var g=h.getCis();if(g.height>5&&g.width>5){g.height-=5;g.width-=5}var d=new Element("div",{"class":"widgets_drop_ghost",styles:$merge(g,{opacity:0.3}),text:"["+(e+1)+"]",title:"点击此处，将["+a.name+"]版块添加到此区域"}).addEvents({mouseover:function(){this.addClass("widgets_drop_ghost_on")},mouseleave:function(){this.removeClass("widgets_drop_ghost_on")},click:function(){i.tempDropBox.empty();i.addWidget(h,a,c);i.drag_operate_box.store("lock",false);parent._hideWidgets_tip()}}).inject(i.tempDropBox)},this)}catch(b){alert(JSON.encode(b))}document.body.addEvent("contextmenu",function(d){d.stop();$("tempDropBox")?$("tempDropBox").empty().remove():"";parent._hideWidgets_tip();this.drag_operate_box.store("lock",false);document.body.removeEvent("contextmenu",arguments.callee)}.bind(this))},copyWidgets:function(a){},addWidget:function(a,b,d){var c={modal:true,title:"增加版块:["+b.label+"]",ajaksable:false};this.curdialog=new top.Dialog(top.SHOPADMINDIR+"index.php?ctl=system/template&act=doAddWidgets&p[0]="+b.name+"&p[1]="+d,c);this.curDrop=a},editWidget:function(a){var b={modal:true,title:"修改版块:["+a.label+"]",ajaksable:false};this.curWidget=$(a);if(a.get("ishtml")){return this.curdialog=new top.Dialog(top.SHOPADMINDIR+"index.php?ctl=content/pages&act=editHtml",$merge(b,{ajaksable:true,ajaxoptions:{method:"post",data:"htmls="+encodeURIComponent($E(".content-html",a).getHTML().clean().trim())},title:"编辑HTML"}))}this.curdialog=new top.Dialog(top.SHOPADMINDIR+"index.php?ctl=system/template&act=editWidgets&p[0]="+a.get("widgets_id")+"&p[1]="+a.get("widgets_theme"),b)},saveWidgets:function(){var c=[];var b=this.drops;var a={};b.each(function(g,d){var e=$ES(".shopWidgets_box",g);e.each(function(i){c.push(("widgets[{widgetsId}]={baseFile}:{baseSlot}:{baseId}").substitute({widgetsId:i.get("widgets_id"),baseFile:this.bf,baseSlot:this.bs,baseId:this.bi}));if(i.get("ishtml")){var h=$E(".content-html",i);c.push(("html[{widgetsId}]={htmls}").substitute({widgetsId:i.get("widgets_id"),htmls:encodeURIComponent(h.getHTML())}))}},{mce:this.mce,bf:g.get("base_file"),bs:g.get("base_slot"),bi:g.get("base_id")});a[g.get("base_file")]=1}.bind(this));for(f in a){c.push(("files[]={file}").substitute({file:f}))}new XHR({method:"post",onRequest:function(){top.MODALPANEL.show();top.$("loadMask").amongTo(top.window).show()},onSuccess:function(d){try{var d=Json.evaluate(d);for(dom in d){if($chk($(dom))&&$chk(d[dom])){$(dom).setProperty("widgets_id",d[dom])}}top.MessageBox.success("保存成功!")}catch(g){top.MessageBox.error("保存失败"+g.message)}finally{top.MODALPANEL.hide();top.$("loadMask").hide()}}}).send(top.SHOPADMINDIR+"index.php?ctl=system/template&act=widgetsSave",c.join("&"))}});window.addEvent("domready",function(){if(parent.$("loadMask")){parent.$("loadMask").hide().getElement(".loading_msg").set("text","正在加载...")}if(parent.MODALPANEL){parent.MODALPANEL.hide()}this.shopWidgets=new Widgets(".shopWidgets_box",".shopWidgets_panel",{onEdit:function(b,a){shopWidgets.editWidget(b)},onDelete:function(b){if(!confirm("确定删除此版块?")){return}var c=this.drag_operate_box;var d=this;c.setStyle("visibility","hidden").store("lock",true);var a=b.getParent();b.effect("opacity").start(0).chain(function(){b.remove();c.store("lock",false);d.checkEmptyDropPanel(a)})}})});