public void GetUrlHelperFromRegularPage()
        {
            // Arrange
            ViewUserControl vuc           = new ViewUserControl();
            Page            containerPage = new Page();

            containerPage.Controls.Add(vuc);

            // Assert
            Assert.Throws <InvalidOperationException>(
                delegate
            {
                UrlHelper foo = vuc.Url;
            },
                "A ViewUserControl can be used only in pages that derive from ViewPage or ViewPage<TModel>."
                );
        }
        public void ModelPropertyStronglyTyped()
        {
            // Arrange
            FooModel model = new FooModel();
            ViewDataDictionary <FooModel> viewData        = new ViewDataDictionary <FooModel>(model);
            ViewUserControl <FooModel>    viewUserControl = new ViewUserControl <FooModel>();

            viewUserControl.ViewData = viewData;

            // Act
            object   viewPageModelObject = ((ViewUserControl)viewUserControl).Model;
            FooModel viewPageModelPerson = viewUserControl.Model;

            // Assert
            Assert.Equal(model, viewPageModelObject);
            Assert.Equal(model, viewPageModelPerson);
        }
Beispiel #3
0
        public void ViewBagProperty_PropagatesChangesToViewData()
        {
            // Arrange
            ViewPage        containerPage = new ViewPage();
            ViewUserControl userControl   = new ViewUserControl();

            containerPage.Controls.Add(userControl);
            userControl.ViewData["A"] = 1;

            // Act
            userControl.ViewBag.A = "foo";
            userControl.ViewBag.B = 2;

            // Assert
            Assert.Equal("foo", userControl.ViewData["A"]);
            Assert.Equal(2, userControl.ViewData["B"]);
        }
        public void SetViewItemToWrongTypeThrows()
        {
            // Arrange
            ViewUserControl <string> vucString = new ViewUserControl <string>();

            vucString.ViewData = new ViewDataDictionary <string>();
            ViewUserControl vuc = vucString;

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                delegate
            {
                vuc.ViewData.Model = 50;
            },
                "The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'System.String'."
                );
        }
Beispiel #5
0
        public static string DynamicField(this HtmlHelper html, object entity, MetaColumn column, string uiHint, DataBoundControlMode mode)
        {
            var host = new SimpleFieldTemplateHost()
            {
                Column = column, Mode = mode
            };

            IFieldTemplate  fieldTemplate        = MetaModel.Default.FieldTemplateFactory.CreateFieldTemplate(column, mode, uiHint ?? column.UIHint);
            ViewUserControl fieldTemplateControl = fieldTemplate as ViewUserControl;

            if (fieldTemplateControl == null)
            {
                throw new InvalidOperationException("Cannot render a dynamic field whose field template is not a ViewUserControl");
            }

            fieldTemplate.SetHost(host);
            return(html.RenderViewUserControl(fieldTemplateControl, entity));
        }
        public void GetUrlHelperFromViewPage()
        {
            // Arrange
            ViewUserControl vuc           = new ViewUserControl();
            ViewPage        containerPage = new ViewPage();

            containerPage.Controls.Add(vuc);
            RequestContext rc = new RequestContext(
                new Mock <HttpContextBase>().Object,
                new RouteData()
                );
            UrlHelper urlHelper = new UrlHelper(rc);

            containerPage.Url = urlHelper;

            // Assert
            Assert.Equal(vuc.Url, urlHelper);
        }
        public void GetViewDataWhenRegularPageSetThrows()
        {
            Page p = new Page();

            p.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl();

            p.Controls[0].Controls.Add(vuc);
            vuc.AppRelativeVirtualPath = "~/Foo.ascx";

            Assert.Throws <InvalidOperationException>(
                delegate
            {
                var foo = vuc.ViewData["Foo"];
            },
                "The ViewUserControl '~/Foo.ascx' cannot find an IViewDataContainer object. The ViewUserControl must be inside a ViewPage, a ViewMasterPage, or another ViewUserControl."
                );
        }
        public void GetHtmlHelperFromViewPage()
        {
            // Arrange
            ViewUserControl vuc           = new ViewUserControl();
            ViewPage        containerPage = new ViewPage();

            containerPage.Controls.Add(vuc);
            ViewContext vc = new Mock <ViewContext>().Object;

            vuc.ViewContext = vc;

            // Act
            HtmlHelper htmlHelper = vuc.Html;

            // Assert
            Assert.Equal(vc, htmlHelper.ViewContext);
            Assert.Equal(vuc, htmlHelper.ViewDataContainer);
        }
