/// <summary> /// Gets the config data stored in the property editor prevalues /// </summary> /// <returns></returns> public object GetPrevalues() { IDataTypeDefinition dataType = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(Alias).First(); if (dataType == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } IEnumerable <string> prevalues = _dataTypeService.GetPreValuesByDataTypeId(dataType.Id); return(new { prevalues }); }
public IEnumerable <Crop> GetAllCrops() { var allCrops = new List <Crop>(); var imageCropperDataTypes = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(ApplicationConstants.ImageCropperPropertyEditorAlias); foreach (var dataType in imageCropperDataTypes) { var crops = _dataTypeService.GetPreValuesByDataTypeId(dataType.Id).ToList(); if (!crops.HasAny()) { continue; } var cropsFromDb = JsonConvert.DeserializeObject <IEnumerable <Crop> >(crops.First()); allCrops.AddRange(cropsFromDb); } return(allCrops); }
public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService) { if (property.Value == null || string.IsNullOrEmpty(property.Value.ToString())) { return(null); } // if we dont have a json structure, we will get it from the property type var val = property.Value.ToString(); if (val.DetectIsJson()) { return(val); } // more magic here ;-( var config = dataTypeService.GetPreValuesByDataTypeId(propertyType.DataTypeDefinitionId).FirstOrDefault(); var crops = string.IsNullOrEmpty(config) ? "[]" : config; var newVal = "{src: '" + val + "', crops: " + crops + "}"; return(newVal); }
private IDataTypeDefinition CreateNestedContentDataType(IDataTypeDefinition archetypeDataType) { var name = archetypeDataType.Name + " (NC)"; var alias = Alias(archetypeDataType.Name + "nc"); // TODO Umbraco method of creating aliases var existingDataType = _dataTypeService.GetDataTypeDefinitionByName(name); if (existingDataType != null) { return(existingDataType); } var preValue = _dataTypeService.GetPreValuesByDataTypeId(archetypeDataType.Id).FirstOrDefault(); var archetypePreValue = JsonConvert.DeserializeObject <ArchetypePreValue>(preValue); var contentType = new ContentType(-1); contentType.Name = name; contentType.Alias = alias; foreach (var fieldset in archetypePreValue.Fieldsets) { var propertyGroup = new PropertyGroup(); propertyGroup.Name = "Content"; foreach (var prop in fieldset.Properties) { var definition = _dataTypeService.GetDataTypeDefinitionById(prop.DataTypeGuid); propertyGroup.PropertyTypes.Add(new PropertyType(definition) { Name = prop.Label, Alias = prop.Alias, Mandatory = prop.Required, Description = prop.HelpText }); } contentType.PropertyGroups.Add(propertyGroup); } _contentTypeService.Save(contentType); var dataType = new DataTypeDefinition(NestedContentAlias); dataType.Name = contentType.Name; var preValues = new Dictionary <string, PreValue>(); preValues.Add("contentTypes", new PreValue(JsonConvert.SerializeObject( new NestedContentPreValue[] { new NestedContentPreValue { NcAlias = contentType.Alias, NcTabAlias = "Content", NameTemplate = archetypePreValue.Fieldsets.First().LabelTemplate } }, new JsonSerializerSettings { ContractResolver = _contractResolver }) )); preValues.Add("minItems", new PreValue("0")); preValues.Add("maxItems", new PreValue("0")); preValues.Add("confirmDeletes", new PreValue("0")); preValues.Add("showIcons", new PreValue("0")); preValues.Add("hideLabel", new PreValue(archetypePreValue.HidePropertyLabel ? "1" : "0")); _dataTypeService.SaveDataTypeAndPreValues(dataType, preValues); return(dataType); }