Exemplo n.º 1
1
 public ColorPicker(ViewContext viewContext, IJavaScriptInitializer initializer, ViewDataDictionary viewData)
     : base(viewContext, initializer, viewData)
 {
     Palette = ColorPickerPalette.None;
     Enabled = true;
     Buttons = true;
 }
Exemplo n.º 2
0
        public static string RenderSitecorePlaceHolder(string key)
        {
            var sublayoutId = GetSublayoutIdFromPlaceHolder(Sitecore.Context.Item[Sitecore.FieldIDs.LayoutField], key);
            if (!string.IsNullOrEmpty(sublayoutId))
            {
                var layoutItem = Sitecore.Context.Database.GetItem(ID.Parse(sublayoutId));
                var controllerName = layoutItem.Fields["Controller"].Value;
                var actionName = layoutItem.Fields["Action"].Value;

                HttpContext.Current.RewritePath(string.Concat("/", controllerName, "/", actionName));

                RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
                if (routeData != null)
                {
                    var factory = new ControllerFactory();
                    var httpContextBase = new HttpContextWrapper(HttpContext.Current);
                    var context = new RequestContext(httpContextBase, routeData);
                    Type type = factory.GetController(context, controllerName);

                    if (type != null)
                    {
                        var controller = (Controller)factory.GetController(context, type);

                        var controllerContext = new ControllerContext(httpContextBase, routeData, controller);
                        var viewContext = new ViewContext(controllerContext, new FakeView(), controller.ViewData, controller.TempData, TextWriter.Null);

                        var helper = new HtmlHelper(viewContext, new ViewPage());

                        return helper.Action(actionName, controllerName).ToHtmlString();
                    }
                }
                HttpContext.Current.RewritePath("default.aspx");
            }
            return "";
        }
        private object GetInstance(ViewContext viewContext)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            object instance = null;

            Type type = BuildManager.GetCompiledType(ViewPath);
            if (type != null)
            {
                instance = ViewPageActivator.Create(_controllerContext, type);
            }

            if (instance == null)
            {
                throw new InvalidOperationException(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        MvcResources.CshtmlView_ViewCouldNotBeCreated,
                        ViewPath));
            }

            return instance;
        }
        public void VeneerScripts_handles_content_types_with_no_scripts()
        {
            // Arrange
            var service = new Mock<IContentService>();
            var content = new Content
            {
                RefreshDate = DateTime.Now,
                Sections = new List<ContentSection>
                {
                    new ContentSection
                    {
                        Id = "Footer", Html = "<div id='hello' />", Scripts = new List<ContentScript>()
                    }
                }
            };
            service.Setup(x => x.Get(It.IsAny<ContentTypes>())).Returns(content);
            var contentTypes = new List<ContentTypes> { ContentTypes.Footer };

            var model = new VeneerBaseViewModel(service.Object, contentTypes);

            var viewContext = new ViewContext();
            var viewDataContainer = new Mock<IViewDataContainer>();
            var htmlHelper = new HtmlHelper(viewContext, viewDataContainer.Object);

            // Act
            var result = htmlHelper.VeneerScripts(model).ToHtmlString();

            // Assert
            Assert.That(result, Is.Empty);
        }
Exemplo n.º 5
0
        public ColorPalette(ViewContext viewContext, IJavaScriptInitializer initializer, ViewDataDictionary viewData)
            : base(viewContext, initializer, viewData)
        {
            Palette = ColorPickerPalette.Basic;

            Columns = ColumnsDefault;
        }
 public JsonResult Add(string name, string visitDate, string arrivalDate, string contact, string emailAddress, int visitType, int officeID, int eventID, int convensionID, int serviceID, int fsmID, int bookingStatus, float gsbAmount, float donationAmount)
 {
     var audienceManager = new DataAccess.AudienceManager();
     var visitDateTime = Convert.ToDateTime(visitDate);
     DateTime? arrivalDateTime = string.IsNullOrEmpty(arrivalDate) ? (DateTime?)null : Convert.ToDateTime(arrivalDate);
     var audienceID = audienceManager.Add(name, contact, emailAddress, visitDateTime, arrivalDateTime, visitType, officeID, eventID, fsmID, convensionID, serviceID, bookingStatus, gsbAmount, donationAmount);
     if (audienceID != 0)
     {
         using (var sw = new StringWriter())
         {
             var fsmSelectionMail = audienceManager.GetFSMSelectionSlipByAudienceID(audienceID);
             ViewData.Model = fsmSelectionMail;
             ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "FSMSelectionMail");
             ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
             try
             {
                 viewResult.View.Render(viewContext, sw);
                 audienceManager.SendSelectionSlipMail(fsmID, emailAddress, sw.GetStringBuilder().ToString());
             }
             catch (Exception ex)
             { }
         }
     }
     return Json(audienceID);
 }