Beispiel #9
0
        public static string RenderViewUserControl(this HtmlHelper html, ViewUserControl control, object model)
        {
            ViewPage viewPage = new ViewPage();

            viewPage.ViewContext = html.ViewContext;
            viewPage.Controls.Add(control);
            viewPage.Url  = new UrlHelper(html.ViewContext.RequestContext);
            viewPage.Html = new HtmlHelper(html.ViewContext, viewPage);

            control.ViewData       = new ViewDataDictionary(html.ViewContext.ViewData);
            control.ViewData.Model = model;
            control.InitializeAsUserControl(viewPage);

            StringBuilder sb     = new StringBuilder();
            StringWriter  writer = new StringWriter(sb, CultureInfo.CurrentCulture);

            HttpContext.Current.Server.Execute(viewPage, writer, true);
            return(sb.ToString());
        }
Beispiel #10
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            object viewInstance = BuildManager.CreateInstanceFromVirtualPath(BaseView.ViewPath, typeof(object));

            if (viewInstance == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              "The view found at '{0}' was not created.",
                              BaseView.ViewPath));
            }



            var viewPage = viewInstance as ViewPage;

            if (viewPage != null)
            {
                //RenderViewPage(viewContext, viewPage);
                return;
            }

            ViewUserControl viewUserControl = viewInstance as ViewUserControl;

            if (viewUserControl != null)
            {
                //RenderViewUserControl(viewContext, viewUserControl);
                return;
            }

            throw new InvalidOperationException(
                      String.Format(
                          CultureInfo.CurrentUICulture,
                          "The view at '{0}' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.",
                          BaseView.ViewPath));
        }
Beispiel #11
0
        public static List <StepsVM.Step> GetAll(this ViewUserControl <StepsVM> control)
        {
            var model  = control.Model;
            var result = new List <StepsVM.Step>();

            foreach (OrderStep orderStep in Enum.GetValues(typeof(OrderStep)))
            {
                if (orderStep == OrderStep.Register && control.Request.IsAuthenticated)
                {
                    continue;
                }
                var step = new StepsVM.Step();
                result.Add(step);
                step.IsCurrent = orderStep == model.OrderStep;
                step.IsPass    = model.OrderStep > orderStep;
                var name = EnumUtils.GetDisplayName(orderStep);
                switch (orderStep)
                {
                case OrderStep.Cart:
                    step.Link = control.Html
                                .ActionLink <CartController>(c => c.Details(), name).ToString();
                    break;

                case OrderStep.Register:
                    step.Link = name;
                    break;

//                    case OrderStep.Contract:
//                        step.Link = control.Html
//                            .ActionLink<OrderController>(c => c.Contract(), name).ToString();
//                        break;
                case OrderStep.PaymentTypeChoice:
                    step.Link = name;
                    break;
                }
                if (!step.IsPass)
                {
                    step.Link = name;
                }
            }
            return(result);
        }
Beispiel #12
0
        // REVIEW: This eventually needs to use Html.RenderView with view engine-independent rendering
        public static string DynamicEntity(this HtmlHelper html, object entity, string uiHint, DataBoundControlMode mode)
        {
            // REVIEW: How can we pass along the model to avoid MetaModel.Default?
            var table = MetaModel.Default.GetTable(entity.GetType());

            // REVIEW: MetaTable does not have a UIHint. Should it?
            IEntityTemplate entityTemplate        = MetaModel.Default.GetEntityTemplateFactory().CreateEntityTemplate(table, ref mode, uiHint /* ?? table.UIHint */);
            ViewUserControl entityTemplateControl = entityTemplate as ViewUserControl;

            if (entityTemplateControl == null)
            {
                throw new InvalidOperationException("Cannot render a dynamic entity whose entity template is not a ViewUserControl");
            }

            entityTemplate.SetHost(new SimpleEntityTemplateHost()
            {
                Table = table, Mode = mode
            });
            return(html.RenderViewUserControl(entityTemplateControl, entity));
        }
        public void RenderViewAndRestoreContentType()
        {
            // Arrange
            Mock <ViewContext> mockViewContext = new Mock <ViewContext>();

            mockViewContext.SetupProperty(c => c.HttpContext.Response.ContentType);
            ViewContext vc = mockViewContext.Object;

            Mock <ViewPage> mockViewPage = new Mock <ViewPage>();

            mockViewPage.Setup(vp => vp.RenderView(vc)).Callback(() => vc.HttpContext.Response.ContentType = "newContentType");

            // Act
            vc.HttpContext.Response.ContentType = "oldContentType";
            ViewUserControl.RenderViewAndRestoreContentType(mockViewPage.Object, vc);
            string postContentType = vc.HttpContext.Response.ContentType;

            // Assert
            Assert.Equal("oldContentType", postContentType);
        }
        public void GetViewDataFromViewPage()
        {
            // Arrange
            ViewPage p = new ViewPage();

            p.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl();

            p.Controls[0].Controls.Add(vuc);
            p.ViewData = new ViewDataDictionary {
                { "FirstName", "Joe" }, { "LastName", "Schmoe" }
            };

            // Act
            object firstName = vuc.ViewData.Eval("FirstName");
            object lastName  = vuc.ViewData.Eval("LastName");

            // Assert
            Assert.Equal("Joe", firstName);
            Assert.Equal("Schmoe", lastName);
        }
