protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (!Context.ClientPage.IsEvent) { if (!WebDAVConfiguration.IsWebDAVEnabled(true)) { this.OpenWebDAVViewButton.Visible = false; } MediaBrowserOptions options = MediaBrowserOptions.Parse(); Item root = options.Root; if (root != null) { this.MediaDataContext.Root = root.ID.ToString(); } Item selectedItem = options.SelectedItem; if (selectedItem != null) { this.MediaDataContext.Folder = selectedItem.ID.ToString(); } Item folder = this.MediaDataContext.GetFolder(); Assert.IsNotNull(folder, "Item not found."); this.UpdateSelection(folder); } }
protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); MediaBrowserOptions options = MediaBrowserOptions.Parse(); string str = this.Filename.Value; if (options.AllowEmpty && string.IsNullOrEmpty(str)) { SheerResponse.SetDialogValue(string.Empty); base.OnOK(sender, args); } else if (string.IsNullOrEmpty(str)) { SheerResponse.Alert(Translate.Text("Select a media item."), new string[0]); } else { Item root = this.MediaDataContext.GetRoot(); if ((root != null) && (root.ID != root.Database.GetRootItem().ID)) { str = FileUtil.MakePath(root.Paths.Path, str, '/'); } Item item = this.MediaDataContext.GetItem(str); if (item == null) { SheerResponse.Alert(Translate.Text("The media item could not be found."), new string[0]); } else if (IsFolderItem(item)) { this.MediaDataContext.SetFolder(item.Uri); } else { SheerResponse.SetDialogValue(item.ID.ToString()); base.OnOK(sender, args); } } }
/// <summary> /// Browses for an image. /// /// </summary> /// <param name="args">The args.</param><exception cref="T:Sitecore.Exceptions.ClientAlertException">The source of this Image field points to an item that does not exist.</exception> protected new void BrowseImage(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.IsPostBack) { if (string.IsNullOrEmpty(args.Result) || args.Result == "undefined") { return; } MediaItem mediaItem = Client.ContentDatabase.Items[args.Result]; if (mediaItem != null) { var template = mediaItem.InnerItem.Template; if (template != null && !IsImageMedia(template)) { SheerResponse.Alert("The selected item does not contain an image."); } else { XmlValue.SetAttribute("mediaid", mediaItem.ID.ToString()); var croppingOption = GetCroppingOption(); var cropRegion = ProduceCropRegionXmlAttributeValueFromAnOption(mediaItem, croppingOption); if (!string.IsNullOrWhiteSpace(cropRegion)) { XmlValue.SetAttribute("cropregion", cropRegion); XmlValue.SetAttribute("ratio", string.Concat(croppingOption.Width, ":", croppingOption.Height)); } XmlValue.SetAttribute("width", croppingOption.Width.ToString()); XmlValue.SetAttribute("height", croppingOption.Height.ToString()); Value = mediaItem.MediaPath; Update(); SetModified(); } } else { SheerResponse.Alert("Item not found."); } } else { var souceValues = HttpUtility.ParseQueryString(Source); var mediaSource = string.Empty; if (souceValues.AllKeys.Any()) { mediaSource = souceValues["mediaSource"]; } var str1 = StringUtil.GetString(new string[2] { mediaSource, "/sitecore/media library" }); var str2 = str1; var path = XmlValue.GetAttribute("mediaid"); var str3 = path; if (str1.StartsWith("~", StringComparison.InvariantCulture)) { str2 = StringUtil.Mid(str1, 1); if (string.IsNullOrEmpty(path)) { path = str2; } str1 = "/sitecore/media library"; } var language = Language.Parse(ItemLanguage); var mediaBrowserOptions = new MediaBrowserOptions(); var obj1 = Client.ContentDatabase.GetItem(str1, language); if (obj1 == null) { throw new ClientAlertException("The source of this Image field points to an item that does not exist."); } mediaBrowserOptions.Root = obj1; if (!string.IsNullOrEmpty(path)) { var obj2 = Client.ContentDatabase.GetItem(path, language); if (obj2 != null) { mediaBrowserOptions.SelectedItem = obj2; } } var urlHandle = new UrlHandle(); urlHandle["ro"] = str1; urlHandle["fo"] = str2; urlHandle["db"] = Client.ContentDatabase.Name; urlHandle["la"] = ItemLanguage; urlHandle["va"] = str3; var urlString = mediaBrowserOptions.ToUrlString(); urlHandle.Add(urlString); SheerResponse.ShowModalDialog(urlString.ToString(), "1200px", "700px", string.Empty, true); args.WaitForPostBack(); } }
/// <summary> /// Browses for an image. /// /// </summary> /// <param name="args">The args.</param><exception cref="T:Sitecore.Exceptions.ClientAlertException">The source of this Image field points to an item that does not exist.</exception> protected new void BrowseImage(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (args.IsPostBack) { if (string.IsNullOrEmpty(args.Result) || args.Result == "undefined") return; MediaItem mediaItem = Client.ContentDatabase.Items[args.Result]; if (mediaItem != null) { var template = mediaItem.InnerItem.Template; if (template != null && !IsImageMedia(template)) { SheerResponse.Alert("The selected item does not contain an image."); } else { XmlValue.SetAttribute("mediaid", mediaItem.ID.ToString()); var croppingOption = GetCroppingOption(); var cropRegion = ProduceCropRegionXmlAttributeValueFromAnOption(mediaItem, croppingOption); if (!string.IsNullOrWhiteSpace(cropRegion)) { XmlValue.SetAttribute("cropregion", cropRegion); XmlValue.SetAttribute("ratio", string.Concat(croppingOption.Width, ":", croppingOption.Height)); } XmlValue.SetAttribute("width", croppingOption.Width.ToString()); XmlValue.SetAttribute("height", croppingOption.Height.ToString()); Value = mediaItem.MediaPath; Update(); SetModified(); } } else SheerResponse.Alert("Item not found."); } else { var souceValues = HttpUtility.ParseQueryString(Source); var mediaSource = string.Empty; if (souceValues.AllKeys.Any()) { mediaSource = souceValues["mediaSource"]; } var str1 = StringUtil.GetString(new string[2] { mediaSource, "/sitecore/media library" }); var str2 = str1; var path = XmlValue.GetAttribute("mediaid"); var str3 = path; if (str1.StartsWith("~", StringComparison.InvariantCulture)) { str2 = StringUtil.Mid(str1, 1); if (string.IsNullOrEmpty(path)) path = str2; str1 = "/sitecore/media library"; } var language = Language.Parse(ItemLanguage); var mediaBrowserOptions = new MediaBrowserOptions(); var obj1 = Client.ContentDatabase.GetItem(str1, language); if (obj1 == null) throw new ClientAlertException("The source of this Image field points to an item that does not exist."); mediaBrowserOptions.Root = obj1; if (!string.IsNullOrEmpty(path)) { var obj2 = Client.ContentDatabase.GetItem(path, language); if (obj2 != null) mediaBrowserOptions.SelectedItem = obj2; } var urlHandle = new UrlHandle(); urlHandle["ro"] = str1; urlHandle["fo"] = str2; urlHandle["db"] = Client.ContentDatabase.Name; urlHandle["la"] = ItemLanguage; urlHandle["va"] = str3; var urlString = mediaBrowserOptions.ToUrlString(); urlHandle.Add(urlString); SheerResponse.ShowModalDialog(urlString.ToString(), "1200px", "700px", string.Empty, true); args.WaitForPostBack(); } }
protected void AddItem(ClientPipelineArgs args) { if (args.IsPostBack) { if (args.HasResult) { SetModified(); LastSelectedItemID = args.Result; SheerResponse.Eval("window.frames['{0}_frame'].window.scVisualList.addItem('{1}');".FormatWith(ID, args.Result)); } } else { var source = new UrlString(StringUtil.GetString(Source, "/sitecore/media library")).Path; Item lastSelectedItem = null; if (!string.IsNullOrEmpty(LastSelectedItemID)) { lastSelectedItem = Client.ContentDatabase.GetItem(LastSelectedItemID); } if (source.Contains("/sitecore/media library")) { var options = new MediaBrowserOptions(); if (source.StartsWith("~")) { options.Root = Client.GetItemNotNull(ItemIDs.MediaLibraryRoot); options.SelectedItem = Client.GetItemNotNull(source.Substring(1)); } else { options.Root = Client.GetItemNotNull(source); } if (lastSelectedItem != null && lastSelectedItem.Parent.Paths.IsDescendantOf(options.Root)) { options.SelectedItem = lastSelectedItem.Parent; } SheerResponse.ShowModalDialog(options.ToUrlString().ToString(), true); } else { var options = new SelectItemOptions { Title = "Please Select an Item", Text = "Select an item to add", Icon = "Applications/32x32/star_green.png" }; if (source.StartsWith("~")) { options.Root = Client.GetItemNotNull(ItemIDs.ContentRoot); options.SelectedItem = Client.GetItemNotNull(source.Substring(1)); } else { options.Root = Client.GetItemNotNull(source); } if (lastSelectedItem != null && lastSelectedItem.Paths.IsDescendantOf(options.Root)) { options.SelectedItem = lastSelectedItem; } SheerResponse.ShowModalDialog(options.ToUrlString().ToString(), true); } args.WaitForPostBack(); } }
protected new static void Run(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Item itemNotNull = Client.GetItemNotNull(args.Parameters["itemid"]); itemNotNull.Fields.ReadAll(); Field field = itemNotNull.Fields[args.Parameters["fieldid"]]; Assert.IsNotNull(field, "field"); ImageField imageField = new ImageField(field, field.Value); string controlid = args.Parameters["controlid"]; if (args.IsPostBack) { if (args.Result != "undefined") { string rawValue; if (!string.IsNullOrEmpty(args.Result)) { MediaItem item = Client.ContentDatabase.Items[args.Result]; if (item != null) { MediaUrlOptions mediaOptions = new MediaUrlOptions(); string mediaUrl = MediaManager.GetMediaUrl(item, mediaOptions); imageField.SetAttribute("mediaid", item.ID.ToString()); imageField.SetAttribute("mediapath", item.MediaPath); imageField.SetAttribute("src", mediaUrl); if (!string.IsNullOrEmpty(args.Parameters["fieldValue"])) { XmlValue xmlValue = new XmlValue(args.Parameters["fieldValue"], "image"); string height = xmlValue.GetAttribute("height"); if (!String.IsNullOrEmpty(height)) { imageField.Height = height; } string width = xmlValue.GetAttribute("width"); if (!String.IsNullOrEmpty(width)) { imageField.Width = width; } } } else { SheerResponse.Alert("Item not found.", new string[0]); } rawValue = imageField.Value; } else { rawValue = string.Empty; } string markup = WebEditImageCommand.RenderImage(args, rawValue); SheerResponse.SetAttribute("scHtmlValue", "value", markup); SheerResponse.SetAttribute("scPlainValue", "value", rawValue); SheerResponse.Eval("scSetHtmlValue('" + rawValue + "')"); } } else { string text = StringUtil.GetString(new string[] { field.Source, ImageSourceHelper.MEDIA_ROOT }); if (text.StartsWith(ImageSourceHelper.SITE_SOURCE_PREFIX)) { string path = ImageSourceHelper.GetSiteMediaPath(itemNotNull); if (path != null) { text = path; } } string mediaid = imageField.GetAttribute("mediaid"); if (text.StartsWith("~")) { if (string.IsNullOrEmpty(mediaid)) { mediaid = StringUtil.Mid(text, 1); } text = ImageSourceHelper.MEDIA_ROOT; } Language language = itemNotNull.Language; MediaBrowserOptions mediaOptions = new MediaBrowserOptions(); Item item3 = Client.ContentDatabase.GetItem(text, language); if (item3 == null) { throw new ClientAlertException("The source of this Image field points to an item that does not exist."); } mediaOptions.Root = item3; mediaOptions.AllowEmpty = true; if (!string.IsNullOrEmpty(mediaid)) { Item selected = Client.ContentDatabase.GetItem(mediaid, language); if (selected != null) { mediaOptions.SelectedItem = selected; } } SheerResponse.ShowModalDialog(mediaOptions.ToUrlString().ToString(), true); args.WaitForPostBack(); } }
protected void BrowseImage(ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); if (!args.IsPostBack) { //string[] source = new string[] { this.Source, "/sitecore/media library" }; string[] source = new string[] { "/sitecore/media library" }; string str = StringUtil.GetString(source); string str1 = str; string attribute = this.XmlValue.GetAttribute("mediaid"); string str2 = attribute; if (str.StartsWith("~", StringComparison.InvariantCulture)) { str1 = StringUtil.Mid(str, 1); if (string.IsNullOrEmpty(attribute)) { attribute = str1; } str = "/sitecore/media library"; } Language language = Language.Parse(this.ItemLanguage); MediaBrowserOptions mediaBrowserOption = new MediaBrowserOptions(); Item item = Client.ContentDatabase.GetItem(str, language); if (item == null) { throw new ClientAlertException("The source of this Image field points to an item that does not exist."); } mediaBrowserOption.Root = item; if (!string.IsNullOrEmpty(attribute)) { Item item1 = Client.ContentDatabase.GetItem(attribute, language); if (item1 != null) { mediaBrowserOption.SelectedItem = item1; } } UrlHandle urlHandle = new UrlHandle(); urlHandle["ro"] = str; urlHandle["fo"] = str1; urlHandle["db"] = Client.ContentDatabase.Name; urlHandle["la"] = this.ItemLanguage; urlHandle["va"] = str2; UrlString urlString = mediaBrowserOption.ToUrlString(); urlHandle.Add(urlString); SheerResponse.ShowModalDialog(urlString.ToString(), "1200px", "700px", string.Empty, true); args.WaitForPostBack(); } else if (!string.IsNullOrEmpty(args.Result) && args.Result != "undefined") { MediaItem mediaItem = Client.ContentDatabase.Items[args.Result]; if (mediaItem == null) { SheerResponse.Alert("Item not found.", new string[0]); return; } TemplateItem template = mediaItem.InnerItem.Template; if (template != null && !this.IsImageMedia(template)) { SheerResponse.Alert("The selected item does not contain an image.", new string[0]); return; } this.XmlValue.SetAttribute("mediaid", mediaItem.ID.ToString()); this.Value = mediaItem.MediaPath; this.Update(false); this.SetModified(); return; } }