コード例 #1
0
 public static void SetReadOnly(Widget widget, bool isReadOnly)
 {
     EditorUtils.SetReadOnly(widget, isReadOnly);
 }
コード例 #2
0
 public static void SetRequired(Widget widget, bool isRequired)
 {
     EditorUtils.SetRequired(widget, isRequired);
 }
コード例 #3
0
 public static void LoadEditorValue(Widget editor, PropertyItem item, dynamic source)
 {
 }
コード例 #4
0
 public static void SaveEditorValue(Widget editor, PropertyItem item, dynamic target)
 {
     EditorUtils.SaveValue(editor, item, target);
 }
コード例 #5
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);

            if (!String.IsNullOrEmpty(item.FormCssClass))
            {
                fieldDiv.AddClass(item.FormCssClass);
                if (item.FormCssClass.IndexOf("line-break-") >= 0)
                {
                    var splitted = item.FormCssClass.Split(' ');
                    if (splitted.IndexOf("line-break-xs") >= 0)
                        J("<div class='line-break' style='width: 100%' />").InsertBefore(fieldDiv);
                    else if (splitted.IndexOf("line-break-sm") >= 0)
                        J("<div class='line-break hidden-xs' style='width: 100%' />").InsertBefore(fieldDiv);
                    else if (splitted.IndexOf("line-break-md") >= 0)
                        J("<div class='line-break hidden-sm' style='width: 100%' />").InsertBefore(fieldDiv);
                    else if (splitted.IndexOf("line-break-lg") >= 0)
                        J("<div class='line-break hidden-md' style='width: 100%' />").InsertBefore(fieldDiv);
                }
            }

            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 (!string.IsNullOrEmpty(item.LabelWidth))
            {
                if (item.LabelWidth == "0")
                    label.Hide();
                else
                    label.CSS("width", item.LabelWidth);
            }

            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 (editor is RadioButtonEditor && (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;
        }