Beispiel #15
0
        public virtual void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            object viewInstance = BuildManager.CreateInstanceFromVirtualPath(ViewPath, typeof(object));

            if (viewInstance == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              "",
                              ViewPath));
            }

            DlrViewPage viewPage = viewInstance as DlrViewPage;

            if (viewPage != null)
            {
                RenderViewPage(viewContext, viewPage);
                return;
            }

            ViewUserControl viewUserControl = viewInstance as ViewUserControl;

            if (viewUserControl != null)
            {
                RenderViewUserControl(viewContext, viewUserControl);
                return;
            }

            throw new InvalidOperationException(
                      String.Format(
                          CultureInfo.CurrentUICulture,
                          "",
                          ViewPath));
        }
    public string ViewToString <T>(string aspx, Dictionary <string, object> viewData, T model)
    {
        StringBuilder sb = new StringBuilder();

        using (StringWriter sw = new StringWriter(sb))
        {
            using (HtmlTextWriter tw = new HtmlTextWriter(sw))
            {
                var workerRequest = new SimpleWorkerRequest(aspx, "", tw);
                HttpContext.Current = new HttpContext(workerRequest);
                ViewDataDictionary <T> viewDataDictionary = new ViewDataDictionary <T>(model);
                foreach (KeyValuePair <string, object> pair in viewData)
                {
                    viewDataDictionary.Add(pair.Key, pair.Value);
                }
                object   view     = BuildManager.CreateInstanceFromVirtualPath(aspx, typeof(object));
                ViewPage viewPage = view as ViewPage;
                if (viewPage != null)
                {
                    viewPage.ViewData = viewDataDictionary;
                }
                else
                {
                    ViewUserControl viewUserControl = view as ViewUserControl;
                    if (viewUserControl != null)
                    {
                        viewPage = new ViewPage();
                        viewPage.Controls.Add(viewUserControl);
                    }
                }

                if (viewPage != null)
                {
                    HttpContext.Current.Server.Execute(viewPage, tw, true);
                    return(sb.ToString());
                }
                throw new InvalidOperationException();
            }
        }
    }
        public void GetViewDataFromViewPageWithViewDataKeyPointingToViewDataDictionary()
        {
            // Arrange
            ViewDataDictionary vdd = new ViewDataDictionary()
            {
                { "Foo", "FooParent" },
                { "Bar", "BarParent" },
                {
                    "Child",
                    new ViewDataDictionary()
                    {
                        { "Foo", "FooChild" },
                        { "Bar", "BarChild" }
                    }
                }
            };

            ViewPage p = new ViewPage();

            p.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl()
            {
                ViewDataKey = "Child"
            };

            p.Controls[0].Controls.Add(vuc);
            p.ViewData = vdd;

            // Act
            object oFoo = vuc.ViewData.Eval("Foo");
            object oBar = vuc.ViewData.Eval("Bar");

            // Assert
            Assert.Equal(vdd["Child"], vuc.ViewData);
            Assert.Equal("FooChild", oFoo);
            Assert.Equal("BarChild", oBar);
        }
        public void GetViewDataFromViewUserControlWithViewDataKeyOnInnerControl()
        {
            // Arrange
            ViewPage p = new ViewPage();

            p.Controls.Add(new Control());
            ViewUserControl outerVuc = new ViewUserControl();

            p.Controls[0].Controls.Add(outerVuc);
            outerVuc.Controls.Add(new Control());
            ViewUserControl vuc = new ViewUserControl()
            {
                ViewDataKey = "SubData"
            };

            outerVuc.Controls[0].Controls.Add(vuc);

            p.ViewData = new ViewDataDictionary
            {
                { "FirstName", "Joe" },
                { "LastName", "Schmoe" }
            };
            p.ViewData["SubData"] = new ViewDataDictionary
            {
                { "FirstName", "SubJoe" },
                { "LastName", "SubSchmoe" }
            };

            // Act
            object firstName = vuc.ViewData.Eval("FirstName");
            object lastName  = vuc.ViewData.Eval("LastName");

            // Assert
            Assert.Equal("SubJoe", firstName);
            Assert.Equal("SubSchmoe", lastName);
        }
