public BsEditorHtmlBuilder(TModel model, ViewContext viewContext) : base(viewContext) { this.viewContext = viewContext; this.renderer = new BsEditorRenderer <TModel>(this); this.tabConfigurator = new BsEditorTabConfigurator <TModel>(viewContext); this.groupConfigurator = new BsEditorGroupConfigurator <TModel>(viewContext); var type = typeof(TModel); var props = type.GetProperties(); var editableTabIds = new List <object>(); // find out what tabs are editable to send to group configurator TODO refactor somehow (3 foreach ..) foreach (var prop in props) { BsEditorTabAttribute tabAttr = null; if (ReflectionHelpers.TryGetAttribute(prop, out tabAttr)) { if (tabAttr.Editable) { editableTabIds.Add(tabAttr.Id); } } } //if (!this.IsAjaxRequest()) // we don't care about groups // { foreach (var prop in props) { BsEditorGroupAttribute groupAttr = null; if (ReflectionHelpers.TryGetAttribute(prop, out groupAttr)) { var value = prop.GetValue(model); InvokeAddGroupConfig(value, prop, groupAttr, editableTabIds); // TODO send editableTabIds } } // } foreach (var prop in props) { BsEditorTabAttribute tabAttr = null; if (ReflectionHelpers.TryGetAttribute(prop, out tabAttr)) { tabConfigurator.AddNavTab(tabAttr); var value = prop.GetValue(model); InvokeAddTabConfig(value, prop, tabAttr); // this has to happen after group configuration } } }
private void InvokeAddTabConfig(object value, PropertyInfo prop, BsEditorTabAttribute attr) { var propertyType = prop.PropertyType; if (!propertyType.GetInterfaces().Contains(typeof(IBsEditorTabModel))) { throw new Exception("The model with BsEditorTabAttribute must inherit BsEditorTabModel"); } var genericArgs = propertyType.GetGenericArguments(); var count = genericArgs.Count(); if (count == 0) { var baseType = propertyType.BaseType; genericArgs = baseType.GetGenericArguments(); count = genericArgs.Count(); } if (count > 0) { MethodInfo method = null, generic = null; Type rowType = genericArgs[0]; method = typeof(BsEditorTabConfigurator <TModel>).GetMethod("Add", this.Bindings()); generic = method.MakeGenericMethod(propertyType, rowType); generic.Invoke(this.tabConfigurator, new object[] { attr, value, this.groupConfigurator.Connections, this.groupConfigurator.GetGroupIds(), this.Theme }); } }
private BsEditorTabBuilder GetTab <TValue>(Expression <Func <TModel, TValue> > expression) { var prop = expression.GetPropertyInfo <TModel, TValue>(); BsEditorTabAttribute attr = null; if (ReflectionHelpers.TryGetAttribute(prop, out attr)) { var id = attr.Id; return(this.Tabs[id]); } throw new Exception("Property " + prop.Name + " has no BsGroupEditorAttribute"); }
private void Add <TEditor, TRow>(BsEditorTabAttribute attr, BsEditorTabModel <TRow> model, List <TabGroupConnection> connections, object[] groupIds, BsTheme theme) where TEditor : IBsEditorTabModel where TRow : BsItemModel { var tab = new BsEditorTabBuilder <TEditor>(model, this.viewContext, connections).ConnectsWith(groupIds) .DisplayName(attr.Name) .Id(attr.Id) .Selected(attr.Selected); if (attr.Editable) { tab.Editable(); } tab.InitRenderer <TRow>(theme); if (attr.Selected) { navBuilder.Selected(attr.Id); } InsertTab <TEditor, TRow>(attr.Id, tab); }
public BsEditorNavBuilder AddTab(BsEditorTabAttribute attr) { this.TabsProperties.Add(attr); return(this); }
internal void AddNavTab(BsEditorTabAttribute attr) { navBuilder.AddTab(attr); }