Exemplo n.º 7
0
        public static Editor CreateEditor()
        {
            Mock<HttpContextBase> httpContext = TestHelper.CreateMockedHttpContext();

            httpContext.Setup(c => c.Request.Browser.CreateHtmlTextWriter(It.IsAny<TextWriter>())).Returns(new HtmlTextWriter(TextWriter.Null));

            Mock<IViewDataContainer> viewDataContainer = new Mock<IViewDataContainer>();

            viewDataContainer.SetupGet(container => container.ViewData).Returns(new ViewDataDictionary());

            Mock<IClientSideObjectWriterFactory> clientSideObjectWriterFactory = new Mock<IClientSideObjectWriterFactory>();
            clientSideObjectWriter = new Mock<IClientSideObjectWriter>();

            viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = new ViewDataDictionary();

            clientSideObjectWriterFactory.Setup(c => c.Create(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<TextWriter>())).Returns(clientSideObjectWriter.Object);

            viewContext = TestHelper.CreateViewContext();
            viewContext.ViewData = new ViewDataDictionary();

            var urlGenerator = new Mock<IUrlGenerator>();
            urlGenerator.Setup(url => url.Generate(It.IsAny<RequestContext>(), It.IsAny<INavigatable>())).Returns(string.Empty);
            return new Editor(viewContext, clientSideObjectWriterFactory.Object, new Mock<IWebAssetCollectionResolver>().Object, CreateLocalizationService(), urlGenerator.Object)
            {
                Name = "Editor"
            };
        }
 /// <summary>
 /// Create a new HtmlHelper with a fake context and container
 /// </summary>
 /// <returns>HtmlHelper</returns>
 public static HtmlHelper Create()
 {
     var vc = new ViewContext();
     vc.HttpContext = new FakeHttpContext();
     var html = new HtmlHelper(vc, new FakeViewDataContainer());
     return html;
 }
            public void WritesExpectedCollectionIndexHiddenInput_WhenThereIsAnIndexInRequestData()
            {
                const string collectionName = "CollectionName";
                var index0 = Guid.NewGuid();
                var index1 = Guid.NewGuid();
                var indexes = string.Format("{0},{1}", index0, index1);
                var httpContext = new Mock<HttpContextBase>();
                var httpContextItems = new Dictionary<string, object>();
                httpContext.Setup(p => p.Items).Returns(httpContextItems);

                var httpRequest = new Mock<HttpRequestBase>();
                httpRequest.Setup(i => i[It.Is<string>(s => s == string.Format("{0}.index", collectionName))])
                    .Returns(indexes);
                httpContext.Setup(p => p.Request).Returns(httpRequest.Object);

                var viewContext = new ViewContext();
                var writer = new StringWriter();
                viewContext.Writer = writer;

                var html = new HtmlHelper(viewContext, new FakeViewDataContainer());
                viewContext.HttpContext = httpContext.Object;

                using (var result = html.BeginCollectionItem(collectionName))
                {
                    Assert.That(result, Is.Not.Null);
                }

                var text = writer.ToString();
                Assert.That(text,
                            Is.Not.Null
                              .And.Not.Empty
                              .And.StringStarting(string.Format(@"<input type=""hidden"" name=""{0}.index"" autocomplete=""off"" value=""{1}"" />", collectionName, index0)));
            }
Exemplo n.º 10
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (page == null)
            {
                throw new InvalidOperationException("Cannot create a page from " + viewPath);
            }
            //damn, now why is this internal, how can you ever reuse the webviewpage then??
            //page.OverridenLayoutPath = this.LayoutPath;
            if (!String.IsNullOrEmpty(this.LayoutPath))
                page.Layout = LayoutPath;

            page.VirtualPath = viewPath;
            page.ViewContext = viewContext;
            page.ViewData = viewContext.ViewData;
            page.InitHelpers();
            WebPageRenderingBase startPage = null;
            if (this.RunViewStartPages)
            {
                startPage = this.StartPageLookup(page, VirtualPathFactoryManagerViewEngine.ViewStartFileName, this.ViewStartFileExtensions);
            }
            var httpContext = viewContext.HttpContext;
            WebPageRenderingBase base4 = null;
            object model = null;

            //instead of page.OverridenLayoutPath:
            if (!String.IsNullOrEmpty(this.LayoutPath))
                page.Layout = LayoutPath;

            page.ExecutePageHierarchy(new WebPageContext(httpContext, base4, model), writer, startPage);
        }
Exemplo n.º 11
0
 public Brand(ViewContext view)
 {
     this.ViewContext = view;
     this.Component = new BrandComponent();
     this.Component.Skin = new BrandSkin();
     this.Component.HtmlProperties = new HtmlProperties(view, this.Component.GetType());
 }
