Example #1
0
        private string getHtmlForThumbView(CmsPage page, ImageGalleryData data, string ImageGalleryId, bool inEditMode)
        {
            StringBuilder html            = new StringBuilder();
            string        DirOnDiskToView = getDirOnDiskToView(data);


            if (!Directory.Exists(DirOnDiskToView))
            {
                return("Error with Image Gallery: ImageGallery directory does not exist!");
            }

            string[] JPGFiles = Directory.GetFiles(DirOnDiskToView, "*.jpg");
            if (JPGFiles.Length < 1)
            {
                return("no images are in this image gallery");
            }

            html.Append("<table>");
            int       imgCount         = 0;
            ArrayList formCaptionNames = new ArrayList();

            foreach (string jpg in JPGFiles)
            {
                if (imgCount % data.numThumbsPerRow == 0)
                {
                    html.Append("<tr>");
                }

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

                ImageGalleryImageData imgData = data.getImageData(imgFilenameUnderAppPath);

                NameValueCollection imgParams = new NameValueCollection();
                imgParams.Add("galleryMode", Convert.ToInt32(RenderMode.FullSize).ToString());
                imgParams.Add("galleryImg", Path.GetFileName(jpg));

                string fullSizeUrl = CmsContext.getUrlByPagePath(page.Path, imgParams);

                html.Append("<td class=\"ImageGalleryImage_td\">");

                if (!inEditMode)
                {
                    html.Append("<a class=\"ImageGalleryImageLink\" href=\"" + fullSizeUrl + "\">");
                }

                html.Append("<img class=\"ImageGalleryImage\" src=\"" + thumbUrl + "\">");

                if (!inEditMode)
                {
                    html.Append("</a>");
                }

                html.Append("<br>");
                if (inEditMode)
                {
                    string tbName = System.Web.HttpUtility.UrlEncode("imgCaption" + ImageGalleryId + "_" + imgFilenameUnderAppPath);
                    formCaptionNames.Add(tbName);
                    string tb = PageUtils.getInputTextHtml(tbName, tbName, imgData.Caption, 15, 255);
                    tb = "<nobr>caption: " + tb + "</nobr>";
                    html.Append(tb);
                }
                else
                {
                    html.Append(imgData.Caption);
                }
                html.Append("</td>");
                if (imgCount % data.numThumbsPerRow == data.numThumbsPerRow)
                {
                    html.Append("</tr>");
                }

                imgCount++;
            }
            if (imgCount % data.numThumbsPerRow != data.numThumbsPerRow)
            {
                html.Append("</tr>");
            }
            html.Append("</table>");

            if (inEditMode)
            {
                string csv = "";
                foreach (string id in formCaptionNames)
                {
                    csv = csv + id + ",";
                }
                string h = PageUtils.getHiddenInputHtml(ImageGalleryId + "_captions", csv);
                html.Append(h);
            }

            return(html.ToString());
        } // getHtmlForThumbView
Example #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