Beispiel #19
0
        public static IDisposable Capture(this ViewUserControl control, string name)
        {
            var writer = LayoutViewContext.From(control.ViewContext).GetNamedContent(name);

            return(new HtmlTextWriterScope(control.Writer, writer));
        }
        public virtual string Render(ControllerContext context, string viewName, ViewDataDictionary viewData, object model, TempDataDictionary tempData, IDMode idMode, string controlId)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(viewName))
            {
                viewName = context.RouteData.GetRequiredString("action");
            }

            //string path = PartialViewResult.FindView(context, viewName);
            string id = controlId ?? "ID_" + Guid.NewGuid().ToString().Replace("-", "");
            string ct = "ID_" + Guid.NewGuid().ToString().Replace("-", "");

            ViewDataDictionary newViewData = null;

            if (model == null)
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary();
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData);
                }
            }
            else
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(model);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData)
                    {
                        Model = model
                    };
                }
            }

            ViewEngineResult result = ViewEngines.Engines.FindPartialView(context, viewName);
            IView            view   = result.View;
            string           path   = ((WebFormView)view).ViewPath;

            ViewContext viewContext = new ViewContext(context, view, newViewData, tempData ?? new TempDataDictionary(), context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = newViewData,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;
            object oldPageRM = null;

            if (context.HttpContext.CurrentHandler is Page)
            {
                oldPageRM = ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)];
                ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)] = null;
            }

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = idMode;
            pageHolder.Controls.Add(rm);
            Panel p = new Panel {
                ID = id, IDMode = idMode, Border = false, Header = false
            };

            pageHolder.Controls.Add(p);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = newViewData;
            p.ContentControls.Add(uc);

            pageHolder.InitHelpers();

            string wScript = DefaultScriptBuilder.Create(p).Build(RenderMode.RenderTo, ct, null, true, true);
            string script  = string.Format("<div id=\"{0}\"></div><script type=\"text/javascript\">Ext.onReady(function(){{{1}}});</script>", ct, wScript);

            IDisposable disposable = view as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;
            if (context.HttpContext.CurrentHandler is Page)
            {
                ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)] = oldPageRM;
            }

            return(script);
        }
Beispiel #21
0
 public PageHolderContainerPage(ViewUserControl userControl)
 {
     _userControl = userControl;
 }
 internal ControlContainerPage(ViewUserControl control)
 {
     Controls.Add(control);
 }
 public static string CSS(this HtmlHelper helper, ViewUserControl pg, string fileName)
 {
     return CSS(helper, pg.SiteRoot(), fileName);
 }
 public MockViewUserControlContainerPage(ViewUserControl userControl)
 {
     Controls.Add(userControl);
 }
 public static string Script(this HtmlHelper helper, ViewUserControl pg, string viewDir, string fileName)
 {
     return Script(helper, pg.SiteRoot(), viewDir, fileName);
 }
 public static Order CurrentOrder(this ViewUserControl pg)
 {
     return(CurrentOrder(pg.Page as ViewPage));
 }
 public static string ClimberProfileLink(ViewUserControl control, ClimberProfile climberProfile)
 {
     return(ClimberProfileLink((ViewPage)control.Page, climberProfile));
 }
Beispiel #28
0
        public static string SiteRoot(this ViewUserControl pg)
        {
            var vpage = pg.Page as ViewPage;

            return(SiteRoot(vpage.ViewContext.HttpContext));
        }