Exemplo n.º 12
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            // Reading the file content
            var text = File.ReadAllText(_filepath);

            // Page doctype
            var doctype = "<!doctype html>";

            // Page encoding
            var charset = "<meta charset=\"utf-8\" />";

            // Page title
            var title = "<title>" + Path.GetFileNameWithoutExtension(_filepath) + "</title>";

            // Page CSS (if any)
            var css = string.IsNullOrWhiteSpace(_cssHref) ?
                string.Format(CultureInfo.InvariantCulture, "<style>\n{0}\n</style>", Resources.Style) :
                string.Format(CultureInfo.InvariantCulture, "<link rel=\"stylesheet\" href=\"{0}\">", _cssHref);

            // Parsing the Markdown content
            var markdown = CommonMarkConverter.Convert(text);

            // Joining all up
            var content = string.Join("\n", doctype, charset, title, css, markdown);

            // Writing to the stream
            writer.Write(content);
        }
Exemplo n.º 13
0
        private void RenderHtmlOutput(ControllerContext context)
        {
            IView viewEngineResult = ViewEngines.Engines.FindView(context, this.ViewName, null).View;

            var viewContext = new ViewContext(context, viewEngineResult, context.Controller.ViewData, context.Controller.TempData, context.HttpContext.Response.Output);
            viewEngineResult.Render(viewContext, context.HttpContext.Response.Output);
        }
Exemplo n.º 14
0
 public DropDownHeaderItem(ViewContext view)
 {
     this.ViewContext = view;
     this.Component = new DropDownHeaderItemComponent();
     this.Component.HtmlProperties = new HtmlProperties(view, this.Component.GetType());
     this.ContainerElements = new Collection<ISushiComponentBuilder>();
 }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptRegistrar"/> class.
        /// </summary>
        /// <param name="scripts">The scripts.</param>
        /// <param name="scriptableComponents">The scriptable components.</param>
        /// <param name="viewContext">The view context.</param>
        /// <param name="assetItemMerger">The asset merger.</param>
        /// <param name="scriptWrapper">The script wrapper.</param>
        public ScriptRegistrar(WebAssetCollection scripts, IList<IScriptableComponent> scriptableComponents, ViewContext viewContext, IWebAssetCollectionResolver resolver, ScriptWrapperBase scriptWrapper)
        {
            this.resolver = resolver;

            if (viewContext.HttpContext.Items[Key] != null)
            {
                throw new InvalidOperationException(Resources.TextResource.OnlyOneScriptRegistrarIsAllowedInASingleRequest);
            }

            viewContext.HttpContext.Items[Key] = this;

            OutputScriptFiles = true;

            DefaultGroup = new WebAssetGroup("default", false) { DefaultPath = WebAssetDefaultSettings.ScriptFilesPath };
            Scripts = scripts;
            Scripts.Insert(0, DefaultGroup);

            this.scriptableComponents = scriptableComponents;
            ViewContext = viewContext;
            ScriptWrapper = scriptWrapper;
            AssetHandlerPath = WebAssetHttpHandler.DefaultPath;

            OnDocumentReadyActions = new List<Action>();
            OnDocumentReadyStatements = new List<string>();
            OnWindowUnloadActions = new List<Action>();
            OnWindowUnloadStatements = new List<string>();
        }
Exemplo n.º 16
0
 private Action<IModelValueContainer> ConfigureContext(ViewContext viewContext)
 {
     return c => {
     ConfigureModel(viewContext, c.TalModel);
     ConfigureModel(viewContext, c.MetalModel);
       };
 }
