| 1 |
- 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;e<t.length;e++){var i=t[e];i.voteOptions.sort(function(t,e){return t.orderNumber-e.orderNumber})}},loadContent_read:function(){var i=false;var t="";if(this.data.voteLimitTime&&this.data.voteLimitTime!=""){var e=new Date;var o=new Date(this.data.voteLimitTime.replace(/-/g,"/"));if(e<o){t=",距结束还有"+this.diffTime(e,o)+""}else{i=true;t=",投票已经结束"}}var s="";if(this.data.voteCount){s=",目前已有"+this.data.voteCount+"人参与"}else{s=",目前还没有人参与"}var n=new Element("div",{styles:this.css.inforNode,text:this.lp.vote}).inject(this.container);new Element("span",{styles:this.css.infor2Node,text:s+t}).inject(n);if(this.data.votePersonVisible&&this.data.votePerson!=0){}this.groupContainer=new Element("div",{styles:this.css.groupContainer}).inject(this.container);this.data.voteOptionGroupList.each(function(t,e){if(this.voted||i){if(this.data.voteResultVisible||this.data.creatorName==this.userName){this.createGroupVoted(t,e)}}else{this.createGroupVoting(t,e)}}.bind(this));if(this.voted||i){if(!this.data.voteResultVisible&&this.data.creatorName!=this.userName){new Element("div",{styles:{"margin-bottom":"5px"},text:"此为不公开投票,只有发帖人能看到投票结果"}).inject(this.container)}}if(!this.voted){if(!i){var r=new Element("div").inject(this.container);var a=new Element("input",{type:"button",styles:this.css.submitButton,value:"提交"}).inject(r);a.addEvent("click",function(){this.submitVote()}.bind(this));a.addEvents({mouseover:function(){this.node.setStyles(this.obj.css.submitButton_over)}.bind({obj:this,node:a}),mouseout:function(){this.node.setStyles(this.obj.css.submitButton)}.bind({obj:this,node:a})});if(this.data.votePersonVisible){new Element("span",{styles:{"margin-left":"10px"},text:"(此为公开投票,其他人可以看到您的投票项目)"}).inject(r)}else{new Element("span",{styles:{"margin-left":"10px"},text:"(此为匿名投票,他人无法查看您的投票项目)"}).inject(r)}}}else{new Element("span",{text:"您已经投过票,谢谢您的参与"}).inject(this.container)}},createGroupVoted:function(t,e){var u=this.getRandomColor();var i="800";var p=0;var o=false;t.voteOptions.each(function(t){p+=parseInt(t.chooseCount);if(t.optionContentType=="图片"){o=true}});if(p!=0){var s=new Element("div",{styles:this.css.groupTitle}).inject(this.groupContainer);var n=parseInt(t.voteChooseCount)>1?"多选(最多可选"+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;i<l.voteOptions.length;i++){if(l.voteOptions[i].optionContentType=="图片"){p=true;break}}var c=new Element("div",{styles:p?this.css.optionPictureContainer:this.css.optionContainer}).inject(this.groupContainer);var d;if(p){if(layout.mobile){d=new Element("div").inject(c)}else{d=new Element("table",{cellSpacing:"0",border:"0"}).inject(c)}}var h;l.voteOptions.each(function(t,e){var i;if(p){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}))}}else{i=new Element("div",{styles:this.css.optionsDiv}).inject(c)}var r=new Element("input",{type:l.voteChooseCount==1?"radio":"checkbox",name:"voteCheck_"+u,value:t.id,styles:p?this.css.optionsPictureInput:this.css.optionsInput}).inject(i);var a=new Element("span",{text:e+1+"."+(p?"":" ")+t.optionTextContent}).inject(i);if(l.voteChooseCount>1){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="<table width='100%' bordr='0' cellpadding='5' cellspacing='0' style='margin-top:15px;'>"+"<tr>"+" <td styles='formTableTitleRight' lable='voteLimitTime' width='7%'></td>"+" <td styles='formTableValue' item='voteLimitTime' width='20%'></td>"+" <td styles='formTableTitleRight' lable='voteResultVisible' width='16%'></td>"+" <td styles='formTableValue' item='voteResultVisible' width='20%'></td>"+" <td styles='formTableTitleRight' lable='votePersonVisible' width='16%'></td>"+" <td styles='formTableValue' item='votePersonVisible' width='20%'></td>"+"</tr>"+"</table>";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<a.voteOptions.length;e++){if(a.voteOptions[e].optionContentType=="图片"){l=true;break}}}var i=new Element("tr").inject(this.addVoteGroupTr,"before");var u=new Element("td",{colspan:6}).inject(i);var o;MWF.xDesktop.requireApp("Template","MGrid",function(){var t=new MGrid(u,a.voteOptions,{style:"forum",isEdited:true||this.isEdited||this.isNew,hasOperation:true,hasSequence:false,minTrCount:2,tableAttributes:{width:"100%",border:"0",cellpadding:"5",cellspacing:"0"},itemTemplate:{optionTextContent:{text:this.lp.option,defaultValue:this.lp.option,notEmpty:true,defaultValueAsEmpty:true,event:{focus:function(t,e){if(t.getValue()==this.lp.option)t.setValue("")}.bind(this),blur:function(t,e){if(t.getValue()=="")t.setValue(this.lp.option)}.bind(this)}},optionPictureId:{type:"imageClipper",text:"图片",notEmpty:true,disable:!l,style:{imageStyle:this.css.optionPicture,imageWrapStyle:this.css.optionPictureArea,actionStyle:this.css.uploadActionNode},aspectRatio:0,ratioAdjustedEnable:true,reference:this.app.advanceId||this.app.data.id,referenceType:"forumDocument"}},onQueryCreateTr:function(){if(this.form){if(this.form.getItem("voteContentType").getValue()=="true"){this.itemTemplate["optionPictureId"].disable=false}else{this.itemTemplate["optionPictureId"].disable=true}}}},this.app);t.setThTemplate("<tr><th style='text-align: left;font-size:14px;font-weight: normal;'></th><th button_add></th></tr>");t.setTrTemplate("<tr><td><div item='optionTextContent' style='padding-top:10px'></div><div item='optionPictureId' style='padding-top: 5px;'></div></td><td button_remove style='vertical-align: top;padding-top:15px;'></td></tr>");t.load();if(!r){t.addTrs(3)}var e=t.tableHead.getElement("th");var i="<div><span style='font-size:18px;margin-right:10px;' item='groupLabel' index='"+this.groupIndex+"'>"+this.lp.group+this.groupIndex+":</span>"+"<span item='groupName' style='margin-right:15px;'></span>"+"<span lable='voteChooseCount' style='margin-right:5px;'></span><span item='voteChooseCount' style='margin-right:5px;'></span><span style='margin-right:10px;''>"+this.lp.opt+"</span>"+"<span item='voteContentType' style='margin-right:15px;'></span>"+"<span style='margin-right:15px;' item='removeVoteGroup'></span></div>"+"<div item='tipNode'></div>";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<this.groupIndex-1;o++){this.groupObject[o]=this.groupObject[o+1];this.groupObject[o].groupNameNode.set("text",this.lp.group+o+":");this.groupObject[o].groupNameNode.set("index",o)}this.groupObject[this.groupIndex-1]=null;this.groupIndex--},getVoteInfor:function(){var t=true;var e=this.form_vote.getResult(true,",",true,false,true);if(!e)t=false;if(t)e.optionGroups=[];for(var i in this.groupObject){var o=this.groupObject[i];if(o){var s=o.form.getResult(true,",",true,false,true);if(!s)t=false;var n=o.grid.getResult(true,",",true,false,true);if(!n)t=false;if(t){for(var r=0;r<n.length;r++){n[r].optionContentType=s.voteContentType=="true"?"图片":"文字"}s.voteOptions=n;e.optionGroups.push(s)}}}return t?e:null},getVoteResult:function(){var t=true;var e={};e.id=this.data.id;e.optionGroups=[];for(var i in this.groupObject){var o={};o.selectedVoteOptionIds=[];var s=this.groupObject[i];o.id=s.id;for(var n=0;n<s.inputs.length;n++){var r=s.inputs[n];if(r.get("checked")){o.selectedVoteOptionIds.push(r.get("value"))}}if(o.selectedVoteOptionIds.length==0){t=false}e.optionGroups.push(o)}if(!t){if(this.data.voteOptionGroupList.length>=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="<table width='95%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>"+"<tr><td styles='formTableTitle' lable='group' width='15%'></td>"+" <td styles='formTableValue' item='group' width='85%'></td></tr>"+"<tr><td styles='formTableTitle' lable='option'></td>"+" <td styles='formTableValue' item='option'></td></tr>"+"<tr><td styles='formTableTitle'></td>"+" <td styles='formTableValue'><div item='logArea' styles='logArea'></div></td>"+" </tr>"+"</table>";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"})}});
|