Beispiel #29
0
 public static string GetReturnUrl(this ViewUserControl pg)
 {
     return(GetReturnUrl(pg.Page as ViewPage));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var instanceScript = HttpContext.Current.Items[ResourceManager.INSTANCESCRIPT];

            if (instanceScript != null)
            {
                this.afterScript = instanceScript.ToString();
                HttpContext.Current.Items.Remove(ResourceManager.INSTANCESCRIPT);
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                this.ViewName = context.RouteData.GetRequiredString("action");
            }

            string id = this.ControlId ?? BaseControl.GenerateID();
            string ct = this.ContainerId ?? "Ext.getBody()";

            if (this.Model != null)
            {
                this.ViewData.Model = this.Model;
            }

            ViewDataDictionary dict   = new ViewDataDictionary(this.ViewData);
            ViewEngineResult   result = null;

            if (this.View == null)
            {
                result    = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                this.View = result != null ? result.View : null;
            }

            if (this.View == null)
            {
                throw new Exception("View with name '{0}' is not found".FormatWith(this.ViewName));
            }

            if (this.View is RazorView)
            {
                if (this.SingleControl)
                {
                    throw new Exception("Razor view doesn't support SingleControl option");
                }

                if (this.ControlToRender.IsNotEmpty())
                {
                    throw new Exception("Razor view doesn't support ControlToRender option");
                }

                if (this.Items)
                {
                    throw new Exception("Razor view doesn't support Items option");
                }

                this.RenderRazorView(context, (RazorView)this.View);

                if (result != null)
                {
                    result.ViewEngine.ReleaseView(context, this.View);
                }

                return;
            }

            if (this.Items && this.RenderMode != Ext.Net.RenderMode.AddTo && this.RenderMode != Ext.Net.RenderMode.InsertTo)
            {
                throw new Exception("Items mode can be used with AddTo/InsertTo only");
            }

            if (this.Items && this.SingleControl)
            {
                throw new Exception("Items and SingleControl cannot be used at one time");
            }

            if (this.Items && this.ControlToRender.IsNotEmpty())
            {
                throw new Exception("Items and ControlToRender cannot be used at one time");
            }

            if (this.SingleControl && this.ControlToRender.IsNotEmpty())
            {
                throw new Exception("SingleControl and ControlToRender cannot be used at one time");
            }

            string path = ((WebFormView)this.View).ViewPath;

            ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = dict,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = this.IDMode;
            pageHolder.Controls.Add(rm);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = ViewData;

            if (uc is IDynamicUserControl)
            {
                ((IDynamicUserControl)uc).BeforeRender();
            }

            BaseControl controlToRender = null;

            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Container p;

                if (this.ContainerConfig != null)
                {
                    p        = new Container(this.ContainerConfig);
                    p.ID     = id;
                    p.IDMode = this.IDMode;
                }
                else
                {
                    p = new Container {
                        ID = id, IDMode = this.IDMode, Border = false
                    };
                }

                if (this.Namespace != null)
                {
                    p.Namespace = this.Namespace;
                }

                if (this.Items || this.Config)
                {
                    p.Layout = "auto";
                    p.AddBeforeClientInitScript("<ext.net.container>");
                    p.AddAfterClientInitScript("</ext.net.container>");
                    p.ID     = "Ext_Net_Temp_Container";
                    p.IDMode = Ext.Net.IDMode.Static;
                }

                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            StringBuilder sb = new StringBuilder();

            string script;

            if (this.Items || this.Config)
            {
                script = controlToRender.ToScript(Ext.Net.RenderMode.AddTo, "Ext_Net_Partial_Items", true);

                script = ItemsAddToContainer_RE.Replace(script, delegate
                {
                    return("");
                }, 1);

                script = ItemsDestroyCmpContainer_RE.Replace(script, delegate
                {
                    return("");
                }, 1);

                script = TempIDRemove_RE.Replace(script, delegate
                {
                    return("");
                }, 1);

                if (this.Config)
                {
                    Match match = ItemsContainer_RE.Match(script);
                    if (match != null && match.Success)
                    {
                        this.Output = "[" + match.Groups[1].Value + "]";
                    }
                    else
                    {
                        this.Output = "[]";
                    }

                    IDisposable disposable = this.View as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }

                    if (result != null)
                    {
                        result.ViewEngine.ReleaseView(context, this.View);
                    }

                    return;
                }

                script = ItemsContainer_RE.Replace(script, delegate(Match m)
                {
                    string elementGet     = ct.Contains(".") ? ct : "Ext.getCmp({0})".FormatWith(JSON.Serialize(ct));
                    string methodTemplate = string.Concat(".", "add", "([");

                    if (this.RenderMode == RenderMode.InsertTo)
                    {
                        methodTemplate = string.Concat(".", "insert", "(", this.Index, ",[");
                    }

                    string replace = elementGet.ConcatWith(methodTemplate, m.Groups[1].Value, "]);");

                    return(this.ClearContainer ? (elementGet + ".removeAll();" + replace) : replace);
                }, 1);
            }
            else
            {
                if (this.RenderMode == Ext.Net.RenderMode.InsertTo)
                {
                    script = controlToRender.ToScript(mode: this.RenderMode, element: ct, index: this.Index, selfRendering: true, clearContainer: this.ClearContainer);
                }
                else
                {
                    script = controlToRender.ToScript(mode: this.RenderMode, element: ct, selfRendering: true, clearContainer: this.ClearContainer);
                }
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            if (this.RenderMode == Ext.Net.RenderMode.AddTo || this.RenderMode == Ext.Net.RenderMode.InsertTo || this.RenderMode == Ext.Net.RenderMode.Replace)
            {
                string cmpId = this.ContainerId.Contains(".") ? this.ContainerId.RightOfRightmostOf(".") : this.ContainerId;
                sb.AppendFormat("Ext.ComponentManager.onAvailable(\"{0}\",function(){{{1}{2}{3}}});", cmpId, this.beforeScript ?? "", script, this.afterScript ?? "");
            }
            else
            {
                sb.AppendFormat("Ext.onReady(function(){{{0}{1}{2}}});", this.beforeScript ?? "", script, this.afterScript ?? "");
            }

            this.RenderScript(context, sb.ToString());

            if (result != null)
            {
                result.ViewEngine.ReleaseView(context, this.View);
            }
        }
