public static void SaveValue(Widget editor, PropertyItem item, dynamic target) { var getEditValue = editor as IGetEditValue; if (getEditValue != null) getEditValue.GetEditValue(item, target); else { var stringValue = editor as IStringValue; if (stringValue != null) target[item.Name] = stringValue.Value; else { var booleanValue = editor as IBooleanValue; if (booleanValue != null) target[item.Name] = booleanValue.Value; else { var doubleValue = editor as IDoubleValue; if (doubleValue != null) { var value = doubleValue.Value; target[item.Name] = Double.IsNaN(value.As<double>()) ? null : value; } else if (editor.Element.Is(":input")) { target[item.Name] = editor.Element.GetValue(); } } } } }
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>()); } } } }
public static SlickColumn ToSlickColumn(PropertyItem item) { var result = new SlickColumn(); result.SourceItem = item; result.Visible = item.Visible != false && item.FilterOnly != true && (item.ReadPermission == null || Q.Authorization.HasPermission(item.ReadPermission)); result.Field = item.Name; result.Title = Q.TryGetText(item.Title) ?? item.Title; result.CssClass = item.CssClass; result.HeaderCssClass = item.HeaderCssClass; result.Sortable = item.Sortable != false; result.SortOrder = item.SortOrder ?? 0; if (Script.IsValue(item.Alignment) && item.Alignment.Length > 0) { if (!result.CssClass.IsEmptyOrNull()) result.CssClass += " align-" + item.Alignment; else result.CssClass = "align-" + item.Alignment; } result.Width = Script.IsValue(item.Width) ? item.Width : 80; result.MinWidth = item.MinWidth ?? 30; result.MaxWidth = (item.MaxWidth == null || item.MaxWidth == 0) ? null : item.MaxWidth; result.Resizable = item.Resizable == null || item.Resizable.Value; if (Script.IsValue(item.FormatterType) && item.FormatterType.Length > 0) { var formatter = (ISlickFormatter)Activator.CreateInstance(FormatterTypeRegistry.Get(item.FormatterType)); if (item.FormatterParams != null) ReflectionOptionsSetter.Set(formatter, item.FormatterParams); var initializer = formatter as IInitializeColumn; if (initializer != null) initializer.InitializeColumn(result); result.Format = formatter.Format; } return result; }
public static SlickColumn ToSlickColumn(PropertyItem item) { var result = new SlickColumn(); result.SourceItem = item; result.Field = item.Name; result.Title = Q.TryGetText(item.Title) ?? item.Title; result.CssClass = item.CssClass; result.SortOrder = item.SortOrder; if (Script.IsValue(item.Alignment) && item.Alignment.Length > 0) { if (!result.CssClass.IsEmptyOrNull()) result.CssClass += " align-" + item.Alignment; else result.CssClass = "align-" + item.Alignment; } result.Width = Script.IsValue(item.Width) ? item.Width : 80; result.MinWidth = (!Script.IsValue(item.MinWidth) || item.MinWidth == 0) ? 30 : item.MinWidth; result.MaxWidth = (!Script.IsValue(item.MaxWidth) || item.MaxWidth == 0) ? null : (int?)item.MaxWidth; result.Resizable = !Script.IsValue(item.Resizable) || item.Resizable; if (Script.IsValue(item.FormatterType) && item.FormatterType.Length > 0) { var formatter = (ISlickFormatter)Activator.CreateInstance(FormatterTypeRegistry.Get(item.FormatterType)); if (item.FormatterParams != null) ReflectionOptionsSetter.Set(formatter, item.FormatterParams); var initializer = formatter as IInitializeColumn; if (initializer != null) initializer.InitializeColumn(result); result.Format = formatter.Format; } return result; }
public void SetEditValue(dynamic source, PropertyItem property) { Value = source[property.Name]; }
public void GetEditValue(PropertyItem property, dynamic target) { target[property.Name] = this.Value; }
protected virtual string GetTitle(PropertyItem field) { return Q.TryGetText(field.Title) ?? field.Title ?? field.Name; }
public static List<PropertyItem> GetPropertyItemsFor(Type type) { if (type == null) throw new Exception("type"); var list = new List<PropertyItem>(); foreach (var member in type.GetMembers(BindingFlags.Public | BindingFlags.Instance)) { PropertyItem pi = new PropertyItem(); if (member.MemberType != MemberTypes.Property && member.MemberType != MemberTypes.Field) continue; var hiddenAttribute = member.GetCustomAttributes(typeof(HiddenAttribute), false); if (hiddenAttribute.Length > 0) continue; var displayNameAttribute = member.GetCustomAttributes(typeof(DisplayNameAttribute), false); var hintAttribute = member.GetCustomAttributes(typeof(HintAttribute), false); var placeholderAttribute = member.GetCustomAttributes(typeof(PlaceholderAttribute), false); Type memberType = member.MemberType == MemberTypes.Property ? ((PropertyInfo)member).PropertyType : ((FieldInfo)member).FieldType; if (member.MemberType == MemberTypes.Property) { var p = (PropertyInfo)member; if (p.ScriptFieldName == null) // şu an sadece serializable destekliyoruz! continue; pi.Name = p.ScriptFieldName; } else if (member.MemberType == MemberTypes.Field) { var f = (FieldInfo)member; pi.Name = f.ScriptName; } else continue; var categoryAttribute = member.GetCustomAttributes(typeof(CategoryAttribute), false); if (categoryAttribute.Length > 0) pi.Category = ((CategoryAttribute)categoryAttribute[0]).Category; else if (list.Count > 0) pi.Category = list[list.Count - 1].Category; var collapsibleAttribute = member.GetCustomAttributes(typeof(CollapsibleAttribute), false); if (collapsibleAttribute.Length > 0 && ((CollapsibleAttribute)collapsibleAttribute[0]).Value) { pi.Collapsible = true; pi.Collapsed = ((CollapsibleAttribute)collapsibleAttribute[0]).Collapsed; } var cssClassAttr = member.GetCustomAttributes(typeof(CssClassAttribute), false); if (cssClassAttr.Length > 0) pi.CssClass = ((CssClassAttribute)cssClassAttr[0]).CssClass; if (member.GetCustomAttributes(typeof(OneWayAttribute), false).Length > 0) pi.OneWay = true; if (member.GetCustomAttributes(typeof(ReadOnlyAttribute), false).Length > 0) pi.ReadOnly = true; if (displayNameAttribute.Length > 0) pi.Title = ((DisplayNameAttribute)displayNameAttribute[0]).DisplayName; if (hintAttribute.Length > 0) pi.Hint = ((HintAttribute)hintAttribute[0]).Hint; if (placeholderAttribute.Length > 0) pi.Placeholder = ((PlaceholderAttribute)placeholderAttribute[0]).Value; if (pi.Title == null) pi.Title = pi.Name; var defaultValueAttribute = member.GetCustomAttributes(typeof(DefaultValueAttribute), false); if (defaultValueAttribute.Length == 1) pi.DefaultValue = ((DefaultValueAttribute)defaultValueAttribute[0]).Value; var insertableAttribute = member.GetCustomAttributes(typeof(InsertableAttribute), false); if (insertableAttribute.Length > 0) pi.Insertable = insertableAttribute[0].As<InsertableAttribute>().Value; else pi.Insertable = true; var updatableAttribute = member.GetCustomAttributes(typeof(UpdatableAttribute), false); if (updatableAttribute.Length > 0) pi.Updatable = updatableAttribute[0].As<UpdatableAttribute>().Value; else pi.Updatable = true; var typeAttrArray = member.GetCustomAttributes(typeof(EditorTypeAttribute), false); Type nullableType = memberType;//Nullable.GetUnderlyingType(memberType); Type enumType = null; if (memberType.IsEnum) enumType = memberType; else if (nullableType != null && nullableType.IsEnum) enumType = nullableType; if (typeAttrArray.Length == 0) { if (enumType != null) pi.EditorType = "Select"; else if (memberType == typeof(JsDate)) pi.EditorType = "Date"; else if (memberType == typeof(Boolean)) pi.EditorType = "Boolean"; else if (memberType == typeof(Decimal) || memberType == typeof(Double)) pi.EditorType = "Decimal"; else if (memberType == typeof(Int32)) pi.EditorType = "Integer"; else pi.EditorType = "String"; } else { var et = ((EditorTypeAttribute)typeAttrArray[0]); pi.EditorType = et.EditorType; et.SetParams(pi.EditorParams); } var reqAttr = member.GetCustomAttributes(typeof(RequiredAttribute), true); if (reqAttr.Length > 0) pi.Required = reqAttr[0].As<RequiredAttribute>().IsRequired; var maxLengthAttr = member.GetCustomAttributes(typeof(MaxLengthAttribute), false); if (maxLengthAttr.Length > 0) { pi.MaxLength = maxLengthAttr.As<MaxLengthAttribute>().MaxLength; pi.EditorParams["maxLength"] = pi.MaxLength; } foreach (EditorOptionAttribute param in member.GetCustomAttributes(typeof(EditorOptionAttribute), false)) { var key = param.Key; if (key != null && key.Length >= 1) key = key.Substring(0, 1).ToLower() + key.Substring(1); pi.EditorParams[key] = param.Value; } list.Add(pi); } return list; }
protected virtual string GetTitle(PropertyItem field) { return(Q.TryGetText(field.Title) ?? field.Title ?? field.Name); }
public static void LoadValue(Widget editor, PropertyItem item, dynamic source) { var setEditValue = editor as ISetEditValue; if (setEditValue != null) { setEditValue.SetEditValue(source, item); return; } var stringValue = editor as IStringValue; if (stringValue != null) { var value = source[item.Name]; if (value != null) { value = value.toString(); } stringValue.Value = value; return; } var booleanValue = editor as IBooleanValue; if (booleanValue != null) { object value = source[item.Name]; if (Script.TypeOf(value) == "number") { booleanValue.Value = value.As <double>() > 0; } else { booleanValue.Value = Q.IsTrue(value); } return; } 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; } return; } if (Script.IsValue((editor as dynamic).setEditValue)) { (editor as dynamic).setEditValue(source, item); return; } 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>()); } return; } }