Exemplo n.º 17
0
 public Pager(IPageableModel model, ViewContext context)
 {
     this.model = model;
     this.viewContext = context;
     this.urlBuilder = CreateDefaultUrl;
     this.booleanParameterNames = new List<string>();
 }
            public void WritesCollectionIndexHiddenInput_WhenThereIsNothingInRequestData()
            {
                const string collectionName = "CollectionName";
                var httpContext = new Mock<HttpContextBase>();
                var httpContextItems = new Dictionary<string, object>();
                httpContext.Setup(p => p.Items).Returns(httpContextItems);

                var httpRequest = new Mock<HttpRequestBase>();
                httpContext.Setup(p => p.Request).Returns(httpRequest.Object);

                var viewContext = new ViewContext();
                var writer = new StringWriter();
                viewContext.Writer = writer;

                var html = new HtmlHelper(viewContext, new FakeViewDataContainer());
                viewContext.HttpContext = httpContext.Object;

                using (var result = html.BeginCollectionItem(collectionName))
                {
                    Assert.That(result, Is.Not.Null);
                }

                var text = writer.ToString();
                Assert.That(text,
                            Is.Not.Null
                              .And.Not.Empty
                              .And.StartsWith(string.Format(@"<input type=""hidden"" name=""{0}.index"" autocomplete=""off"" value=""", collectionName))
                              .And.Contains(@""" />"));
            }
Exemplo n.º 19
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            var       news = (News)dataItem;
            UrlHelper url  = new UrlHelper(viewContext.RequestContext);

            return(new HtmlString(string.Format(@"<a href=""{0}"">{1}</a>", url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("Id", news.Id)), value)));
        }
Exemplo n.º 20
0
 public void Render(ViewContext viewContext, TextWriter writer)
 {
     var doc = CreateDocument();
       doc.Render(writer,
          contextConfigurator: ConfigureContext(viewContext),
          options: RenderingOptions);
 }
Exemplo n.º 21
0
 public void Render(ViewContext viewContext, TextWriter writer)
 {
     using (MiniProfiler.Current.Step("Render " + (isPartial ? "partial" : "") + ": " + name))
     {
         wrapped.Render(viewContext, writer);
     }
 }
        public GridItemAction Render(object dataItem, GridItemAction itemAction, ViewContext viewContext)
        {
            var inheritable = dataItem as IInheritable;
            if (inheritable != null)
            {
                var localized = inheritable.IsLocalized(Site.Current);
                if (localized)
                {
                    //注释下面的代码,解决子页面本地化,父页面没有本地化时,不能进行还原操作。
                    var hasParent = Site.Current.Parent != null;
                    if (hasParent)
                    {
                        itemAction.ActionName = "Unlocalize";
                        itemAction.Title = "Unlocalize".Localize();
                        itemAction.Class = "o-icon unlocalize actionCommand";
                        itemAction.ConfirmMessage = "Are you sure you want to unlocalize this item?";
                        itemAction.Visible = true;
                    }
                    else
                    {
                        itemAction.Title = "Localize";
                        itemAction.Visible = false;
                    }
                }

            }

            return itemAction;
        }
Exemplo n.º 23
0
 private void EndCapturingValidation(ViewContext viewContext)
 {
     if (!viewContext.ClientValidationEnabled)
         return;
     viewContext.OutputClientValidation();
     viewContext.Writer.WriteLine("<script type=\"text/javascript\">Sys.Mvc.FormContext._Application_Load()</script>");
 }
Exemplo n.º 24
0
 public DatePicker(ViewContext viewContext, IJavaScriptInitializer initializer, ViewDataDictionary viewData)
     : base(viewContext, initializer, viewData)
 {
     Min = defaultMinDate;
     Max = defaultMaxDate;
     MonthTemplate = new MonthTemplate();
 }
Exemplo n.º 25
0
        private string ActivateAndRenderTemplate(IRazorTemplateBase obj, DisplayContext displayContext, string templateVirtualPath, object model)
        {
            var buffer = new StringBuilder(1024);
            using (var writer = new StringWriter(buffer)) {
                using (var htmlWriter = new HtmlTextWriter(writer)) {

                    if (displayContext != null && displayContext.ViewContext.Controller != null) {
                        var shapeViewContext = new ViewContext(
                            displayContext.ViewContext.Controller.ControllerContext,
                            displayContext.ViewContext.View,
                            displayContext.ViewContext.ViewData,
                            displayContext.ViewContext.TempData,
                            htmlWriter
                            );

                        obj.WebPageContext = new WebPageContext(displayContext.ViewContext.HttpContext, obj as WebPageRenderingBase, model);
                        obj.ViewContext = shapeViewContext;

                        obj.ViewData = new ViewDataDictionary(displayContext.ViewDataContainer.ViewData) {Model = model};
                        obj.InitHelpers();
                    }
                    else {

                        obj.ViewData = new ViewDataDictionary(model);
                        obj.WebPageContext = new WebPageContext(_httpContextBase, obj as WebPageRenderingBase, model);
                    }

                    obj.VirtualPath = templateVirtualPath ?? "~/Themes/Orchard.Templates";
                    obj.Render(htmlWriter);
                }
            }

            return buffer.ToString();
        }
Exemplo n.º 26
0
 public SearchBox(ViewContext view)
 {
     this.ViewContext = view;
     this.Component = new SearchBoxComponent();
     this.Component.Form = new Form(view);
     this.Component.Input = new Input(view);
 }
Exemplo n.º 27
0
        public static string RenderPartial(this ControllerBase self, string viewName, object model,
            bool strip = true)
        {
            var context = self.ControllerContext;

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

            self.ViewData.Model = model;

            //try {
            using (var writer = new StringWriter()) {
                var viewResult = ViewEngines.Engines.FindPartialView(context, viewName);
                var viewContext = new ViewContext(context, viewResult.View, self.ViewData,
                    self.TempData, writer);
                viewResult.View.Render(viewContext, writer);

                var result = writer.GetStringBuilder().ToString();
                return strip ? _stripper.Replace(result, StripInvalidChars) : result;
            }
            //} catch (ArgumentNullException ex) { }

            //return "";
        }
Exemplo n.º 28
0
        public static string RenderViewToString(string controllerName, string viewName, object viewData, List<KeyValuePair<string, object>> additionalData)
        {
            var context = HttpContext.Current;
              var contextBase = new HttpContextWrapper(context);
              var routeData = new RouteData();
              routeData.Values.Add("controller", controllerName);

              var controllerContext = new ControllerContext(contextBase,
            routeData,
            new EmptyController());

              var razorViewEngine = new RazorViewEngine();
              var razorViewResult = razorViewEngine.FindView(controllerContext,
            viewName,
            "",
            false);

              ViewDataDictionary vdd = new ViewDataDictionary(viewData);
              if (additionalData != null && additionalData.Any())
            additionalData.ForEach(vdd.Add);

              var writer = new StringWriter();
              var viewContext = new ViewContext(controllerContext,
            razorViewResult.View,
            vdd,
            new TempDataDictionary(),
            writer);
              razorViewResult.View.Render(viewContext, writer);

              return writer.ToString();
        }
Exemplo n.º 29
0
 protected virtual void BuildControl(TagBuilder builder, CustomFieldDefinition fieldDefinition, string fieldValue, object htmlAttributes, ViewContext viewContext)
 {
     if (htmlAttributes != null)
     {
         builder.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), true);
     }
 }
        public virtual void Render(ViewContext viewContext, TextWriter writer)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            object instance = null;

            Type type = BuildManager.GetCompiledType(ViewPath);
            if (type != null)
            {
                instance = ViewPageActivator.Create(_controllerContext, type);
            }

            if (instance == null)
            {
                throw new InvalidOperationException(
                    String.Format(
                        CultureInfo.CurrentCulture,
                        MvcResources.CshtmlView_ViewCouldNotBeCreated,
                        ViewPath));
            }

            RenderView(viewContext, writer, instance);
        }
Exemplo n.º 31
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (string.IsNullOrEmpty(ViewName))
                this.ViewName = context.RouteData.GetRequiredString("action");

            ViewEngineResult result = null;

            if (View == null)
                View = FindView(context).View;

            using (StringWriter output = new StringWriter())
            {
                ViewData["_isGriddlySettingsRequest"] = true;

                ViewContext viewContext = new ViewContext(context, View, ViewData, TempData, output);

                View.Render(viewContext, output);

                Settings = ViewData["settings"] as GriddlySettings;
            }

            if (result != null)
                result.ViewEngine.ReleaseView(context, View);
        }
Exemplo n.º 32
0
 public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
 {
     if (value != null)
     {
         return(new HtmlString(string.Join(",", ((IEnumerable <string>)value).ToArray())));
     }
     return(new HtmlString(""));
 }
Exemplo n.º 33
0
        public void Render(System.Web.Mvc.ViewContext viewContext, TextWriter writer)
        {
            var context  = new ViewContext(viewContext.TempData, viewContext.ViewData, viewContext.ViewData.Model);
            var fileInfo = new FileInfo(path);
            var res      = renderer.Render(fileInfo, context);
            var result   = renderer.ResultOrThrow(res);

            writer.Write(result);
            writer.Close();
        }
Exemplo n.º 34
0
 public BootstrapHelper(mvc.ViewContext viewContext, mvc.UrlHelper urlHelper, Func <int, string> messageSource)
 {
     this.ViewContext = viewContext;
     this.UrlHelper   = urlHelper;
     parents          = (Stack <IWritableItem>)viewContext.HttpContext.Items[ParentStackContextKey];
     if (parents == null)
     {
         parents = new Stack <IWritableItem>(5);
         parents.Push(null);
         viewContext.HttpContext.Items[ParentStackContextKey] = parents;
     }
 }
Exemplo n.º 35
0
        public override void Render(System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer)
        {
            var focus = (IView)null;

            ResponseType responseType = ResponseType.None;
            var          routeData    = viewContext.RouteData.Values;

            object tempObj;

            if (routeData.TryGetValue("responseType", out tempObj) && tempObj is ResponseType)
            {
                responseType = (ResponseType)tempObj;
            }

            if (responseType == ResponseType.None)
            {
                responseType = ServiceHelper.GetResponseType(viewContext);
            }

            switch (responseType)
            {
            case ResponseType.JavaScript:
                focus = new JavaScriptCallbackResult();
                break;

            case ResponseType.Json:
                focus = new JsonView();
                break;

            case ResponseType.Xml:
                focus = new XmlView();
                break;

            case ResponseType.Csv:
                focus = new CsvResult();
                break;

            case ResponseType.Html:
            default:
                focus = viewContext.View;
                break;
            }

            if (focus is SerializedView)
            {
                ServiceHelper.CopyProperties(this, (SerializedView)focus);
            }

            if (focus != null)
            {
                focus.Render(viewContext, writer);
            }
        }
        public virtual bool IsVisible(object dataItem, System.Web.Mvc.ViewContext viewContext)
        {
            var inheritable = dataItem as IInheritable;

            if (inheritable != null)
            {
                return(inheritable.IsLocalized(((Controllers.AdminControllerBase)viewContext.Controller).Site));
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 37
0
        public virtual bool IsVisible(object dataItem, System.Web.Mvc.ViewContext viewContext)
        {
            var inheritable = dataItem as IInheritable;

            if (inheritable != null)
            {
                return(inheritable.IsLocalized(Site.Current));
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 38
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            if (dataItem is IInheritable)
            {
                var inheritable = (IInheritable)dataItem;
                if (Site.Current != inheritable.Site)
                {
                    return(new HtmlString(value == null ? "" : value.ToString()));
                }
            }
            UrlHelper url = new UrlHelper(viewContext.RequestContext);

            return(new HtmlString(string.Format(@"<a href=""{0}"">{1}</a>", url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("Name", value)), value)));
        }
Exemplo n.º 39
0
        public override IHtmlString RenderItemColumn(System.Web.Mvc.ViewContext viewContext)
        {
            var isStaticPage = Kooboo.CMS.Sites.Services.ServiceFactory.PageManager.IsStaticPage(Kooboo.CMS.Sites.Models.Site.Current, (Page)DataItem);

            UrlHelper urlHelper = new UrlHelper(viewContext.RequestContext);
            var       href      = FrontUrlHelper.Preview(urlHelper, Kooboo.CMS.Sites.Models.Site.Current, (Page)DataItem, null);

            if (!isStaticPage)
            {
                return(new HtmlString(PropertyValue == null ? "" : PropertyValue.ToString()));
            }

            return(new HtmlString(string.Format(@"<a href=""{0}"" target=""_blank"" class=""o-icon preview"" title=""{2}"">{1}</a>", href, PropertyValue, PropertyValue)));
        }
Exemplo n.º 40
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            if (dataItem is IInheritable)
            {
                var inheritable = (IInheritable)dataItem;
                if (Site.Current != inheritable.Site)
                {
                    return(new HtmlString(value == null ? "" : value.ToString()));
                }
            }


            return(new HtmlString(string.Format(@"<a href=""{0}"" class=""dialog-link"" title=""{1}"">{2}</a>", GetUrl(dataItem, value, viewContext), GetTitle(dataItem, value, viewContext), GetDisplayText(dataItem, value, viewContext))));
        }
        public override IHtmlString RenderItemColumn(System.Web.Mvc.ViewContext viewContext)
        {
            var script = (ScriptFile)DataItem;

            if (script.IsLocalized(Site.Current))
            {
                UrlHelper url = new UrlHelper(viewContext.RequestContext);

                return(new HtmlString(string.Format(@"<a href=""{0}"" class=""f-icon file js dialog-link"" title=""{1}"">{2}</a>", url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("FileName", ((ScriptFile)DataItem).FileName)), "Edit".Localize(), PropertyValue)));
            }
            else
            {
                return(new HtmlString(string.Format("{0}", PropertyValue)));
            }
        }
Exemplo n.º 42
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            var htmlBlock = ((HtmlBlock)dataItem).AsActual();

            UrlHelper url = new UrlHelper(viewContext.RequestContext);

            if (htmlBlock.IsLocalized(Site.Current))
            {
                return(new HtmlString(string.Format(@"<a href=""{0}"" class=""dialog-link"" title=""{2}"">{1}</a>",
                                                    url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("Name", dataItem).
                                                               Merge("ReturnUrl", viewContext.RequestContext.HttpContext.Request.RawUrl)), value, "Edit".Localize())));
            }
            else
            {
                return(new HtmlString(dataItem.ToString()));
            }
        }
Exemplo n.º 43
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            FolderIndexInfo folderIndexInfo = (FolderIndexInfo)dataItem;

            if (folderIndexInfo.Rebuilding)
            {
                return(new HtmlString(@"<span class=""o-icon load""></span>"));
            }
            else
            {
                UrlHelper urlHelper = new UrlHelper(viewContext.RequestContext);
                return(new HtmlString(string.Format("<a href='{0}' class='o-icon rebuild actionCommand' confirm='{1}' title='{2}'>{2}</a>"
                                                    , urlHelper.Action("Rebuild", "SearchIndex", viewContext.RequestContext.AllRouteValues().Merge("FolderName", folderIndexInfo.Folder.FullName))
                                                    , "The system will automatically index new or updated content, rebuilding all may take a long time, are you sure you want to continue?".Localize()
                                                    , "Rebuild index".Localize())));
            }
        }
        public static MvcHtmlString DisplayMessages(this System.Web.Mvc.ViewContext context)
        {
            if (!context.Controller.TempData.ContainsKey(Constants.TempDataKey))
            {
                return(null);
            }

            var messages = (IEnumerable <Message>)context.Controller.TempData[Constants.TempDataKey];
            var builder  = new StringBuilder();

            foreach (var message in messages)
            {
                builder.AppendLine(message.Generate());
            }

            return(builder.ToHtmlString());
        }
Exemplo n.º 45
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {

            //string str = string.Format(@"<a class=""f-icon file js dialog-link"" href=""javascript:;"" title=""{1}"">{0}</a>", script.Name, "Edit".Localize());
            //return new HtmlString(str);
            var script = (ScriptFile)dataItem;
            if (script.IsLocalized(Site.Current))
            {
                UrlHelper url = new UrlHelper(viewContext.RequestContext);

                return new HtmlString(string.Format(@"<a href=""{0}"" class=""f-icon file js dialog-link"" title=""{1}"">{2}</a>", url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("FileName", ((ScriptFile)dataItem).FileName)), "Edit".Localize(), value));
            }
            else
            {
                return new HtmlString(string.Format("{0}", value));
            }
        }
Exemplo n.º 46
0
        public BootstrapContext(mvc.ViewContext viewContext, mvc.UrlHelper urlHelper, mvc.ViewDataDictionary viewData, Func <int, string> messageSource)
        {
            this.ViewContext   = viewContext;
            this.Url           = urlHelper;
            this.ViewData      = viewData;
            this.MessageSource = messageSource;

            var httpContext = viewContext.RequestContext.HttpContext;

            if (httpContext.Items.Contains(CachedDataContextKey))
            {
                cachedData = (Stack)httpContext.Items[CachedDataContextKey];
            }
            else
            {
                cachedData = new Stack(5);
                httpContext.Items[CachedDataContextKey] = cachedData;
            }
        }
Exemplo n.º 47
0
        public static string RenderPartialViewToString(nameFile.ControllerContext controllerContext, string viewName, object model)
        {
            nameFile.ViewDataDictionary ViewData = new nameFile.ViewDataDictionary(model);
            nameFile.TempDataDictionary TempData = new nameFile.TempDataDictionary();

            if (string.IsNullOrEmpty(viewName))
            {
                viewName = controllerContext.RouteData.GetRequiredString("action");
            }

            ViewData.Model = model;

            using (StringWriter sw = new StringWriter())
            {
                nameFile.ViewEngineResult viewResult  = nameFile.ViewEngines.Engines.FindPartialView(controllerContext, viewName);
                nameFile.ViewContext      viewContext = new nameFile.ViewContext(controllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);

                return(sw.GetStringBuilder().ToString());
            }
        }
Exemplo n.º 48
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            var    page         = ((Page)dataItem).AsActual();
            string homePageIcon = page.IsDefault ? string.Format("<span class=\"o-icon home\" title=\"{0}\"></span>", "Home page".Localize()) : "";

            if (dataItem is IInheritable)
            {
                var inheritable = (IInheritable)dataItem;
                if (!inheritable.IsLocalized(Site.Current))
                {
                    return(new HtmlString((value == null ? "" : value.ToString()) + homePageIcon));
                }
            }

            UrlHelper url = new UrlHelper(viewContext.RequestContext);

            return(new HtmlString(string.Format(@"<a name='PageName' href=""{0}"">{1}</a>",
                                                url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("FullName", page.FullName).
                                                           Merge("ReturnUrl", viewContext.RequestContext.HttpContext.Request.RawUrl))
                                                , value) + homePageIcon));
        }
Exemplo n.º 49
0
        public override IHtmlString RenderItemColumn(System.Web.Mvc.ViewContext viewContext)
        {
            var page           = (Page)DataItem;
            var allowToPublish = ServiceFactory.UserManager.Authorize(Site.Current, viewContext.HttpContext.User.Identity.Name, Kooboo.CMS.Account.Models.Permission.Sites_Page_PublishPermission);

            allowToPublish = allowToPublish && page.IsLocalized(Site.Current);
            if (allowToPublish)
            {
                string url       = "";
                var    published = (bool)PropertyValue;

                var    urlHelper = new UrlHelper(viewContext.RequestContext);
                string tip       = "Click to {0}";
                string @class    = "";
                if (published)
                {
                    url    = urlHelper.Action("Unpublish", viewContext.RequestContext.AllRouteValues().Merge("FullName", page.FullName));
                    tip    = string.Format(tip, "unpublish").Localize();
                    @class = "actionCommand";
                }
                else
                {
                    url    = urlHelper.Action("Publish", viewContext.RequestContext.AllRouteValues().Merge("FullName", page.FullName));
                    tip    = string.Format(tip, "publish").Localize();
                    @class = "dialog-link";
                }
                return(new HtmlString(string.Format(@"<a class=""o-icon {0} {1} "" href=""{2}"" title=""{3}"">{1}</a>"
                                                    , GetIconClass(PropertyValue)
                                                    , @class
                                                    , url
                                                    , tip)));
            }
            else
            {
                return(base.RenderItemColumn(viewContext));
            }
        }
Exemplo n.º 50
0
 public override IHtmlString RenderItemColumn(System.Web.Mvc.ViewContext viewContext)
 {
     return(viewContext.HtmlHelper().Partial("_ValueGridItemColumn", this.DataItem));
 }
Exemplo n.º 51
0
 public abstract override void RenderView(System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer);
Exemplo n.º 52
0
 public virtual string GetTitle(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
 {
     return("Edit".Localize());
 }
Exemplo n.º 53
0
 public System.Web.Routing.RouteValueDictionary GetValues(object dataItem, System.Web.Routing.RouteValueDictionary routeValueDictionary, System.Web.Mvc.ViewContext viewContext)
 {
     routeValueDictionary["page"]     = viewContext.RequestContext.GetRequestValue("page");
     routeValueDictionary["pageSize"] = viewContext.RequestContext.GetRequestValue("pageSize");
     return(routeValueDictionary);
 }
Exemplo n.º 54
0
        public IHtmlString Render(CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            var container = new TagBuilder("div");

            container.AddCssClass("custom-file");
            container.Attributes.Add("data-toggle", "fileupload");

            var textbox = new TagBuilder("input");

            textbox.Attributes.Add("type", "text");
            textbox.Attributes.Add("name", field.Name);
            textbox.MergeAttributes(field.GetUnobtrusiveValidationAtributes());

            RouteValueDictionary additionHtmlAttributes = null;

            if (htmlAttributes != null)
            {
                additionHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

                var databind = additionHtmlAttributes["data-bind"];
                if (databind != null)
                {
                    additionHtmlAttributes.Remove("data-bind");
                    textbox.MergeAttribute("data-bind", databind.ToString());
                }

                container.MergeAttributes(additionHtmlAttributes);
            }

            var button = new TagBuilder("a");

            button.AddCssClass("button");

            var span = new TagBuilder("span");

            var fileInput = new TagBuilder("input");

            fileInput.Attributes.Add("type", "file");
            fileInput.Attributes.Add("id", field.Name);
            fileInput.Attributes.Add("name", field.Name);

            span.InnerHtml   = fileInput.ToString(TagRenderMode.SelfClosing);
            button.InnerHtml = "Browse..." + span.ToString();

            container.InnerHtml = String.Concat(textbox.ToString(TagRenderMode.SelfClosing), button.ToString());

            return(new HtmlString(container.ToString()));
        }
Exemplo n.º 55
0
        public virtual string GetUrl(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            UrlHelper url = new UrlHelper(viewContext.RequestContext);

            return(url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("Name", value)));
        }
Exemplo n.º 56
0
 public virtual string GetDisplayText(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
 {
     return(value.ToString());
 }
Exemplo n.º 57
0
        public System.Web.Routing.RouteValueDictionary GetValues(object dataItem, System.Web.Routing.RouteValueDictionary routeValueDictionary, System.Web.Mvc.ViewContext viewContext)
        {
            var folder = ((Folder)dataItem).AsActual();

            //if (folder is ContainerFolder)
            //{
            //    routeValueDictionary["folderType"] = "Container";
            //}
            if (folder is TextFolder)
            {
                routeValueDictionary["folderType"] = "Text";
            }
            else if (folder is MediaFolder)
            {
                routeValueDictionary["folderType"] = "Binary";
            }
            return(routeValueDictionary);
        }
Exemplo n.º 58
0
 protected TreeViewBase(System.Web.Mvc.ViewContext viewContext, Kendo.Mvc.Infrastructure.IJavaScriptInitializer initializer, ViewDataDictionary viewData = null)
     : this(viewContext, viewData)
 {
     this.Initializer = initializer;
 }
Exemplo n.º 59
0
        protected override void BuildControl(System.Web.Mvc.TagBuilder builder, Products.CustomFieldDefinition field, string value, object htmlAttributes, System.Web.Mvc.ViewContext viewContext)
        {
            builder.AddCssClass("form-list");

            var itemsHtml = new StringBuilder();
            var i         = 0;

            foreach (var item in field.SelectionItems)
            {
                itemsHtml.AppendLine("<li>");

                var radioId = field.Name + "_" + i;
                var radio   = new TagBuilder("input");
                radio.MergeAttribute("id", radioId);
                radio.MergeAttribute("type", "radio");
                radio.MergeAttribute("name", field.Name);
                radio.MergeAttribute("value", item.Value);

                var label = new TagBuilder("label");
                label.InnerHtml = item.Text;
                label.AddCssClass("inline");
                label.MergeAttribute("for", radioId);

                itemsHtml.AppendLine(radio.ToString(TagRenderMode.SelfClosing));
                itemsHtml.AppendLine(label.ToString());

                itemsHtml.AppendLine("</li>");

                i++;
            }

            builder.InnerHtml = itemsHtml.ToString();

            base.BuildControl(builder, field, value, htmlAttributes, viewContext);
        }
Exemplo n.º 60
0
        public IHtmlString Render(object dataItem, object value, System.Web.Mvc.ViewContext viewContext)
        {
            UrlHelper url = new UrlHelper(viewContext.RequestContext);

            return(new HtmlString(string.Format(@"<a href=""{0}"" class=""dialog-link"" title=""{1}"">{2}</a>", url.Action("Edit", viewContext.RequestContext.AllRouteValues().Merge("UserName", value)), "Edit".Localize(), value)));
        }