Provides extension methods to work with identity values
Exemplo n.º 1
0
        protected virtual dynamic GetItemMetadata(TItem entity, int index)
        {
            var activeFieldName = GetIsActiveFieldName();

            if (activeFieldName.IsEmptyOrNull())
            {
                return(new object());
            }

            var value = entity.As <JsDictionary>()[activeFieldName].As <Int32?>();

            if (value == null)
            {
                return(new object());
            }

            if (Script.TypeOf(value) == "number")
            {
                if (IdExtensions.IsNegativeId(value.As <Int64>()))
                {
                    return new { cssClasses = "deleted" }
                }
                ;
                else if (value.As <Int32>() == 0)
                {
                    return new { cssClasses = "inactive" }
                }
                ;
            }
            else if (Script.TypeOf(value) == "boolean")
            {
                if (value.As <Boolean>() == false)
                {
                    return new { cssClasses = "deleted" }
                }
                ;
            }

            return(new object());
        }
Exemplo n.º 2
0
        protected virtual string GetItemCssClass(TItem item, int index)
        {
            var activeFieldName = GetIsActiveFieldName();

            if (activeFieldName.IsEmptyOrNull())
            {
                return(null);
            }

            var value = item.As <JsDictionary>()[activeFieldName].As <Int32?>();

            if (value == null)
            {
                return(null);
            }

            if (Script.TypeOf(value) == "number")
            {
                if (IdExtensions.IsNegativeId(value.As <Int64>()))
                {
                    return("deleted");
                }
                else if (value.As <Int32>() == 0)
                {
                    return("inactive");
                }
            }
            else if (Script.TypeOf(value) == "boolean")
            {
                if (value.As <Boolean>() == false)
                {
                    return("deleted");
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public static void LoadValue(Widget editor, PropertyItem item, dynamic source)
        {
            var setEditValue = editor as ISetEditValue;

            if (setEditValue != null)
            {
                setEditValue.SetEditValue(source, item);
            }

            var stringValue = editor as IStringValue;

            if (stringValue != null)
            {
                var value = source[item.Name];
                if (value != null)
                {
                    value = value.toString();
                }
                stringValue.Value = value;
            }
            else
            {
                var booleanValue = editor as IBooleanValue;
                if (booleanValue != null)
                {
                    object value = source[item.Name];
                    if (Script.TypeOf(value) == "number")
                    {
                        booleanValue.Value = IdExtensions.IsPositiveId(value.As <Int64>());
                    }
                    else
                    {
                        booleanValue.Value = Q.IsTrue(value);
                    }
                }
                else
                {
                    var doubleValue = editor as IDoubleValue;
                    if (doubleValue != null)
                    {
                        var d = source[item.Name];
                        if (d == null || (d is string && Q.IsTrimmedEmpty(d)))
                        {
                            doubleValue.Value = null;
                        }
                        else if (d is string)
                        {
                            doubleValue.Value = Q.ParseDecimal(d);
                        }
                        else if (d is Boolean)
                        {
                            doubleValue.Value = (Boolean)d ? 1 : 0;
                        }
                        else
                        {
                            doubleValue.Value = d;
                        }
                    }
                    else if (editor.Element.Is(":input"))
                    {
                        var v = source[item.Name];
                        if (!Script.IsValue(v))
                        {
                            editor.Element.Value("");
                        }
                        else
                        {
                            editor.Element.Value(((object)v).As <string>());
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Load(dynamic source)
        {
            for (var i = 0; i < editors.Count; i++)
            {
                var item   = items[i];
                var editor = editors[i];

                if (Mode == PropertyGridMode.Insert &&
                    !Script.IsNullOrUndefined(item.DefaultValue) &&
                    Script.IsUndefined(source[item.Name]))
                {
                    source[item.Name] = item.DefaultValue;
                }

                var setEditValue = editor as ISetEditValue;
                if (setEditValue != null)
                {
                    setEditValue.SetEditValue(source, item);
                }

                var stringValue = editor as IStringValue;
                if (stringValue != null)
                {
                    var value = source[item.Name];
                    if (value != null)
                    {
                        value = value.toString();
                    }
                    stringValue.Value = value;
                }
                else
                {
                    var booleanValue = editor as IBooleanValue;
                    if (booleanValue != null)
                    {
                        object value = source[item.Name];
                        if (Script.TypeOf(value) == "number")
                        {
                            booleanValue.Value = IdExtensions.IsPositiveId(value.As <Int64>());
                        }
                        else
                        {
                            booleanValue.Value = Q.IsTrue(value);
                        }
                    }
                    else
                    {
                        var doubleValue = editor as IDoubleValue;
                        if (doubleValue != null)
                        {
                            var d = source[item.Name];
                            if (d == null || (d is string && Q.IsTrimmedEmpty(d)))
                            {
                                doubleValue.Value = null;
                            }
                            else if (d is string)
                            {
                                doubleValue.Value = Q.ParseDecimal(d);
                            }
                            else if (d is Boolean)
                            {
                                doubleValue.Value = (Boolean)d ? 1 : 0;
                            }
                            else
                            {
                                doubleValue.Value = d;
                            }
                        }
                        else if (editor.Element.Is(":input"))
                        {
                            var v = source[item.Name];
                            if (!Script.IsValue(v))
                            {
                                editor.Element.Value("");
                            }
                            else
                            {
                                editor.Element.Value(((object)v).As <string>());
                            }
                        }
                    }
                }
            }
        }