Beispiel #31
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            object viewInstance = BuildManager.CreateInstanceFromVirtualPath(BaseView.ViewPath, typeof(object));

            if (viewInstance == null)
            {
                throw new InvalidOperationException(
                          String.Format(
                              CultureInfo.CurrentUICulture,
                              "The view found at '{0}' was not created.",
                              BaseView.ViewPath));
            }

            ////////////////////////////////
            // This is where our code starts
            ////////////////////////////////
            var viewType       = viewInstance.GetType();
            var isBaseViewPage = viewType.Closes(typeof(ViewPageBase <>));

            Container.Configure(cfg =>
            {
                cfg.For <ViewContext>().Use(viewContext);
                cfg.For <IViewDataContainer>().Use((IViewDataContainer)viewInstance);

                if (isBaseViewPage)
                {
                    var modelType           = GetModelType(viewType);
                    var builderType         = typeof(IHtmlBuilder <>).MakeGenericType(modelType);
                    var concreteBuilderType = typeof(HtmlBuilder <>).MakeGenericType(modelType);

                    cfg.For(builderType).Use(concreteBuilderType);
                }
            });

            Container.BuildUp(viewInstance);
            ////////////////////////////////
            // This is where our code ends
            ////////////////////////////////

            var viewPage = viewInstance as ViewPage;

            if (viewPage != null)
            {
                RenderViewPage(viewContext, viewPage);
                return;
            }

            ViewUserControl viewUserControl = viewInstance as ViewUserControl;

            if (viewUserControl != null)
            {
                RenderViewUserControl(viewContext, viewUserControl);
                return;
            }

            throw new InvalidOperationException(
                      String.Format(
                          CultureInfo.CurrentUICulture,
                          "The view at '{0}' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.",
                          BaseView.ViewPath));
        }
Beispiel #32
0
 public ViewUserControlContainerPage(ViewUserControl userControl) {
     Controls.Add(userControl);
 }
Beispiel #33
0
        private void RenderViewUserControl(ViewContext context, ViewUserControl control)
        {
            if (!String.IsNullOrEmpty(BaseView.MasterPath))
            {
                throw new InvalidOperationException("A master name cannot be specified when the view is a ViewUserControl.");
            }

            control.ViewData = context.ViewData;
            control.RenderView(context);
        }
 public static string Image(this HtmlHelper helper, ViewUserControl pg, string fileName, string attributes)
 {
     return Image(helper, pg.SiteRoot(), fileName, attributes);
 }
Beispiel #35
0
 public ViewUserControlContainerPage(ViewUserControl userControl) {
     _userControl = userControl;
 }
