/// <summary>
 /// Initializes a new image picker item based on the specified <paramref name="image"/>, <paramref name="title"/>,
 /// <paramref name="description"/> and <paramref name="link"/>.
 /// </summary>
 /// <param name="image">An instance of <see cref="IPublishedContent"/> representing the selected image.</param>
 /// <param name="title">The title of the item.</param>
 /// <param name="description">The description of the item.</param>
 /// <param name="link">An instance of <see cref="LinkPickerItem"/> representing the link of the item.</param>
 public ImagePickerItem(ImagePickerImage image, string title, string description, LinkPickerItem link)
 {
     Image       = image;
     Title       = title;
     Description = description;
     Link        = link ?? LinkPickerItem.Parse(new JObject());
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the first link item from the <see cref="LinkPickerList"/> of the property with the specified
        /// <paramref name="propertyAlias"/>.
        ///
        /// If the property isn't a link picker (or the list is empty), an empty item
        /// will be returned instead. You can use the <see cref="LinkPickerItem.IsValid"/> property to check whether
        /// the returned item is valid.
        /// </summary>
        /// <param name="content">The published content to read the property from.</param>
        /// <param name="propertyAlias">The alias of the property.</param>
        /// <returns>An instance of <see cref="LinkPickerItem"/>.</returns>
        public static LinkPickerItem GetLinkPickerItem(this IPublishedContent content, string propertyAlias)
        {
            LinkPickerList list = content.GetPropertyValue(propertyAlias) as LinkPickerList;
            LinkPickerItem item = list?.Items.FirstOrDefault();

            return(item ?? new LinkPickerItem());
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            LinkPickerItem item = value as LinkPickerItem;

            if (item != null)
            {
                serializer.Serialize(writer, item.JObject);
            }
        }
 /// <summary>
 /// Initializes a new image picker item based on the specified <see cref="JObject"/>.
 /// </summary>
 /// <param name="obj">An instanceo of <see cref="JObject"/> representing the item.</param>
 protected ImagePickerItem(JObject obj)
 {
     JObject     = obj;
     Image       = obj.GetInt32("imageId", ImagePickerImage.GetFromId);
     Title       = obj.GetString("title") ?? "";
     Description = obj.GetString("description") ?? "";
     Link        = obj.GetObject("link", LinkPickerItem.Parse) ?? LinkPickerItem.Parse(new JObject());
     NoCrop      = obj.GetBoolean("nocrop");
 }
        private object ReadJsonObject(JsonReader reader, Type objectType)
        {
            JObject obj = JObject.Load(reader);

            if (!(objectType == typeof(LinkPickerItem)))
            {
                return(null);
            }
            if (obj != null)
            {
                return(LinkPickerItem.Parse(obj));
            }
            return(new LinkPickerItem());
        }
        /// <summary>Writes the JSON representation of the object.</summary>
        /// <param name="writer">The <see cref="JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is LinkPickerItem))
            {
                return;
            }
            LinkPickerItem linkPickerItem = (LinkPickerItem)value;

            if (linkPickerItem.IsValid)
            {
                serializer.Serialize(writer, linkPickerItem);
            }
            else
            {
                writer.WriteNull();
            }
        }
        public GridControlCtaValue(GridControl control) : base(control)
        {
            var blenderCtrl = GridControlLeBlenderValue.Parse(control);

            if (blenderCtrl == null || blenderCtrl.Items == null)
            {
                return;
            }
            var item = blenderCtrl.Items.First();

            Headline = item.GetRawValue("headline");

            Text = item.GetRawValue("text");

            Link = !string.IsNullOrEmpty(item.GetRawValue("link"))
                                ? LinkPickerList.Parse(JObject.Parse(item.GetRawValue("link"))).Items.FirstOrDefault()
                                : null;
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            // Skip if the reader is not at the start of an object
            if (reader.TokenType != JsonToken.StartObject)
            {
                return(null);
            }

            // Load JObject from stream
            JObject obj = JObject.Load(reader);

            switch (objectType.FullName)
            {
            case "Skybrud.LinkPicker.LinkPickerList":
                return(LinkPickerList.Parse(obj));

            case "Skybrud.LinkPicker.LinkPickerItem":
                return(LinkPickerItem.Parse(obj));

            default:
                return(null);
            }
        }