/// <summary> /// 解析提交的字段的值 /// </summary> public object Parse(FormField field, IList <string> values) { var attribute = (CheckBoxTreeFieldAttribute)field.Attribute; var parsed = JsonConvert.DeserializeObject <IList <string> >(values[0]); return(ListItemUtils.WrapValueAndProvider(attribute.Source, parsed)); }
/// <summary> /// 获取表单字段的html /// </summary> public string Build(FormField field, IDictionary <string, string> htmlAttributes) { var attribute = (CheckBoxTreeFieldAttribute)field.Attribute; var valueAndProvider = ListItemUtils.GetValueAndProvider <IListItemTreeProvider>( attribute.Source, field.Value); var value = valueAndProvider.First; var listItemTree = valueAndProvider.Second.GetTree(); var items = listItemTree.EnumerateAllNodes().Where(n => n.Value != null).Select(n => new { name = n.Value.Name, value = n.Value.Value, level = n.GetParents().Count() - 1 }); var templateManager = Application.Ioc.Resolve <TemplateManager>(); var fieldHtml = templateManager.RenderTemplate("common.base/tmpl.form.hidden.html", new { name = field.Attribute.Name, value = JsonConvert.SerializeObject(value ?? new string[0]), attributes = htmlAttributes }); var checkboxTree = templateManager.RenderTemplate("common.base/tmpl.checkbox_tree.html", new { items, fieldName = field.Attribute.Name, fieldHtml = new HtmlString(fieldHtml) }); return(field.WrapFieldHtml(htmlAttributes, checkboxTree)); }
/// <summary> /// 解析提交的字段的值 /// </summary> public object Parse(FormField field, IList <string> values) { var attribute = (RadioButtonsFieldAttribute)field.Attribute; var parsed = values[0]; return(ListItemUtils.WrapValueAndProvider(attribute.Source, parsed)); }
/// <summary> /// 解析提交的字段的值 /// </summary> public object Parse(FormField field, IList <string> values) { var attribute = (SearchableDropdownListFieldAttribute)field.Attribute; var parsed = values[0]; return(ListItemUtils.WrapValueAndProvider(attribute.Source, parsed)); }
/// <summary> /// 获取表单字段的html /// </summary> public string Build(FormField field, IDictionary <string, string> htmlAttributes) { var attribute = (CheckBoxGroupFieldAttribute)field.Attribute; var valueAndProvider = ListItemUtils.GetValueAndProvider <IListItemProvider>( attribute.Source, field.Value); var value = valueAndProvider.First; var listItems = valueAndProvider.Second.GetItems().ToList(); var templateManager = Application.Ioc.Resolve <TemplateManager>(); var fieldHtml = templateManager.RenderTemplate("common.base/tmpl.form.hidden.html", new { name = field.Attribute.Name, value = JsonConvert.SerializeObject(value ?? new string[0]), attributes = htmlAttributes }); var checkboxGroup = templateManager.RenderTemplate("common.base/tmpl.checkbox_group.html", new { items = listItems, fieldName = field.Attribute.Name, fieldHtml = new HtmlString(fieldHtml) }); return(field.WrapFieldHtml(htmlAttributes, checkboxGroup)); }
/// <summary> /// 构建单选按钮组的Html /// </summary> public static HtmlString BuildRadioButtonsHtml( RadioButtonsFieldAttribute attribute, IDictionary <string, string> htmlAttributes, object value) { var valueAndProvider = ListItemUtils.GetValueAndProvider <IListItemProvider>( attribute.Source, value); var listItems = valueAndProvider.Second.GetItems().ToList(); var valueString = (valueAndProvider.First is Enum) ? ((int)valueAndProvider.First).ToString() : valueAndProvider.First.ConvertOrDefault <string>(); var templateManager = Application.Ioc.Resolve <TemplateManager>(); var radioList = templateManager.RenderTemplate("common.base/tmpl.form.radio_list.html", new { name = attribute.Name, attributes = htmlAttributes, options = listItems.Select(item => new { name = item.Name, value = item.Value, selected = item.Value == valueString }) }); return(new HtmlString(radioList)); }