Ejemplo n.º 1
0
        public static IHtmlControl GetCommentsPanel(IDataLayer commentConnection,
                                                    SiteState state, LightObject currentUser, TopicStorage topic, RowLink[] pageMessages)
        {
            HPanel addPanel = null;

            if (currentUser != null)
            {
                HPanel editPanel = null;
                if (state.BlockHint == "commentAdd")
                {
                    string commentValue = BasketballHlp.AddCommentFromCookie();

                    editPanel = new HPanel(
                        new HTextArea("commentContent", commentValue).Width("100%").Height("10em").MarginTop(5).MarginBottom(5),
                        Decor.Button("отправить")
                        .OnClick(BasketballHlp.AddCommentToCookieScript("commentContent"))
                        .Event("comment_add_save", "commentData",
                               delegate(JsonData json)
                    {
                        lock (lockObj)
                        {
                            string content = json.GetText("commentContent");
                            if (StringHlp.IsEmpty(content))
                            {
                                return;
                            }

                            if (BasketballHlp.IsDuplicate(topic, currentUser.Id, content))
                            {
                                return;
                            }

                            InsertMessageAndUpdate(commentConnection, topic, currentUser, null, content);

                            state.BlockHint = "";

                            BasketballHlp.ResetAddComment();
                        }
                    }
                               ),
                        new HElementControl(
                            h.Script(h.type("text/javascript"), "$('.commentContent').focus();"),
                            ""
                            )
                        ).EditContainer("commentData");
                }

                addPanel = new HPanel(
                    Decor.ButtonMini("оставить комментарий").FontBold().FontSize(12).Padding(2, 7).
                    Event("comment_add", "", delegate
                {
                    state.SetBlockHint("commentAdd");
                }
                          ),
                    new HButton("",
                                new HBefore().ContentIcon(11, 11).BackgroundImage(UrlHlp.ImageUrl("refresh.png"))
                                ).Color("#9c9c9c").MarginLeft(10).Title("Загрузить новые комментарии")
                    .Event("comments_refresh", "", delegate { }),
                    editPanel
                    );
            }

            Dictionary <int, string> htmlRepresentByMessageId = topic.HtmlRepresentByMessageId;

            //RowLink[] allMessages = topic.MessageLink.AllRows;
            RowLink bottomMessage = null;

            if (pageMessages.Length > 0)
            {
                bottomMessage = pageMessages[Math.Max(0, pageMessages.Length - 2)];
            }

            return(new HPanel(
                       new HAnchor("comments"),
                       new HLabel("Комментарии:").MarginTop(30).MarginBottom(20).FontSize("160%")
                       .Hide(commentConnection == context.ForumConnection),
                       new HPanel(
                           new HLabel("Автор").PositionAbsolute().Top(0).Left(0)
                           .BoxSizing().Width(100).Padding(7, 5, 5, 5),
                           new HLabel("Сообщение").Block().Padding(7, 5, 5, 5).BorderLeft(Decor.columnBorder)
                           ).PositionRelative().Align(null).PaddingLeft(100).Background("#dddddd").FontBold(),
                       new HGrid <RowLink>(pageMessages, delegate(RowLink comment)
            {
                IHtmlControl commentBlock = ViewCommentHlp.GetCommentBlock(
                    commentConnection, state, currentUser, topic, htmlRepresentByMessageId, comment
                    );

                if (bottomMessage == comment)
                {
                    return new HPanel(new HAnchor("bottom"), commentBlock);
                }
                return commentBlock;
            },
                                           new HRowStyle().Even(new HTone().Background(Decor.evenBackground))
                                           ).BorderBottom(Decor.bottomBorder).MarginBottom(10),
                       //new HAnchor("bottom"),
                       addPanel
                       ));
        }
