예제 #1
0
        public void Detail()
        {
            ForumPoll p = ctx.GetItem("poll") as ForumPoll;

            if (p == null)
            {
                set("pollForm", "");
                set("pollResult", "");
                return;
            }

            ForumBoard board = setCurrentBoard(p);

            set("topicId", p.TopicId);
            set("resultLink", to(GetPollResultHtml, p.Id) + "?boardId=" + board.Id);
            set("poll.VoteLink", to(Vote, p.Id) + "?boardId=" + board.Id);

            String hideCss = "display:none;";

            if (p.CheckHasVote(ctx.viewer.Id) || (p.IsClosed() && p.IsVisible == 0))
            {
                set("formStyle", hideCss);
                set("resultStype", "");
            }
            else
            {
                set("formStyle", "");
                set("resultStype", hideCss);
            }

            load("pollForm", pollForm);
            load("pollResult", pollResult);
        }
예제 #2
0
        private void setCurrentBoard(ForumPoll poll)
        {
            ForumTopic topic = topicService.GetById(poll.TopicId, ctx.owner.obj);
            ForumBoard board = boardService.GetById(topic.ForumBoard.Id, ctx.owner.obj);

            ctx.SetItem("forumBoard", board);
        }
예제 #3
0
        public void GetPollResultHtml(int pollId)
        {
            ForumPoll p = pollService.GetById(pollId);

            ctx.SetItem("poll", p);

            echo(loadHtml(pollResult));
        }
예제 #4
0
        private String getVoterLink(ForumPoll p, ForumBoard board)
        {
            if (p.IsOpenVoter == 0)
            {
                String url = to(Voter, p.Id) + "?boardId=" + board.Id;
                return(string.Format("<a href=\"{0}\" class=\"frmBox left10 right10\" target=\"_blank\">投票人数: {1}</a>", url, p.VoteCount));
            }

            return("<span class=\"poll-voter-count\">投票人数: " + p.VoteCount + "</span>");
        }
예제 #5
0
        public void pollResult()
        {
            ForumPoll  p     = ctx.GetItem("poll") as ForumPoll;
            ForumBoard board = setCurrentBoard(p);

            set("topicId", p.TopicId);

            set("poll.Title", p.Title);
            set("poll.Question", p.Question);
            set("poll.Voters", p.VoteCount);

            set("lnkVoter", getVoterLink(p, board));

            int colorCount = 6;
            int iColor     = 1;

            IBlock opblock = getBlock("options");

            for (int i = 0; i < p.OptionList.Length; i++)
            {
                PollHelper or = new PollHelper(p, p.OptionList.Length, i);

                opblock.Set("op.Text", p.OptionList[i]);
                opblock.Set("op.Id", (i + 1));
                opblock.Set("op.ImgWidth", or.ImgWidth * 1);
                opblock.Set("op.Percent", or.VotesAndPercent);
                opblock.Set("op.ColorIndex", iColor);
                opblock.Next();

                iColor++;
                if (iColor > colorCount)
                {
                    iColor = 1;
                }
            }

            set("poll.ExpiryInfo", p.GetRealExpiryDate());

            IBlock btnVote  = getBlock("btnVote");
            IBlock lblVoted = getBlock("lblVoted");

            if (p.CheckHasVote(ctx.viewer.Id))
            {
                lblVoted.Next();
            }
            else if (p.IsClosed() == false)
            {
                btnVote.Next();
            }
        }
예제 #6
0
        private void bindVoter( ForumPoll poll, DataPage<ForumPollResult> voterList )
        {
            setCurrentBoard( poll );

            IBlock block = getBlock( "list" );
            foreach (ForumPollResult result in voterList.Results) {
                block.Set( "user.Name", result.User.Name );
                block.Set( "user.Choice", result.Answer );
                block.Set( "user.Created", result.Created );
                block.Next();
            }

            set( "page", voterList.PageBar );
        }
예제 #7
0
        public void Voter(int id)
        {
            ForumPoll poll = pollService.GetById(id);

            if (poll == null)
            {
                echoText(lang("exPollItemNotFound"));
                return;
            }

            DataPage <ForumPollResult> voterList = pollService.GetVoterList(id);

            bindVoter(poll, voterList);
        }
예제 #8
0
        private void bindViewLink(ForumPoll p)
        {
            IBlock lnkView = getBlock("lnkView");
            IBlock lblView = getBlock("lblView");

            if (p.IsVisible == 0 || isAuthor(p) || ctx.viewer.IsAdministrator() || ctx.viewer.IsOwnerAdministrator(ctx.owner.obj))
            {
                lnkView.Set("topicId", p.TopicId);
                lnkView.Next();
            }
            else
            {
                lblView.Next();
            }
        }
예제 #9
0
        private void bindVoter(ForumPoll poll, DataPage <ForumPollResult> voterList)
        {
            setCurrentBoard(poll);

            IBlock block = getBlock("list");

            foreach (ForumPollResult result in voterList.Results)
            {
                block.Set("user.Name", result.User.Name);
                block.Set("user.Choice", result.Answer);
                block.Set("user.Created", result.Created);
                block.Next();
            }

            set("page", voterList.PageBar);
        }
예제 #10
0
        private String getControl(ForumPoll poll, int optionIndex, String optionText)
        {
            Html html = new Html();

            if (poll.Type == 1)
            {
                html.CheckBox("pollOption", Convert.ToString((optionIndex + 1)), optionText);
            }
            else
            {
                String __name = "pollOption";
                String __val  = Convert.ToString((optionIndex + 1));
                String __txt  = optionText;

                html.Code(string.Format("<label class=\"radio\"><input type=\"radio\" name=\"{0}\" id=\"{3}\" value=\"{1}\" /> {2}</label> ", __name, __val, __txt, __name + __val));
            }
            return(html.ToString());
        }
