Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Laurence Gillian 600 posts 1219 karma points
    Feb 02, 2016 @ 18:54
    Laurence Gillian
    3

    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;
        }
    
    }
    

    p.s I resolved my own question ;-)

    NuPickers in Action in the Grid!

Please Sign in or register to post replies

Write your reply to:

Draft