Exemple #1
0
        }         // RenderEdit

        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            ImageGalleryData data = new ImageGalleryData();

            data.subDir          = "images" + DirSeperator + "ImageGallery" + DirSeperator;
            data.thumbSize       = 200;
            data.largeSize       = 500;
            data.numThumbsPerRow = 3;

            ImageGalleryDb db = new ImageGalleryDb();

            data = db.getImageGallery(page, identifier, true);

            if (!data.subDir.EndsWith(DirSeperator))
            {
                data.subDir += DirSeperator;
            }



            if (currentViewRenderMode == RenderMode.FullSize)
            {             // -- render full size
                writer.Write("<div class=\"ImageGallery FullSize\">");
                string jpg = PageUtils.getFromForm("galleryImg", "");
                if (jpg == "")
                {
                    writer.Write("Invalid galleryImg parameter");
                    return;
                }

                string imgCaption            = "";
                int    currentImageDataIndex = -1;
                for (int i = 0; i < data.ImageData.Length; i++)
                {
                    ImageGalleryImageData d = data.ImageData[i];
                    if (Path.GetFileName(d.Filename) == Path.GetFileName(jpg) || d.Filename == jpg)
                    {
                        imgCaption            = "<p align=\"center\" class=\"caption full\">" + d.Caption + "</p>";
                        currentImageDataIndex = i;
                        break;
                    }
                }

                string imgFilenameUnderAppPath = data.subDir + Path.GetFileName(jpg);
                string largeUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(imgFilenameUnderAppPath, data.largeSize, -1);

                string backUrl = CmsContext.getUrlByPagePath(page.Path);
                writer.Write("<p class=\"ImageGalleryBackLink\"><a class=\"ImageGalleryBackLink\" href=\"" + backUrl + "\">&#171; back to thumbnails</a><p>");

                List <string> nextPrevLinks = new List <string>();
                if (currentImageDataIndex > 0)
                {
                    NameValueCollection prevImgParams = new NameValueCollection();
                    prevImgParams.Add("galleryMode", Convert.ToInt32(RenderMode.FullSize).ToString());
                    prevImgParams.Add("galleryImg", Path.GetFileName(data.ImageData[currentImageDataIndex - 1].Filename));
                    string prevUrl  = CmsContext.getUrlByPagePath(page.Path, prevImgParams);
                    string prevHtml = "<a class=\"ImageGalleryBackLink prev\" href=\"" + prevUrl + "\">&#171; prev</a>";
                    nextPrevLinks.Add(prevHtml);
                }

                if (data.ImageData.Length > 1 && currentImageDataIndex < (data.ImageData.Length - 1))
                {
                    NameValueCollection nextImgParams = new NameValueCollection();
                    nextImgParams.Add("galleryMode", Convert.ToInt32(RenderMode.FullSize).ToString());
                    nextImgParams.Add("galleryImg", Path.GetFileName(data.ImageData[currentImageDataIndex + 1].Filename));
                    string nextUrl  = CmsContext.getUrlByPagePath(page.Path, nextImgParams);
                    string nextHtml = "<a class=\"ImageGalleryBackLink next\" href=\"" + nextUrl + "\">next &#187;</a>";
                    nextPrevLinks.Add(nextHtml);
                }

                if (nextPrevLinks.Count > 0)
                {
                    writer.Write("<p class=\"ImageGalleryBackLink\">" + string.Join(" | ", nextPrevLinks.ToArray()) + "</p>");
                }


                writer.Write("<img class=\"ImageGalleryFullSizedImage\" src=\"" + largeUrl + "\">");
                writer.WriteLine(imgCaption);
            }
            else
            {             // -- render the directory
                writer.Write("<div class=\"ImageGallery thumbnails\">");

                string ImageGalleryId = "ImageGallery_" + page.Id.ToString() + "_" + identifier.ToString();
                string thumbViewHtml  = getHtmlForThumbView(page, data, ImageGalleryId, false);
                writer.WriteLine(thumbViewHtml);
            }     // render directory
            writer.Write("</div>");
        }         // RenderView
