Ejemplo n.º 1
0
        private IFiltering GetFilteringFor(jQueryObject row)
        {
            var field = GetFieldFor(row);

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

            IFiltering filtering = (IFiltering)row.GetDataValue("Filtering");

            if (filtering != null)
            {
                return(filtering);
            }

            var filteringType = FilteringTypeRegistry.Get(field.FilteringType ?? "String");

            jQueryObject editorDiv = row.Children("div.v");

            filtering = (IFiltering)Activator.CreateInstance(filteringType);
            ReflectionOptionsSetter.Set(filtering, field.FilteringParams);
            filtering.Container = editorDiv;
            filtering.Field     = field;
            row.Data("Filtering", filtering);

            return(filtering);
        }
        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);
        }
Ejemplo n.º 4
0
        private Widget CreateField(jQueryObject container, PropertyItem item)
        {
            var fieldDiv = J("<div/>")
                           .AddClass("field")
                           .AddClass(item.Name)
                           .Data("PropertyItem", item)
                           .AppendTo(container);

            if (!String.IsNullOrEmpty(item.CssClass))
            {
                fieldDiv.AddClass(item.CssClass);
            }

            string editorId = options.IdPrefix + item.Name;

            string title       = DetermineText(item.Title, prefix => prefix + item.Name);
            string hint        = DetermineText(item.Hint, prefix => prefix + item.Name + "_Hint");
            string placeHolder = DetermineText(item.Placeholder, prefix => prefix + item.Name + "_Placeholder");

            var label = J("<label/>")
                        .AddClass("caption")
                        .Attribute("for", editorId)
                        .Attribute("title", hint ?? title ?? "")
                        .Html(title ?? "")
                        .AppendTo(fieldDiv);

            if (item.Required == true)
            {
                J("<sup>*</sup>")
                .Attribute("title", Q.Text("Controls.PropertyGrid.RequiredHint"))
                .PrependTo(label);
            }

            var    editorType  = EditorTypeRegistry.Get(item.EditorType ?? "String");
            var    elementAttr = editorType.GetCustomAttributes(typeof(ElementAttribute), true);
            string elementHtml = (elementAttr.Length > 0) ? elementAttr[0].As <ElementAttribute>().Value : "<input/>";

            var element = Widget.ElementFor(editorType)
                          .AddClass("editor")
                          .AddClass("flexify")
                          .Attribute("id", editorId)
                          .AppendTo(fieldDiv);

            if (element.Is(":input"))
            {
                element.Attribute("name", item.Name ?? "");
            }

            if (!placeHolder.IsEmptyOrNull())
            {
                element.Attribute("placeholder", placeHolder);
            }

            object editorParams = item.EditorParams;
            Type   optionsType  = null;
            var    optionsAttr  = editorType.GetCustomAttributes(typeof(OptionsTypeAttribute), true);

            if (optionsAttr != null && optionsAttr.Length > 0)
            {
                optionsType = optionsAttr[0].As <OptionsTypeAttribute>().OptionsType;
            }

            Widget editor;

            if (optionsType != null)
            {
                editorParams = jQuery.ExtendObject(Activator.CreateInstance(optionsType), item.EditorParams);

                editor = (Widget)(Activator.CreateInstance(editorType, element, editorParams));
            }
            else
            {
                editorParams = jQuery.ExtendObject(new object(), item.EditorParams);
                editor       = (Widget)(Activator.CreateInstance(editorType, element, editorParams));
            }

            editor.Initialize();

            if (editor is BooleanEditor && (item.EditorParams == null || !Q.IsTrue(item.EditorParams["labelFor"])))
            {
                label.RemoveAttr("for");
            }

            if (Script.IsValue(item.MaxLength))
            {
                SetMaxLength(editor, item.MaxLength.Value);
            }

            if (item.EditorParams != null)
            {
                ReflectionOptionsSetter.Set(editor, item.EditorParams);
            }

            J("<div/>")
            .AddClass("vx")
            .AppendTo(fieldDiv);

            J("<div/>")
            .AddClass("clear")
            .AppendTo(fieldDiv);

            return(editor);
        }