Exemplo n.º 1
0
        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
                }
            }
        }
Exemplo n.º 2
0
        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 });
            }
        }
Exemplo n.º 3
0
        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");
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public BsEditorNavBuilder AddTab(BsEditorTabAttribute attr)
        {
            this.TabsProperties.Add(attr);

            return(this);
        }
Exemplo n.º 6
0
 internal void AddNavTab(BsEditorTabAttribute attr)
 {
     navBuilder.AddTab(attr);
 }