MWF.xApplication.ForumDocument=MWF.xApplication.ForumDocument||{};MWF.require("MWF.widget.O2Identity",null,false);MWF.xDesktop.requireApp("Template","MPopupForm",null,false);MWF.xApplication.ForumDocument.Vote=new Class({Extends:MWF.widget.Common,Implements:[Options,Events],options:{style:"default",isNew:false,isEdited:true},initialize:function(t,e,i,o){this.setOptions(i);this.container=t;this.app=e;this.lp=e.lp;this.actions=e.restActions||e.action;this.data=o;this.userName=layout.user&&layout.user.distinguishedName?layout.user.distinguishedName:layout.desktop.session.user.distinguishedName;this.path="/x_component_ForumDocument/$Vote/";this.cssPath="/x_component_ForumDocument/$Vote/"+this.options.style+"/css.wcss";this._loadCss()},load:function(){this.voted=this.data.voted||false;if(!this.options.isNew&&this.data.voteOptionGroupList){this.sortData()}if(this.options.isNew||this.options.isEdited){this.loadContent_edit()}else{this.loadContent_read()}},reload:function(){this.container.empty();this.getData(function(){this.load(true)}.bind(this))},getData:function(e){this.actions.getSubjectView(this.data.id,function(t){this.data=t.data.currentSubject;if(e)e()}.bind(this))},sortData:function(){var t=this.data.voteOptionGroupList||[];t.sort(function(t,e){return t.orderNumber-e.orderNumber});for(var e=0;e1?"多选(最多可选"+t.voteChooseCount+"项):":"单选:";new Element("span",{styles:this.css.groupSubject,text:n}).inject(s);new Element("span",{styles:this.css.groupSubject,text:t.groupName}).inject(s);var c=new Element("div",{styles:this.css.optionContainer}).inject(this.groupContainer);var d;if(o){if(layout.mobile){d=new Element("div").inject(c)}else{d=new Element("table",{cellSpacing:"0",border:"0"}).inject(c)}var h;t.voteOptions.each(function(t,e){var i;if(layout.mobile){i=new Element("div",{styles:this.css.optionsPictureDiv_mobile}).inject(d);var o=new Element("div",{styles:this.css.optionPictureArea_mobile}).inject(i);var s=new Element("img",{src:MWF.xDesktop.getImageSrc(t.optionPictureId),styles:this.css.optionPicture_mobile}).inject(o)}else{if(e%3==0){h=new Element("tr").inject(d)}var n=new Element("td").inject(h);i=new Element("div",{styles:this.css.optionsPictureDiv}).inject(n);var o=new Element("div",{styles:this.css.optionPictureArea}).inject(i);var s=new Element("img",{src:MWF.xDesktop.getImageSrc(t.optionPictureId),styles:this.css.optionPicture}).inject(o);s.addEvent("click",function(){window.open(MWF.xDesktop.getImageSrc(this.id),"_blank")}.bind({id:t.optionPictureId}))}var r=(t.chooseCount/p*100).toString().substr(0,5)+"%";var a=new Element("div",{text:r,styles:this.css.presentDiv}).inject(i);new Element("span",{styles:{color:"#ccc"},text:"("+t.chooseCount+")"}).inject(a);var l=new Element("div",{text:e+1+"."+t.optionTextContent}).inject(i)}.bind(this))}t.voteOptions.each(function(t,e){var i=new Element("div.optionText",{styles:{},text:e+1+". "+t.optionTextContent}).inject(c);var o=new Element("div.resultContainer",{styles:this.css.optionItem}).inject(c);var s=new Element("div",{styles:this.css.optionItemBack}).inject(o);s.setStyle("width",layout.mobile?"70%":"85%");var n=Math.floor(t.chooseCount/p*100);var r=new Element("div.optionItemFront",{styles:this.css.optionItemFront,text:" "}).inject(s);r.setStyles({"background-color":u,width:n+"%"});if(this.data.votePersonVisible&&!layout.mobile){r.setStyles({cursor:"pointer"});r.addEvents({click:function(){this.obj.openLog(this.data)}.bind({obj:this,data:t}),mouseover:function(){this.node.setStyle("opacity","0.8")}.bind({node:r}),mouseout:function(){this.node.setStyle("opacity","1")}.bind({node:r})})}var a=(t.chooseCount/p*100).toString().substr(0,5)+"%";var l=new Element("div",{text:a,styles:this.css.presentNode}).inject(o);new Element("span",{styles:{color:"#ccc"},text:"("+t.chooseCount+")"}).inject(l);if(t.voted){new Element("div",{styles:this.css.checkedOption}).inject(o)}}.bind(this))}},createGroupVoting:function(l,u){this.groupObject=this.groupObject||{};this.groupObject[u]={};this.groupObject[u].id=l.id;this.groupObject[u].inputs=[];var t=new Element("div",{styles:this.css.groupTitle}).inject(this.groupContainer);var e=parseInt(l.voteChooseCount)>1?"多选(最多可选"+l.voteChooseCount+"项):":"单选:";new Element("span",{styles:this.css.groupSubject,text:e}).inject(t);new Element("span",{styles:this.css.groupSubject,text:l.groupName}).inject(t);var p=false;for(var i=0;i1){r.addEvents({click:function(t){var e=this.obj.groupObject[this.groupIndex].inputs;this.obj.checkCountLimited(this.limit,e)}.bind({obj:this,groupIndex:u,optionIndex:e,limit:l.voteChooseCount})});a.addEvents({click:function(t){if(this.input.get("checked")){this.input.set("checked",false)}else if(!this.input.get("disabled")){this.input.set("checked",true)}var e=this.obj.groupObject[this.groupIndex].inputs;this.obj.checkCountLimited(this.limit,e)}.bind({obj:this,groupIndex:u,optionIndex:e,limit:l.voteChooseCount,input:r})})}else{a.addEvents({click:function(t){if(this.input.get("checked")){return}var e=this.obj.groupObject[this.groupIndex].inputs;e.each(function(t){t.set("checked",false)});this.input.set("checked",true)}.bind({obj:this,groupIndex:u,optionIndex:e,input:r})})}this.groupObject[u].inputs.push(r)}.bind(this))},checkCountLimited:function(t,e){var i=0;e.each(function(t){if(t.get("checked"))i++});if(i>=t){e.each(function(t){if(!t.get("checked"))t.set("disabled",true)})}else{e.each(function(t){if(!t.get("checked"))t.set("disabled",false)})}},loadContent_edit:function(){var t=""+""+" "+" "+" "+" "+" "+" "+""+"
";this.container.set("html",t);this.voteTable=this.container.getElement("table");MWF.xDesktop.requireApp("Template","MForm",function(){this.form_vote=new MForm(this.container,this.data,{style:"forum",isEdited:true||this.isEdited||this.isNew,itemTemplate:{voteLimitTime:{text:this.lp.voteLimitTime,tType:"date"},voteResultVisible:{text:this.lp.voteResultVisible,type:"select",selectText:this.lp.yesOrNo.split(","),selectValue:["true","false"]},votePersonVisible:{text:this.lp.votePersonVisible,type:"select",selectText:this.lp.votePersonValue.split(","),selectValue:["true","false"]}}},this);this.form_vote.load()}.bind(this),true);this.addVoteGroupTr=new Element("tr").inject(this.voteTable);var e=new Element("td",{colspan:6}).inject(this.addVoteGroupTr);var i=new Element("input",{type:"button",styles:this.css.addVoteGroupNode,value:this.lp.addVoteGroup}).inject(e);i.addEvent("click",function(){this.createGroupEdited()}.bind(this));if(this.options.isNew||!this.data.voteOptionGroupList){this.createGroupEdited()}else{this.data.voteOptionGroupList.each(function(t,e){this.createGroupEdited(t,e)}.bind(this))}},createGroupEdited:function(r,t){this.groupObject=this.groupObject||{};this.groupIndex=this.groupIndex||1;var a=r||{};var l=false;if(a.voteOptions){for(var e=0;e");t.setTrTemplate("
");t.load();if(!r){t.addTrs(3)}var e=t.tableHead.getElement("th");var i="
"+this.lp.group+this.groupIndex+":"+""+""+this.lp.opt+""+""+"
"+"
";e.set("html",i);var o=e.getElement("[item='groupLabel']");var s=e.getElement("[item='tipNode']");var n=new MForm(e,a,{style:"forum",verifyType:"batch",isEdited:true||this.isEdited||this.isNew,itemTemplate:{groupName:{text:this.lp.voteSubject,defaultValue:this.lp.voteSubject,className:"inputTextNoWidth",style:{width:"500px"},notEmpty:true,defaultValueAsEmpty:true,event:{focus:function(t,e){if(t.getValue()==this.lp.voteSubject)t.setValue("")}.bind(this),blur:function(t,e){if(t.getValue()=="")t.setValue(this.lp.voteSubject)}.bind(this)},onPostLoad:function(t){t.tipNode=s}},voteChooseCount:{text:this.lp.voteCountLimit,defaultValue:1,className:"inputTextNoWidth",tType:"number",style:{width:"30px"}},voteContentType:{type:"checkbox",defaultValue:l?"true":"",selectValue:["true"],selectText:["上传图片"],event:{change:function(t,e){this.obj.setPicture(t.getValue(),this.grid)}.bind({obj:this,grid:t})}},removeVoteGroup:{disable:this.groupIndex==1,type:"button",value:this.lp.removeVoteGroup,className:"removeVoteGroupNode",event:{click:function(t,e){var i=this;i.obj.app.confirm("warn",e,i.obj.lp.confirmRemoveVoteGroupTitle,i.obj.lp.confirmRemoveVoteGroupContent,350,120,function(){i.obj.removeGroup(parseInt(i.node.get("index")));this.close()},function(){this.close()})}.bind({obj:this,node:o})}}}},this.app,this.css);n.load();t.form=n;this.groupObject[this.groupIndex]={grid:t,form:n,groupNameNode:o};this.groupIndex++}.bind(this),true)},removeGroup:function(t){var e=this.groupObject[t];var i=e.grid.container;i.destroy();delete this.groupObject[t];for(var o=t;o=1){this.app.notice("请对每组选择至少一项再提交","error")}else{this.app.notice("请至少选择一项再提交","error")}return null}else{return e}},submitVote:function(){var t=this.getVoteResult();if(t){this.actions.submitVote(t,function(){this.reload()}.bind(this))}},setPicture:function(t,e){if(t=="true"){e.enableItem("optionPictureId")}else{e.disableItem("optionPictureId")}},openLog:function(t){var e=new MWF.xApplication.ForumDocument.VoteLog(this,this.data,{onPostOk:function(t){}.bind(this)});e.optionData=t;e.edit()},diffTime:function(t,e){var i=e.getTime()-t.getTime();var o=Math.floor(i/(24*3600*1e3));var s=i%(24*3600*1e3);var n=Math.floor(s/(3600*1e3));var r=s%(3600*1e3);var a=Math.floor(r/(60*1e3));var l=r%(60*1e3);var u=Math.round(l/1e3);var p=u+"秒";if(a>0){p=a+"分"+p}if(n>0){p=n+"小时"+p}if(o>0){p=o+"天"+p}return p},getRandomColor:function(){var t=false;do{var e=("00000"+(Math.random()*16777216<<0).toString(16)).slice(-6);var i=parseInt(e.substr(0,2),16);var o=parseInt(e.substr(3,2),16);var s=parseInt(e.substr(5,2),16);if(i>240&&o>240&&s>240){t=true}}while(t);return"#"+e}});MWF.xApplication.ForumDocument.VoteLog=new Class({Extends:MPopupForm,Implements:[Options,Events],options:{style:"default",width:"750",height:"600",hasTop:true,hasIcon:false,hasTopIcon:true,hasTopContent:true,hasBottom:false,title:"查看投票参与人",draggable:true,closeAction:true,closeByClickMask:true},_createTableContent:function(){var t=""+""+" "+""+" "+""+" "+" "+"
";this.formTableArea.set("html",t);this.logArea=this.formTableArea.getElement("[item='logArea']");var o=[],s=[],n=[],r=[],a,l;this.data.voteOptionGroupList.each(function(t,e){var i=false;o.push("组"+(e+1)+":"+t.groupName);s.push(t.id);if(this.optionData){if(this.optionData.optionGroupId==t.id){i=true}}else if(e==0){i=true}if(i){a=t.id;t.voteOptions.each(function(t,e){n.push(t.optionTextContent);r.push(t.id);if(this.optionData&&this.optionData.id==t.id){l=t.id}else if(e==0){l=t.id}}.bind(this))}}.bind(this));MWF.xDesktop.requireApp("Template","MForm",function(){var t=new MForm(this.formTableArea,this.data,{style:"forum",isEdited:true||this.isEdited||this.isNew,itemTemplate:{group:{type:"select",text:"组别:",selectText:o,selectValue:s,defaultValue:a,event:{change:function(t,e){var i=t.getValue();var o=[],s=[];this.data.voteOptionGroupList.each(function(t,e){if(i==t.id){t.voteOptions.each(function(t,e){o.push(t.optionTextContent);s.push(t.id);if(e==0)l=t.id})}}.bind(this));t.form.getItem("option").resetItemOptions(s,o);this.showLog(l)}.bind(this)}},option:{type:"select",text:"选项:",selectText:n,selectValue:r,defaultValue:l,event:{change:function(t,e){this.showLog(t.getValue())}.bind(this)}}}},this,this.css);t.load()}.bind(this),true);this.showLog(l)},showLog:function(t){this.logArea.empty();this.recordView=new MWF.xApplication.ForumDocument.VoteRecordView(this.logArea,this.app,this,{templateUrl:this.explorer.path+"listItemVote.json",scrollEnable:true});this.recordView.filterData={subjectId:this.data.id,voteOptionId:t};this.recordView.load()}});MWF.xApplication.ForumDocument.VoteRecordView=new Class({Extends:MWF.xApplication.Template.Explorer.ComplexView,_createDocument:function(t,e){t.index=e;return new MWF.xApplication.ForumDocument.VoteRecordDocument(this.viewNode,t,this.explorer,this,null,t.index)},_getCurrentPageData:function(e,t,i){this.clearBody();if(!t)t=50;if(!i)i=1;if(i==1){}else{}var o=this.filterData||{};this.actions.listVoteRecord(i,t,o,function(t){if(!t.data)t.data=[];if(!t.count)t.count=0;if(e)e(t)}.bind(this))},_removeDocument:function(t,e){},_create:function(){},_queryCreateViewNode:function(){},_postCreateViewNode:function(t){},_queryCreateViewHead:function(){},_postCreateViewHead:function(t){}});MWF.xApplication.ForumDocument.VoteRecordDocument=new Class({Extends:MWF.xApplication.Template.Explorer.ComplexDocument,_queryCreateDocumentNode:function(t){},_postCreateDocumentNode:function(t,e){if(e.votorName)new MWF.widget.O2Person({name:e.votorName},t,{style:"xform"})}});