Beispiel #1
0
 void ViewController_ItemCreated(object sender, ItemCreatedEventArgs e)
 {
     if (e.TemplateContainer is LayoutItemTemplateContainer)
     {
         string nullText = GetNullText(e.ModelLayoutElement);
         if (!string.IsNullOrEmpty(nullText))
         {
             ViewItem viewItem = (e.TemplateContainer).ViewItem;
             if (viewItem.Control == null)
             {
                 viewItem.CreateControl();
             }
             SetNullText(viewItem, nullText);
         }
     }
 }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (ViewItem != null)
            {
                String         ModelID = "";
                IModelViewItem Model   = null;
                if (ViewItem is PropertyEditor)
                {
                    ModelID = (ViewItem as PropertyEditor).Model.Id;
                    Model   = (ViewItem as PropertyEditor).Model as IModelViewItem;
                }
                else
                {
                    if (ViewItem.GetType().GetProperty("Model") != null)
                    {
                        Model   = (IModelViewItem)ViewItem.GetType().GetProperty("Model").GetValue(ViewItem);
                        ModelID = Model.Id;
                    }
                }

                ViewItemResponsive responsive = ViewItemResponsive.Default;
                if (Model != null && (Model is IModelBootstrapViewItemResponsive))
                {
                    responsive = (Model as IModelBootstrapViewItemResponsive).ContainerResponsive;
                }

                Func <String> controlsCreatedFunc = () =>
                {
                    var innerView = (ViewItem as DashboardViewItem).InnerView;
                    if (innerView != null && innerView is DetailView && ViewItem.View is DetailView)
                    {
                        (innerView as DetailView).ViewEditMode = (ViewItem.View as DetailView).ViewEditMode;
                        if (innerView.CurrentObject == null)
                        {
                            innerView.CurrentObject = innerView.ObjectSpace.FindObject((innerView as DetailView).Model.ModelClass.TypeInfo.Type, CriteriaOperator.Parse((ViewItem as DashboardViewItem).Model.Criteria), true);
                        }

                        ViewItem.View.ObjectSpace.Committed += new EventHandler(delegate
                        {
                            innerView.ObjectSpace.CommitChanges();
                        });

                        ViewItem.View.ObjectSpace.RollingBack += new EventHandler <System.ComponentModel.CancelEventArgs>(delegate
                        {
                            innerView.ObjectSpace.Rollback();
                        });

                        ViewItem.View.ObjectSpace.Refreshing += new EventHandler <System.ComponentModel.CancelEventArgs>(delegate
                        {
                            innerView.ObjectSpace.Refresh();
                        });
                    }
                    return("");
                };

                if (ViewItem is WebPropertyEditor)
                {
                    (ViewItem as WebPropertyEditor).AllowEdit["XafBootstrapAllowEdit"] = !(ModelID != "" && BootstrapView != null && BootstrapView.DisabledItems.IndexOf(ModelID) > -1);
                    if ((ViewItem as WebPropertyEditor).CurrentObject == null && ViewItem.View is DetailView)
                    {
                        ViewItem.CurrentObject = (ViewItem.View as DetailView).CurrentObject;
                    }
                }
                else
                if (ViewItem is DashboardViewItem)
                {
                    (ViewItem as DashboardViewItem).ControlCreated += new EventHandler <EventArgs>(delegate
                    {
                        controlsCreatedFunc();
                    });
                }

                if (ViewItem.Control == null)
                {
                    ViewItem.CreateControl();
                }
                else
                if (ViewItem is DashboardViewItem)
                {
                    controlsCreatedFunc();
                }

                if (ViewItem.Control != null && ViewItem.Control is Control)
                {
                    Controls.Clear();
                    var Control = ViewItem.Control as Control;
                    int i       = 0;
                    var ID      = Control.ID;
                    while (BootstrapView.ControlUniqueIDList.IndexOf(Control.ID) > -1)
                    {
                        Control.ID = ID + i.ToString();
                        i++;
                    }
                    BootstrapView.ControlUniqueIDList.Add(Control.ID);
                    if (ViewItem is IXafBootstrapEditor ||
                        (ViewItem is ListPropertyEditor && (ViewItem as ListPropertyEditor).ListView != null && (ViewItem as ListPropertyEditor).ListView.Editor is IXafBootstrapListEditor)
                        )
                    {
                        Controls.Add(Control);
                    }
                    else if (ViewItem is DashboardViewItem && (ViewItem as DashboardViewItem).View is DetailView || responsive == ViewItemResponsive.AsIs)
                    {
                        Controls.Add(Control);
                    }
                    else
                    {
                        Controls.Add(new HTMLText()
                        {
                            Text = "<div class='table-responsive'>"
                        });
                        Controls.Add(Control);
                        Controls.Add(new HTMLText()
                        {
                            Text = "</div>"
                        });
                    }
                }
            }
        }