예제 #11
0
        public void pollForm()
        {
            ForumPoll  p     = ctx.GetItem("poll") as ForumPoll;
            ForumBoard board = setCurrentBoard(p);

            set("topicId", p.TopicId);

            set("resultLink", to(GetPollResultHtml, p.Id) + "?boardId=" + board.Id);

            set("poll.Id", p.Id);
            set("poll.Title", p.Title);
            set("poll.Question", p.Question);
            set("poll.Voters", p.VoteCount);
            set("poll.VoteLink", to(Vote, p.Id) + "?boardId=" + board.Id);

            IBlock opblock = getBlock("options");

            for (int i = 0; i < p.OptionList.Length; i++)
            {
                opblock.Set("op.SelectControl", getControl(p, i, p.OptionList[i]));
                opblock.Set("op.Id", (i + 1));
                opblock.Next();
            }

            IBlock cmdBlock = getBlock("cmdVote");   // 投票命令
            IBlock tipBlock = getBlock("plsVote");   // 请先登录

            if (p.IsClosed())
            {
            }
            else if (ctx.viewer.IsLogin)
            {
                cmdBlock.Next();
            }
            else
            {
                tipBlock.Next();
            }

            bindViewLink(p);

            set("poll.ExpiryInfo", p.GetRealExpiryDate());
        }
예제 #12
0
        public void Vote(int id)
        {
            ForumPoll poll = pollService.GetById(id);

            if (poll == null)
            {
                echoError(lang("exPollItemNotFound"));
                return;
            }

            if (poll.CheckHasVote(ctx.viewer.Id))
            {
                echoError(lang("exVoted"));
                return;
            }

            String choice = ctx.Post("pollOption");

            if (strUtil.IsNullOrEmpty(choice))
            {
                echoError(lang("pollSelectRequire"));
                return;
            }

            ForumPollResult pollResult = new ForumPollResult();

            pollResult.User   = (User)ctx.viewer.obj;
            pollResult.PollId = poll.Id;
            pollResult.Answer = choice;
            pollResult.Ip     = ctx.Ip;

            String lnkPost = to(new Forum.TopicController().Show, poll.TopicId);

            pollService.CreateResult(pollResult, lnkPost);

            echoAjaxOk();
        }
예제 #13
0
        public void Vote(int id)
        {
            ForumPoll poll = pollService.GetById(id);

            if (poll == null)
            {
                echoText(alang("exPollItemNotFound"));
                return;
            }

            if (poll.CheckHasVote(ctx.viewer.Id))
            {
                echoText(alang("exVoted"));
                return;
            }

            String          choice     = ctx.Get("pollOption");
            ForumPollResult pollResult = new ForumPollResult();

            pollResult.User   = (User)ctx.viewer.obj;
            pollResult.PollId = poll.Id;
            pollResult.Answer = choice;
            pollResult.Ip     = ctx.Ip;

            String lnkPost = to(new Forum.TopicController().Show, poll.TopicId);

            pollService.CreateResult(pollResult, lnkPost);

            ForumBoard board = setCurrentBoard(poll);

            String lnkVote  = to(Vote, id) + "?boardId=" + board.Id;
            String lnkVoter = to(Voter, id) + "?boardId=" + board.Id;

            String json = new PollViewFactory((User)ctx.viewer.obj, poll, lnkVote, lnkVoter).GetJsonResult();

            echoText(json);
        }
예제 #14
0
 private bool isAuthor(ForumPoll p)
 {
     return(ctx.viewer.Id == p.Creator.Id);
 }
예제 #15
0
        private String getControl( ForumPoll poll, int optionIndex, String optionText )
        {
            Html html = new Html();
            if (poll.Type == 1) {
                html.CheckBox( "pollOption", Convert.ToString( (optionIndex + 1) ), optionText );
            }
            else {
                String __name = "pollOption";
                String __val = Convert.ToString( (optionIndex + 1) );
                String __txt = optionText;

                html.Code( string.Format( "<label class=\"radio\"><input type=\"radio\" name=\"{0}\" id=\"{3}\" value=\"{1}\" /> {2}</label> ", __name, __val, __txt, __name + __val ) );
            }
            return html.ToString();
        }
예제 #16
0
        private String getVoterLink( ForumPoll p, ForumBoard board )
        {
            if (p.IsOpenVoter == 0) {
                String url = to( Voter, p.Id ) + "?boardId=" + board.Id;
                return string.Format( "<a href=\"{0}\" class=\"frmBox left10 right10\" target=\"_blank\">投票人数: {1}</a>", url, p.VoteCount );
            }

            return "<span class=\"poll-voter-count\">投票人数: " + p.VoteCount + "</span>";
        }
예제 #17
0
 private bool isAuthor( ForumPoll p )
 {
     return ctx.viewer.Id == p.Creator.Id;
 }
예제 #18
0
 private ForumBoard setCurrentBoard( ForumPoll poll )
 {
     ForumTopic topic = topicService.GetById( poll.TopicId, ctx.owner.obj );
     ForumBoard board = boardService.GetById( topic.ForumBoard.Id, ctx.owner.obj );
     ctx.SetItem( "forumBoard", board );
     return board;
 }
예제 #19
0
 private void bindViewLink( ForumPoll p )
 {
     IBlock lnkView = getBlock( "lnkView" );
     IBlock lblView = getBlock( "lblView" );
     if (p.IsVisible == 0 || isAuthor( p ) || ctx.viewer.IsAdministrator() || ctx.viewer.IsOwnerAdministrator( ctx.owner.obj )) {
         lnkView.Set( "topicId", p.TopicId );
         lnkView.Next();
     }
     else {
         lblView.Next();
     }
 }