Beispiel #36
0
        private ViewUserControl CreateContainer(IDisplayable displayable)
        {
            var viewData = new ViewDataDictionary(CurrentItem);

            var container = new ViewUserControl
                                {
                                    Page = (Html.ViewContext.View is Control) ? ((Control)Html.ViewContext.View).Page : null,
                                    ViewData = viewData,
                                };
            displayable.AddTo(CurrentItem, propertyName, container);

            return container;
        }
Beispiel #37
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                ViewName = context.RouteData.GetRequiredString("action");
            }


            string id = this.ControlId ?? "ID_" + Guid.NewGuid().ToString().Replace("-", "");
            string ct = this.ContainerId ?? "Ext.getBody()";

            ViewDataDictionary dict = new ViewDataDictionary(ViewData);

            ViewEngineResult result = null;

            if (View == null)
            {
                result = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                //result = this.FindView(context);
                View = result.View;
            }

            string path = ((WebFormView)View).ViewPath;

            ViewContext viewContext = new ViewContext(context, View, ViewData, TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = dict,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = this.IDMode;
            pageHolder.Controls.Add(rm);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = ViewData;

            XControl controlToRender = null;

            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Panel p;
                if (this.PanelConfig != null)
                {
                    p        = new Panel(this.PanelConfig);
                    p.ID     = id;
                    p.IDMode = this.IDMode;
                }
                else
                {
                    p = new Panel {
                        ID = id, IDMode = this.IDMode, Border = false, Header = false
                    };
                }

                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                XControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <XControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <XControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (controlToRender.IDMode == IDMode.Inherit)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            string script = controlToRender.ToScript(this.RenderMode, ct, true);

            if (X.IsAjaxRequest)
            {
                script = "<Ext.Net.Direct.Response>" + script + "</Ext.Net.Direct.Response>";
            }
            else if (this.WrapByScriptTag)
            {
                script = "<script type=\"text/javascript\">" + script + "</script>";
            }

            IDisposable disposable = View as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            context.HttpContext.Response.Write(script);
        }
        /// <summary>
        /// Build the "Previous" link
        /// </summary>
        /// <param name="pageLink">StringBuilder, pageLink</param>
        /// <param name="isDefault">bool, isDefault</param>
        private void BuildPreviousLink(StringBuilder pageLink, bool isDefault)
        {

            ViewUserControl vuc = new ViewUserControl();
            if (isDefault)
            {
                if ((this.CurPage - this.NumLinks) >= 0)
                {
                    int i = this.CurPage - 1;

                    if (i == 0) i = 1;

                    pageLink.Append(this.PrevTagOpen);
                    //pageLink.Append("<a href='" + this.BaseUrl + Convert.ToString(i) + "'>");


                    pageLink.Append("<a href=\"" + this.BaseUrl + Convert.ToString(i) + "\" onclick=\"Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: '" + _updateTargetId + "' });\"  " + _class + ">" + this.PrevLink + "</a>");


                    //pageLink.Append(this.PrevLink);
                    //pageLink.Append("</a>");
                    pageLink.Append(this.PrevTagClose);

                }
            }
            else
            {
                int i = this.CurPage - 1;

                pageLink.Append(this.PrevTagOpen);

                if (i > 0)
                {
                    //pageLink.Append("<a href='" + this.BaseUrl + Convert.ToString(i) + "'>");


                    //pageLink.Append(
                    //    "<a href= " + this.BaseUrl + Convert.ToString(i) + " onclick='Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: '" + _updateTargetId + "' });\">" + this.PrevLink + "</a>"
                    //);


                    pageLink.Append("<a href=\"" + this.BaseUrl + Convert.ToString(i) + "\" onclick=\"Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: '" + _updateTargetId + "' });\"  " + _class + ">" + this.PrevLink + "</a>");




                    //pageLink.Append(
                    //    );
                    pageLink.Append(this.PrevLink);
                    //pageLink.Append("</a>");
                }
                else
                {

                    pageLink.Append("<a href=\"" + this.BaseUrl + Convert.ToString(i) + "\" onclick=\"Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: '" + _updateTargetId + "' });\" " + _class + ">" + this.PrevLink + "</a>");

                    pageLink.Append(this.PrevLink);
                }

                pageLink.Append(this.PrevTagClose);
            }
        }
Beispiel #39
0
 public static Page CurrentPage(this ViewUserControl pg)
 {
     return(CurrentPage(pg.Page as ViewPage));
 }