Ejemplo n.º 2
0
        public static IHtmlControl GetCommentBlock(IDataLayer commentConnection, SiteState state,
                                                   LightObject currentUser, TopicStorage topic, Dictionary <int, string> htmlRepresentByMessageId, RowLink comment)
        {
            LightObject user      = context.UserStorage.FindUser(comment.Get(MessageType.UserId));
            DateTime    localTime = comment.Get(MessageType.CreateTime).ToLocalTime();

            IHtmlControl whomBlock = GetWhomBlock(state, context.UserStorage, topic, htmlRepresentByMessageId, comment);

            int          commentId   = comment.Get(MessageType.Id);
            string       answerHint  = string.Format("answer_{0}", commentId);
            IHtmlControl answerBlock = null;

            if (currentUser != null && state.BlockHint == answerHint)
            {
                string commentValue = BasketballHlp.AddCommentFromCookie();

                answerBlock = new HPanel(
                    new HTextArea("answerContent", commentValue).Width("100%").Height("10em").MarginTop(5).MarginBottom(5),
                    Decor.Button("отправить")
                    .OnClick(BasketballHlp.AddCommentToCookieScript("answerContent"))
                    .Event("save_answer", "answerContainer",
                           delegate(JsonData json)
                {
                    lock (lockObj)
                    {
                        string content = json.GetText("answerContent");
                        if (StringHlp.IsEmpty(content))
                        {
                            return;
                        }

                        if (BasketballHlp.IsDuplicate(topic, currentUser.Id, content))
                        {
                            return;
                        }

                        InsertMessageAndUpdate(commentConnection, topic, currentUser, commentId, content);

                        state.BlockHint = "";

                        BasketballHlp.ResetAddComment();
                    }
                },
                           commentId
                           ),
                    new HElementControl(
                        h.Script(h.type("text/javascript"), "$('.answerContent').focus();"),
                        ""
                        )
                    ).EditContainer("answerContainer");
            }

            IHtmlControl editBlock = null;

            if (currentUser != null && currentUser.Id == user?.Id)
            {
                editBlock = new HPanel(
                    );
            }

            string  redoHint   = string.Format("redo_{0}", commentId);
            HButton redoButton = null;

            if (currentUser != null && currentUser.Id == user?.Id)
            {
                redoButton = Decor.ButtonMini("редактировать").Event("comment_redo", "",
                                                                     delegate(JsonData json)
                {
                    state.SetBlockHint(redoHint);
                },
                                                                     commentId
                                                                     );
            }

            IHtmlControl redoBlock = null;

            if (currentUser != null && state.BlockHint == redoHint)
            {
                redoBlock = new HPanel(
                    new HTextArea("redoContent", comment.Get(MessageType.Content))
                    .Width("100%").Height("10em").MarginTop(5).MarginBottom(5),
                    Decor.Button("изменить").Event("save_redo", "redoContainer",
                                                   delegate(JsonData json)
                {
                    string content = json.GetText("redoContent");
                    if (StringHlp.IsEmpty(content))
                    {
                        return;
                    }

                    //content = BasketballHlp.PreSaveComment(content);

                    commentConnection.GetScalar("",
                                                "Update message Set content=@content, modify_time=@time Where id=@id",
                                                new DbParameter("content", content),
                                                new DbParameter("time", DateTime.UtcNow),
                                                new DbParameter("id", commentId)
                                                );
                    topic.UpdateMessages();

                    state.BlockHint = "";
                },
                                                   commentId
                                                   ),
                    new HElementControl(
                        h.Script(h.type("text/javascript"), "$('.redoContent').focus();"),
                        ""
                        )
                    ).EditContainer("redoContainer");
            }

            IHtmlControl deleteElement = null;

            if (state.ModeratorMode)
            {
                deleteElement = new HButton("",
                                            std.BeforeAwesome(@"\f00d", 0)
                                            ).MarginLeft(5).Color(Decor.redColor).Title("удалить комментарий")
                                .Event("delete_comment", "", delegate
                {
                    MessageHlp.DeleteMessage(commentConnection, commentId);
                    topic.UpdateMessages();
                    context.UpdateLastComments(commentConnection == context.ForumConnection);
                },
                                       commentId
                                       );
            }

            string topicType = topic.Topic.Get(ObjectType.TypeId) == NewsType.News ? "news" : "article";

            string anchor = string.Format("reply{0}", commentId);

            return(new HXPanel(
                       new HAnchor(anchor),
                       new HPanel(
                           new HLink(UrlHlp.ShopUrl("user", user?.Id),
                                     user?.Get(UserType.Login)
                                     ).FontBold(),
                           new HLabel(user?.Get(UserType.FirstName)).Block()
                           .MediaTablet(new HStyle().InlineBlock().MarginLeft(5)),
                           new HPanel(
                               ViewUserHlp.AvatarBlock(user)
                               ).MarginTop(5)
                           .MediaTablet(new HStyle().Display("none"))
                           ).BoxSizing().WidthLimit("100px", "").Padding(7, 5, 10, 5)
                       .MediaTablet(new HStyle().Block().PaddingBottom(0).PaddingRight(110)),
                       new HPanel(
                           new HPanel(
                               new HLabel(localTime.ToString("dd.MM.yyyy HH:mm")).MarginRight(5)
                               .MediaTablet(new HStyle().MarginBottom(5)),
                               new HLink(string.Format("/{0}/{1}#{2}", topicType, topic.TopicId, anchor), "#").TextDecoration("none")
                               .Hide(commentConnection == context.ForumConnection),
                               deleteElement
                               ).Align(false).FontSize("90%").Color(Decor.minorColor),
                           whomBlock,
                           new HTextView(
                               DictionaryHlp.GetValueOrDefault(htmlRepresentByMessageId, commentId)
                               ).PaddingBottom(15).MarginBottom(5).BorderBottom("1px solid silver"),
                           new HPanel(
                               Decor.ButtonMini("ответить").Event("comment_answer", "",
                                                                  delegate
            {
                state.SetBlockHint(answerHint);
            },
                                                                  commentId
                                                                  ),
                               redoButton
                               ).Hide(currentUser == null),
                           answerBlock,
                           redoBlock
                           ).BoxSizing().Width("100%").BorderLeft(Decor.columnBorder).Padding(7, 5, 5, 5)
                       .MediaTablet(new HStyle().Block().MarginTop(-19))
                       ).BorderTop("2px solid #fff"));
        }