public static List <string> GetTopicDisplayTags(ObjectHeadBox tagBox, LightParent topic) { LightHead[] tags = GetTopicTags(tagBox, topic); List <string> displayTags = new List <string>(tags.Length); foreach (LightHead tag in tags) { displayTags.Add(tag.Get(TagType.DisplayName)); } return(displayTags); }
public static LightHead[] GetTopicTags(ObjectHeadBox tagBox, LightParent topic) { int[] tagIds = topic.AllChildIds(TopicType.TagLinks); List <LightHead> tags = new List <LightHead>(tagIds.Length); foreach (int tagId in tagIds) { if (tagBox.ObjectById.Exist(tagId)) { tags.Add(new LightHead(tagBox, tagId)); } } return(tags.ToArray()); }
public static IHtmlControl GetViewTagsPanel(ObjectHeadBox tagBox, LightParent topic) { List <IHtmlControl> elements = new List <IHtmlControl>(); elements.Add(new HLabel("Теги:").FontBold().MarginRight(5)); int[] tagIds = topic.AllChildIds(TopicType.TagLinks); RowLink[] tagRows = GetTagRows(tagBox, tagIds); //tagsDisplay = StringHlp.Join(", ", tagRows, delegate (RowLink row) // { return TagType.DisplayName.Get(row); } //); foreach (RowLink tagRow in tagRows) { elements.Add( new HLink(TagUrl(tagRow.Get(ObjectType.ObjectId), 0), TagType.DisplayName.Get(tagRow)).MarginRight(5) ); } return(new HPanel( elements.ToArray() ).MarginTop(10)); }
public static void SaveTags(BasketballContext context, SiteState state, LightParent editTopic) { List <string> tags = state.Tag as List <string>; if (tags == null) { return; } ObjectHeadBox editBox = null; List <int> tagIds = new List <int>(); foreach (string tag in tags) { if (StringHlp.IsEmpty(tag)) { continue; } string tagKey = tag.ToLower(); { int tagId; if (context.TagIdByKey.TryGetValue(tagKey, out tagId)) { tagIds.Add(tagId); continue; } } string xmlIds = TagType.DisplayName.CreateXmlIds(tag); //RowLink tagRow = context.Tags.ObjectByXmlIds.AnyRow(xmlIds); //if (tagRow != null) //{ // tagIds.Add(tagRow.Get(ObjectType.ObjectId)); // continue; //} if (editBox == null) { editBox = new ObjectHeadBox(context.FabricConnection, "1=0"); } int?newTagId = editBox.CreateUniqueObject(TagType.Tag, xmlIds, null); if (newTagId == null) { continue; } tagIds.Add(newTagId.Value); } if (editBox != null) { editBox.Update(); context.UpdateTags(); } for (int i = 0; i < tagIds.Count; ++i) { int tagId = tagIds[i]; if (tagId != editTopic.GetChildId(TopicType.TagLinks, i)) { editTopic.SetChildId(TopicType.TagLinks, i, tagId); } } RowLink[] allTagRows = editTopic.AllChildRows(TopicType.TagLinks); for (int i = allTagRows.Length - 1; i >= tagIds.Count; --i) { editTopic.RemoveChildLink(TopicType.TagLinks, i); } }
public static IHtmlControl GetActualNewsBlock(SiteState state, LightObject currentUser) { IHtmlControl[] items = ViewNewsHlp.GetNewsItems(state, context.ActualNews); HPanel editBlock = null; string editHint = "news_add"; if (state.BlockHint == editHint) { if (state.Tag == null) { state.Tag = new List <string>(); } string unsaveText = BasketballHlp.AddCommentFromCookie(); editBlock = new HPanel( Decor.PropertyEdit("newsTitle", "Заголовок новости"), new HPanel( HtmlHlp.CKEditorCreate("newsText", unsaveText, "300px", true) ), ViewTagHlp.GetEditTagsPanel(state, context.Tags.TagBox, state.Tag as List <string>, true), Decor.PropertyEdit("newsOriginName", "Источник"), Decor.PropertyEdit("newsOriginUrl", "Ссылка"), Decor.Button("Добавить новость").MarginTop(10) //.CKEditorOnUpdateAll() .OnClick(string.Format("CK_updateAll(); {0}", BasketballHlp.AddCommentToCookieScript("newsText"))) .Event("save_news_add", "addNewsData", 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; } ParentBox editBox = new ParentBox(context.FabricConnection, "1=0"); int addNewsId = editBox.CreateObject(NewsType.News, NewsType.Title.CreateXmlIds(title), DateTime.UtcNow); LightParent editNews = new LightParent(editBox, addNewsId); editNews.Set(NewsType.PublisherId, currentUser.Id); editNews.Set(NewsType.Text, text); editNews.Set(NewsType.OriginName, originName); editNews.Set(NewsType.OriginUrl, originUrl); ViewTagHlp.SaveTags(context, state, editNews); editBox.Update(); context.UpdateNews(); state.BlockHint = ""; state.Tag = null; BasketballHlp.ResetAddComment(); } ) ).EditContainer("addNewsData").Padding(5, 10).MarginTop(10).Background(Decor.pageBackground); } IHtmlControl addButton = null; if (currentUser != null && !BasketballHlp.NoRedactor(currentUser)) { addButton = Decor.Button("Добавить").MarginLeft(10) .Event("news_add", "", delegate { state.Tag = null; state.SetBlockHint(editHint); } ); } return(new HPanel( Decor.Subtitle("Новости"), new HPanel( items.ToArray() ), new HPanel( new HLink("/novosti", "Все новости", new HBefore().ContentIcon(5, 12).BackgroundImage(UrlHlp.ImageUrl("pointer.gif")).MarginRight(5).VAlign(-2) ).FontBold(), addButton ).MarginTop(15), editBlock )); }