Ejemplo n.º 1
0
        protected void gvImages_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var c = (ContentBlockSettingListItem)e.Row.DataItem;
                if (c == null)
                {
                    return;
                }

                e.Row.Attributes["id"] = c.Id;
                var aPreview   = e.Row.FindControl("aPreview") as HtmlAnchor;
                var imgPreview = e.Row.FindControl("imgPreview") as HtmlImage;

                var img = new ImageRotatorImageViewModel();
                img.ImageUrl = ResolveSpecialUrl(c.Setting1);
                img.Url      = c.Setting2;
                if (img.Url.StartsWith("~"))
                {
                    img.Url = ResolveUrl(img.Url);
                }
                img.NewWindow = c.Setting3 == "1";
                img.Caption   = c.Setting4;

                aPreview.HRef = img.Url;
                if (img.NewWindow)
                {
                    aPreview.Target = "_blank";
                }

                imgPreview.Src = img.ImageUrl;
                imgPreview.Alt = HttpUtility.HtmlEncode(img.Caption);
            }
        }
Ejemplo n.º 2
0
        public string Render(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, MerchantTribe.Commerce.Content.ContentBlock block)
        {
            ImageRotatorViewModel model = new ImageRotatorViewModel();

            if (block != null)
            {
                var imageList = block.Lists.FindList("Images");
                foreach (var listItem in imageList)
                {
                    ImageRotatorImageViewModel img = new ImageRotatorImageViewModel();
                    img.ImageUrl = ResolveUrl(listItem.Setting1, app);
                    img.Url      = listItem.Setting2;
                    if (img.Url.StartsWith("~"))
                    {
                        img.Url = app.CurrentRequestContext.UrlHelper.Content(img.Url);
                    }
                    img.NewWindow = (listItem.Setting3 == "1");
                    img.Caption   = listItem.Setting4;
                    model.Images.Add(img);
                }
                string cleanId = MerchantTribe.Web.Text.ForceAlphaNumericOnly(block.Bvin);
                model.CssId    = "rotator" + cleanId;
                model.CssClass = block.BaseSettings.GetSettingOrEmpty("cssclass");

                model.Height = block.BaseSettings.GetIntegerSetting("Height");
                model.Width  = block.BaseSettings.GetIntegerSetting("Width");

                if (block.BaseSettings.GetBoolSetting("ShowInOrder") == false)
                {
                    RandomizeList(model.Images);
                }
            }

            return(RenderModel(model));
        }
Ejemplo n.º 3
0
 private void RandomizeList(List <ImageRotatorImageViewModel> list)
 {
     System.Random rand = new Random();
     for (int i = list.Count - 1; i >= 0; i--)
     {
         int n = rand.Next(i + 1);
         // Swap
         ImageRotatorImageViewModel temp = list[i];
         list[i] = list[n];
         list[n] = temp;
     }
 }
 public static void RenderSingleImage(StringBuilder sb, ImageRotatorImageViewModel img, int height, int width)
 {
     sb.Append("<a href=\"" + img.Url + "\" ");
     if (img.NewWindow == true)
     {
         sb.Append(" target=\"_blank\"");
     }
     sb.Append(">");
     sb.Append("<div style=\"height:" + height + "px;overflow:hidden\">");
     sb.Append("<img src=\"" + img.ImageUrl + "\" alt=\"" + HttpUtility.HtmlEncode(img.Caption) + "\" width=\"" + width + "\" />");
     sb.Append("</div>");
     sb.Append("</a>");
 }
Ejemplo n.º 5
0
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }

            ContentBlockSettingListItem c = (ContentBlockSettingListItem)e.Row.DataItem;

            if (c == null)
            {
                return;
            }

            PlaceHolder ph = (PlaceHolder)e.Row.FindControl("phImagePreview");

            if (ph == null)
            {
                return;
            }

            ImageRotatorImageViewModel img = new ImageRotatorImageViewModel();

            img.ImageUrl = ResolveSpecialUrl(c.Setting1);
            img.Url      = c.Setting2;
            if (img.Url.StartsWith("~"))
            {
                img.Url = Page.ResolveUrl(img.Url);
            }
            img.NewWindow = (c.Setting3 == "1");
            img.Caption   = c.Setting4;

            StringBuilder sb = new StringBuilder();

            ImageRotatorRenderController.RenderSingleImage(sb, img, 75, 75);
            ph.Controls.Add(new LiteralControl(sb.ToString()));
        }
Ejemplo n.º 6
0
        public ActionResult Index(ContentBlock block)
        {
            var model = new ImageRotatorViewModel();

            if (block != null)
            {
                var imageList = block.Lists.FindList("Images");
                foreach (var listItem in imageList)
                {
                    var img = new ImageRotatorImageViewModel
                    {
                        ImageUrl = ResolveUrl(listItem.Setting1),
                        Url      = listItem.Setting2
                    };
                    if (img.Url.StartsWith("~"))
                    {
                        img.Url = Url.Content(img.Url);
                    }
                    img.NewWindow = listItem.Setting3 == "1";
                    img.Caption   = listItem.Setting4;
                    model.Images.Add(img);
                }
                var cleanId = Text.ForceAlphaNumericOnly(block.Bvin);
                model.CssId    = "rotator" + cleanId;
                model.CssClass = block.BaseSettings.GetSettingOrEmpty("cssclass");

                model.Height = block.BaseSettings.GetIntegerSetting("Height");
                model.Width  = block.BaseSettings.GetIntegerSetting("Width");

                if (block.BaseSettings.GetBoolSetting("ShowInOrder") == false)
                {
                    RandomizeList(model.Images);
                }
            }

            return(View(model));
        }