public void EditPost(int id, ProjectionEditViewModel viewModel, IEnumerable<string> pickedFileds) { if (pickedFileds == null) { pickedFileds = new List<string>(); } var projectionPart = _contentManager.Get<ProjectionPart>(id, VersionOptions.Latest); var queryId = projectionPart.Record.QueryPartRecord.Id; var queryPart = _contentManager.Get<QueryPart>(queryId, VersionOptions.Latest); //Post DisplayName queryPart.As<TitlePart>().Title = viewModel.DisplayName; //Post Selected Fields var layoutRecord = projectionPart.Record.LayoutRecord; layoutRecord.Properties.Clear(); string category = viewModel.Name + "ContentFields"; const string settingName = "CoeveryTextFieldSettings.IsDispalyField"; var allFields = _contentDefinitionManager.GetPartDefinition(viewModel.Name).Fields.ToList(); foreach (var property in pickedFileds) { var field = allFields.FirstOrDefault(c => c.Name == property); if (field == null) { continue; } var propertyRecord = new PropertyRecord { Category = category, Type = string.Format("{0}.{1}.", viewModel.Name, property), Description = field.DisplayName, Position = layoutRecord.Properties.Count, State = GetPropertyState(property), LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName]) }; layoutRecord.Properties.Add(propertyRecord); } layoutRecord.State = GetLayoutState(queryPart.Id, layoutRecord.Properties.Count, layoutRecord.Description); // sort queryPart.SortCriteria.Clear(); if (!string.IsNullOrEmpty(viewModel.SortedBy)) { var sortCriterionRecord = new SortCriterionRecord { Category = category, Type = viewModel.SortedBy, Position = queryPart.SortCriteria.Count, State = GetSortState(viewModel.SortedBy, viewModel.SortMode), Description = viewModel.SortedBy + " " + viewModel.SortMode }; queryPart.SortCriteria.Add(sortCriterionRecord); } // VisableTo and pageRowCount var layoutPropertyRecord = new LayoutPropertyRecord { VisableTo = viewModel.VisableTo, PageRowCount = viewModel.PageRowCount, QueryPartRecord_id = queryPart.Id }; _layoutPropertyService.CreateLayoutProperty(layoutPropertyRecord); }
public void PropertyWrapper( dynamic Display, TextWriter Output, HtmlHelper Html, UrlHelper Url, dynamic Item, ContentItem ContentItem, ContentItemMetadata ContentItemMetadata, PropertyRecord Property ) { // Display will encode any string which is not IHtmlString string resultOutput = Convert.ToString(Display(Item)); var resultIsEmpty = String.IsNullOrEmpty(resultOutput) || (resultOutput == "0" && Property.ZeroIsEmpty); if(Property.HideEmpty && resultIsEmpty) { return; } if(Property.RewriteOutput) { resultOutput = _tokenizerWork.Value.Replace(Property.RewriteText, new Dictionary<string, object> { { "Text", resultOutput }, { "Content", ContentItem } }); } if(Property.StripHtmlTags) { resultOutput = resultOutput.RemoveTags(); } if(Property.TrimLength) { var ellipsis = Property.AddEllipsis ? " …" : ""; resultOutput = resultOutput.Ellipsize(Property.MaxLength, ellipsis, Property.TrimOnWordBoundary); } if(Property.TrimWhiteSpace) { resultOutput = resultOutput.Trim(); } if(Property.PreserveLines) { using(var sw = new StringWriter()) { using(var sr = new StringReader(resultOutput)) { string line; while(null != (line = sr.ReadLine())) { sw.WriteLine(line); sw.WriteLine("<br />"); } } resultOutput = sw.ToString(); } } var wrapperTag = new TagBuilder(Property.CustomizeWrapperHtml && !String.IsNullOrEmpty(Property.CustomWrapperTag) ? Property.CustomWrapperTag : "div"); if (Property.CustomizeWrapperHtml && !String.IsNullOrEmpty(Property.CustomWrapperCss)) { wrapperTag.AddCssClass(_tokenizerWork.Value.Replace(Property.CustomWrapperCss, new Dictionary<string, object>())); } if (!(Property.CustomizeWrapperHtml && Property.CustomWrapperTag == "-")) { Output.Write(wrapperTag.ToString(TagRenderMode.StartTag)); } if (Property.CreateLabel) { var labelTag = new TagBuilder(Property.CustomizeLabelHtml && !String.IsNullOrEmpty(Property.CustomLabelTag) ? Property.CustomLabelTag : "span"); if (Property.CustomizeLabelHtml && !String.IsNullOrEmpty(Property.CustomLabelCss)) { labelTag.AddCssClass(_tokenizerWork.Value.Replace(Property.CustomLabelCss, new Dictionary<string, object>())); } if (!(Property.CustomizeLabelHtml && Property.CustomLabelTag == "-")) { Output.Write(labelTag.ToString(TagRenderMode.StartTag)); } Output.Write(_tokenizerWork.Value.Replace(Property.Label, new Dictionary<string, object>())); if (!(Property.CustomizeLabelHtml && Property.CustomLabelTag == "-")) { Output.Write(labelTag.ToString(TagRenderMode.EndTag)); } } var propertyTag = new TagBuilder(Property.CustomizePropertyHtml && !String.IsNullOrEmpty(Property.CustomPropertyTag) ? Property.CustomPropertyTag : "span"); if (Property.CustomizePropertyHtml && !String.IsNullOrEmpty(Property.CustomPropertyCss)) { propertyTag.AddCssClass(_tokenizerWork.Value.Replace(Property.CustomPropertyCss, new Dictionary<string, object>())); } if (!(Property.CustomizePropertyHtml && Property.CustomPropertyTag == "-")) { Output.Write(propertyTag.ToString(TagRenderMode.StartTag)); } if (!resultIsEmpty) { if (Property.LinkToContent) { var linkTag = new TagBuilder("a"); linkTag.Attributes.Add("href", Url.RouteUrl(ContentItemMetadata.DisplayRouteValues)); linkTag.InnerHtml = resultOutput; Output.Write(linkTag.ToString()); } else { Output.Write(resultOutput); } } else { Output.Write(_tokenizerWork.Value.Replace(Property.NoResultText, new Dictionary<string, object>())); } if (!(Property.CustomizePropertyHtml && Property.CustomPropertyTag == "-")) { Output.Write(propertyTag.ToString(TagRenderMode.EndTag)); } if (!(Property.CustomizeWrapperHtml && Property.CustomWrapperTag == "-")) { Output.Write(wrapperTag.ToString(TagRenderMode.EndTag)); } }
private void UpdateLayoutProperties(string typeName, LayoutRecord layoutRecord, IEnumerable<string> properties) { layoutRecord.Properties.Clear(); if (properties == null) { return; } string category = typeName + "ContentFields"; const string settingName = "CoeveryTextFieldSettings.IsDispalyField"; var allFields = _contentDefinitionManager.GetPartDefinition(typeName).Fields.ToList(); foreach (var property in properties) { var field = allFields.FirstOrDefault(c => c.Name == property); if (field == null) { continue; } var propertyRecord = new PropertyRecord { Category = category, Type = string.Format("{0}.{1}.", typeName, property), Description = field.DisplayName, Position = layoutRecord.Properties.Count, LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName]) }; layoutRecord.Properties.Add(propertyRecord); } }
public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)]int propertyId, FormCollection formCollection) { if (!Services.Authorizer.Authorize(Permissions.ManageQueries, T("Not authorized to manage queries"))) return new HttpUnauthorizedResult(); var layout = _layoutRepository.Get(id); var property = _projectionManager.DescribeProperties().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault(); var model = new PropertyEditViewModel(); TryUpdateModel(model); // validating form values _formManager.Validate(new ValidatingContext { FormName = property.Form, ModelState = ModelState, ValueProvider = ValueProvider }); if (ModelState.IsValid) { var propertyRecord = layout.Properties.Where(f => f.Id == propertyId).FirstOrDefault(); // add new property record if it's a newly created property if (propertyRecord == null) { propertyRecord = new PropertyRecord { Category = category, Type = type, Position = layout.Properties.Count }; layout.Properties.Add(propertyRecord); } var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get); // save form parameters propertyRecord.State = FormParametersHelper.ToString(dictionary); propertyRecord.Description = model.Description; propertyRecord.CreateLabel = model.CreateLabel; propertyRecord.ExcludeFromDisplay = model.ExcludeFromDisplay; propertyRecord.Label = model.Label; propertyRecord.LinkToContent = model.LinkToContent; propertyRecord.CustomizeLabelHtml = model.CustomizeLabelHtml; propertyRecord.CustomizePropertyHtml = model.CustomizePropertyHtml; propertyRecord.CustomizeWrapperHtml = model.CustomizeWrapperHtml; propertyRecord.CustomLabelCss = model.CustomLabelCss; propertyRecord.CustomLabelTag = model.CustomLabelTag; propertyRecord.CustomPropertyCss = model.CustomPropertyCss; propertyRecord.CustomPropertyTag = model.CustomPropertyTag; propertyRecord.CustomWrapperCss = model.CustomWrapperCss; propertyRecord.CustomWrapperTag = model.CustomWrapperTag; propertyRecord.NoResultText = model.NoResultText; propertyRecord.ZeroIsEmpty = model.ZeroIsEmpty; propertyRecord.HideEmpty = model.HideEmpty; propertyRecord.RewriteOutput = model.RewriteOutput; propertyRecord.RewriteText = model.RewriteText; propertyRecord.StripHtmlTags = model.StripHtmlTags; propertyRecord.TrimLength = model.TrimLength; propertyRecord.AddEllipsis = model.AddEllipsis; propertyRecord.MaxLength = model.MaxLength; propertyRecord.TrimOnWordBoundary = model.TrimOnWordBoundary; propertyRecord.PreserveLines = model.PreserveLines; propertyRecord.TrimWhiteSpace = model.TrimWhiteSpace; return RedirectToAction("Edit", "Layout", new { id }); } // model is invalid, display it again var form = _formManager.Build(property.Form); _formManager.Bind(form, formCollection); var viewModel = new PropertyEditViewModel { Id = id, Description = model.Description, Property = property, Form = form }; return View(viewModel); }
private void UpdateLayoutProperties(string entityName, ref LayoutRecord layout, string category, string settingName, IEnumerable<string> pickedFileds) { var allFields = _contentDefinitionManager.GetPartDefinition(entityName).Fields.ToList(); const string fieldTypeFormat = "{0}.{1}."; foreach (var property in pickedFileds) { var names = property.Split('.'); var propertyMatch = string.Format(fieldTypeFormat, names[0], names[1]); var field = allFields.FirstOrDefault(c => string.Format(fieldTypeFormat, entityName, c.Name) == propertyMatch); if (field == null) { continue; } var fieldStateProvider = _fieldToPropertyStateProviders.FirstOrDefault(provider=>provider.CanHandle(field.FieldDefinition.Name)); if (fieldStateProvider == null) { throw new NotSupportedException("The field type \""+ field.FieldDefinition.Name + "\" is not supported!"); } var propertyRecord = new PropertyRecord { Category = category, Type = property, Description = field.DisplayName, Position = layout.Properties.Count, State = fieldStateProvider.GetPropertyState(field.FieldDefinition.Name, property, field.Settings), LinkToContent = field.Settings.ContainsKey(settingName) && bool.Parse(field.Settings[settingName]) }; layout.Properties.Add(propertyRecord); } }