Exemple #1
0
        static IHtmlControl GetTopicAddPanel(SiteState state, LightObject currentUser, LightSection section)
        {
            string blockHint = "topic_add";

            IHtmlControl addPanel = null;

            if (state.BlockHint == blockHint)
            {
                addPanel = new HPanel(
                    Decor.PropertyEdit("addTopicTitle", "Заголовок темы"),
                    new HTextArea("addTopicText")
                    .Width("100%").Height("6em").MarginBottom(5),
                    Decor.Button("Сохранить").MarginTop(10)
                    .Event("save_topic_add", "addTopicData", delegate(JsonData json)
                {
                    string title = json.GetText("addTopicTitle");
                    string text  = json.GetText("addTopicText");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }
                    if (!operation.Validate(text, "Не задан текст"))
                    {
                        return;
                    }

                    KinBox editBox = new KinBox(context.FabricConnection, "1=0");

                    int addTopicId    = editBox.CreateObject(TopicType.Topic, TopicType.Title.CreateXmlIds(title), DateTime.UtcNow);
                    LightKin addTopic = new LightKin(editBox, addTopicId);

                    addTopic.SetParentId(ForumSectionType.TopicLinks, section.Id);

                    addTopic.Set(ObjectType.ActTill, DateTime.UtcNow);
                    addTopic.Set(TopicType.PublisherId, currentUser.Id);

                    editBox.Update();

                    MessageHlp.InsertMessage(context.ForumConnection, addTopic.Id, currentUser.Id, null, text);

                    context.UpdateLastComments(true);
                    context.Forum.ForSection(section.Id).Update();

                    state.BlockHint = "";

                    //context.Forum.TopicsStorages.ForTopic(addTopic.Id);
                }
                           )
                    ).EditContainer("addTopicData").MarginTop(5);
            }

            return(new HPanel(
                       Decor.Button("Создать тему")
                       .Event("topic_add", "", delegate
            {
                state.SetBlockHint(blockHint);
            }
                              ),
                       addPanel
                       ).MarginTop(5).MarginBottom(10));
        }
Exemple #2
0
        static IHtmlControl GetNewsEditPanel(SiteState state, TopicStorage topic)
        {
            LightObject news = topic.Topic;

            string blockHint = string.Format("news_edit_{0}", news.Id);

            IHtmlControl redoPanel = null;

            if (state.BlockHint == blockHint)
            {
                IHtmlControl deletePanel = null;
                if (state.ModeratorMode)
                {
                    deletePanel = DeleteTopicPanel(state, topic);
                }

                if (state.Tag == null)
                {
                    state.Tag = ViewTagHlp.GetTopicDisplayTags(context.Tags.TagBox, topic.Topic);
                }

                redoPanel = new HPanel(
                    deletePanel,
                    Decor.PropertyEdit("newsTitle", "Заголовок новости", news.Get(NewsType.Title)),
                    new HPanel(
                        HtmlHlp.CKEditorCreate("newsText", news.Get(NewsType.Text), "300px", true)
                        ),
                    ViewTagHlp.GetEditTagsPanel(state, context.Tags.TagBox, state.Tag as List <string>, false),
                    Decor.PropertyEdit("newsOriginName", "Источник", news.Get(NewsType.OriginName)),
                    Decor.PropertyEdit("newsOriginUrl", "Ссылка", news.Get(NewsType.OriginUrl)),
                    Decor.Button("Изменить новость").CKEditorOnUpdateAll().MarginTop(10)
                    .Event("save_news_edit", "editNewsData",
                           delegate(JsonData json)
                {
                    string title      = json.GetText("newsTitle");
                    string text       = json.GetText("newsText");
                    string originName = json.GetText("newsOriginName");
                    string originUrl  = json.GetText("newsOriginUrl");

                    WebOperation operation = state.Operation;

                    if (!operation.Validate(title, "Не задан заголовок"))
                    {
                        return;
                    }
                    if (!operation.Validate(text, "Не задан текст"))
                    {
                        return;
                    }

                    LightKin editNews = DataBox.LoadKin(context.FabricConnection, NewsType.News, news.Id);

                    editNews.SetWithoutCheck(NewsType.Title, title);

                    editNews.Set(NewsType.Text, text);
                    editNews.Set(NewsType.OriginName, originName);
                    editNews.Set(NewsType.OriginUrl, originUrl);

                    editNews.Set(ObjectType.ActTill, DateTime.UtcNow);

                    ViewTagHlp.SaveTags(context, state, editNews);

                    editNews.Box.Update();

                    context.UpdateNews();
                    context.NewsStorages.ForTopic(news.Id).UpdateTopic();

                    state.BlockHint = "";
                },
                           news.Id
                           )
                    ).EditContainer("editNewsData")
                            .Padding(5, 10).MarginTop(10).Background(Decor.pageBackground);
            }

            return(new HPanel(
                       Decor.Button("Редактировать")
                       .Event("news_edit", "", delegate
            {
                state.SetBlockHint(blockHint);
            }
                              ),
                       redoPanel
                       ).MarginTop(10));
        }