Exemple #2
0
        public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            ImageGalleryDb   db   = new ImageGalleryDb();
            ImageGalleryData data = new ImageGalleryData();

            data.subDir          = "";
            data.thumbSize       = 200;
            data.largeSize       = 500;
            data.numThumbsPerRow = 3;

            data = db.getImageGallery(page, identifier, true);

            string ImageGalleryId = "ImageGallery_" + page.Id.ToString() + "_" + identifier.ToString();

            // ------- CHECK THE FORM FOR ACTIONS
            string action = Hatfield.Web.Portal.PageUtils.getFromForm(ImageGalleryId + "_Action", "");

            if (action.Trim().ToLower() == "update")
            {
                data.ImageGalleryId  = PageUtils.getFromForm(ImageGalleryId + "_DataId", -1);
                data.subDir          = PageUtils.getFromForm("subDir_" + ImageGalleryId, "");
                data.thumbSize       = PageUtils.getFromForm("thumbSize_" + ImageGalleryId, data.thumbSize);
                data.largeSize       = PageUtils.getFromForm("largeSize_" + ImageGalleryId, data.largeSize);
                data.numThumbsPerRow = PageUtils.getFromForm("numThumbsPerRow_" + ImageGalleryId, data.numThumbsPerRow);

                string[] captionIds = PageUtils.getFromForm(ImageGalleryId + "_captions");
                foreach (string captionId in captionIds)
                {
                    // captionId is in the form
                    // "imgCaption"+ImageGalleryId+"_"+imgFilenameUnderAppPath;
                    if (captionId != "")
                    {
                        string capId = System.Web.HttpUtility.UrlDecode(captionId);
                        if (capId.StartsWith("imgCaption" + ImageGalleryId + "_"))
                        {
                            string imgFilenameUnderAppPath = capId.Substring(("imgCaption" + ImageGalleryId + "_").Length);
                            string caption            = PageUtils.getFromForm(System.Web.HttpUtility.UrlEncode(capId), "");
                            ImageGalleryImageData img = data.getImageData(imgFilenameUnderAppPath);
                            img.Caption  = caption;
                            img.Filename = imgFilenameUnderAppPath;

                            if (img.ImageGalleryImageId < 0)
                            {
                                data.addImage(img);
                            }
                        }
                    }
                }

                db.saveUpdatedImageGallery(page, identifier, data);
            }

            // ------- START RENDERING
            // note: no need to put in the <form></form> tags.

            StringBuilder html = new StringBuilder();

            html.Append("<strong>Image Gallery Settings:</strong><br>");
            html.Append("<table>");

            string[] subDirs = getAllAvailableSubDirs();
            string   s       = PageUtils.getDropDownHtml("subDir_" + ImageGalleryId, "subDir_" + ImageGalleryId, subDirs, data.subDir);

            html.Append("<tr><td>Image SubDirectory:</td>");
            html.Append("<td>" + s + "</td></tr>");

            s = PageUtils.getInputTextHtml("numThumbsPerRow_" + ImageGalleryId, "numThumbsPerRow_" + ImageGalleryId, data.numThumbsPerRow.ToString(), 3, 5);
            html.Append("<tr><td>Number of Thumbnails per row:</td>");
            html.Append("<td>" + s + "</td></tr>");

            s = PageUtils.getInputTextHtml("thumbSize_" + ImageGalleryId, "thumbSize_" + ImageGalleryId, data.thumbSize.ToString(), 3, 5);
            html.Append("<tr><td>Thumbnail Size:</td>");
            html.Append("<td>" + s + "</td></tr>");

            s = PageUtils.getInputTextHtml("largeSize_" + ImageGalleryId, "largeSize_" + ImageGalleryId, data.largeSize.ToString(), 3, 5);
            html.Append("<tr><td>Full-Sized Image size:</td>");
            html.Append("<td>" + s + "</td></tr>");


            html.Append("</table>");

            string thumbViewHtml = getHtmlForThumbView(page, data, ImageGalleryId, true);

            writer.WriteLine(thumbViewHtml);

            html.Append("<input type=\"hidden\" name=\"" + ImageGalleryId + "_Action\" value=\"update\">");
            html.Append("<input type=\"hidden\" name=\"" + ImageGalleryId + "_DataId\" value=\"" + data.ImageGalleryId.ToString() + "\">");

            writer.WriteLine(html.ToString());
        }         // RenderEdit