Using NuPickers to Pick a Crop from Umbraco.ImageCropper datatype
As part of my exploration on using the Umbraco Grid, I wanted to create a datatype that allowed content editors to:
Pick image(s)
Control how many are shown on each row (e.g. 1, 2 or 4)
If required apply a crop to the selected images
So I used the DotNot Radiobutton control, to allow me to grab the Crops from the Umbraco Image Cropper datatype.
I'm sharing the code here, as although it's really simple, it took me a few hours of poking about to figure out the data was stored as JSON, etc, etc! Basically this could help someone searching in the future! :-D
So!
using System.Collections.Generic;
using nuPickers.Shared.DotNetDataSource;
using umbraco;
using System.Web.Helpers;
using System.Linq;
public class Crops : IDotNetDataSource
{
IEnumerable<KeyValuePair<string, string>> IDotNetDataSource.GetEditorDataItems(int contextId)
{
// return a collection of key / labels for picker
Dictionary<string, string> dict = new Dictionary<string, string>(2);
var preValuesFromDataType = library.GetPreValues(1043);
var iterator = preValuesFromDataType.Current.SelectChildren("preValues", "");
dynamic data = Json.Decode(iterator.Current.ToString());
foreach (var item in data)
{
dict.Add(item.alias, item.alias); // key must be unique
}
return dict;
}
}
Using NuPickers to Pick a Crop from Umbraco.ImageCropper datatype
As part of my exploration on using the Umbraco Grid, I wanted to create a datatype that allowed content editors to:
So I used the DotNot Radiobutton control, to allow me to grab the Crops from the Umbraco Image Cropper datatype.
I'm sharing the code here, as although it's really simple, it took me a few hours of poking about to figure out the data was stored as JSON, etc, etc! Basically this could help someone searching in the future! :-D
So!
p.s I resolved my own question ;-)
is working on a reply...