private bool SetInternalLinkAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); Item selectionItem = this.InternalLinkTreeview.GetSelectionItem(); if (selectionItem == null) { Context.ClientPage.ClientResponse.Alert("Select an item."); return(false); } string attributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); string str = this.Querystring.Value; if (str.StartsWith("?", StringComparison.InvariantCulture)) { str = str.Substring(1); } LinkForm.SetAttribute(packet, Attributes.anchor, (Sitecore.Web.UI.HtmlControls.Control) this.LinkAnchor); LinkForm.SetAttribute(packet, Attributes.querystring, str); LinkForm.SetAttribute(packet, Attributes.target, attributeFromValue); LinkForm.SetAttribute(packet, Attributes.id, selectionItem.ID.ToString()); this.TrimComboboxControl(this.GoalId); LinkForm.SetAttribute(packet, Attributes.goalid, this.GoalId); this.TrimComboboxControl(this.EventId); LinkForm.SetAttribute(packet, Attributes.eventid, this.EventId); return(true); }
protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); string path = this.GetPath(); string attributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); Packet packet = new Packet("link"); LinkForm.SetAttribute(packet, "text", this.Text); LinkForm.SetAttribute(packet, "linktype", "external"); LinkForm.SetAttribute(packet, "url", path); LinkForm.SetAttribute(packet, "anchor", string.Empty); LinkForm.SetAttribute(packet, "title", this.Title); LinkForm.SetAttribute(packet, "class", this.Class); LinkForm.SetAttribute(packet, "target", attributeFromValue); this.TrimComboboxControl(this.Goal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalTriggerAttName, this.TriggerGoal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalAttributeName, this.Goal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalDataAttName, this.GoalData); this.TrimComboboxControl(this.PageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventTriggerAttName, this.TriggerPageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventAttributeName, this.PageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventDataAttName, this.PageEventData); SheerResponse.SetDialogValue(packet.OuterXml); SheerResponse.CloseWindow(); }
/// <summary> /// Raises the load event. /// </summary> /// <param name="e"> /// The <see cref="T:System.EventArgs" /> instance containing the event data. /// </param> /// <remarks> /// This method notifies the server control that it should perform actions common to each HTTP /// request for the page it is associated with, such as setting up a database query. At this /// stage in the page lifecycle, server controls in the hierarchy are created and initialized, /// view state is restored, and form controls reflect client-side data. Use the IsPostBack /// property to determine whether the page is being loaded in response to a client postback, /// or if it is being loaded and accessed for the first time. /// </remarks> protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (Context.ClientPage.IsEvent) { return; } string item = base.LinkAttributes["url"]; if (base.LinkType != "external") { item = string.Empty; } string empty = string.Empty; string str = base.LinkAttributes["target"]; string linkTargetValue = LinkForm.GetLinkTargetValue(str); if (linkTargetValue == "Custom") { empty = str; this.CustomTarget.Disabled = false; this.CustomLabel.Disabled = false; } this.Text.Value = base.LinkAttributes["text"]; this.Url.Value = item; this.Target.Value = linkTargetValue; this.CustomTarget.Value = empty; this.Class.Value = base.LinkAttributes["class"]; this.Title.Value = base.LinkAttributes["title"]; this.CustomAttributes.Value = GetLinkValue(this.GetLink(), "customattributes"); this.Test.ToolTip = Translate.Text("Open the specified URL in a browser."); }
private void SetCommonAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); LinkForm.SetAttribute(packet, Attributes.linktype, this.CurrentMode); LinkForm.SetAttribute(packet, Attributes.text, (Sitecore.Web.UI.HtmlControls.Control) this.Text); LinkForm.SetAttribute(packet, Attributes.title, (Sitecore.Web.UI.HtmlControls.Control) this.Title); LinkForm.SetAttribute(packet, Attributes._class, (Sitecore.Web.UI.HtmlControls.Control) this.Class); }
public Result GenerateTestData(int count) { Random randomData = new Random(); int range = 5 * 365; //5 years Random rand = new Random(); var result = new Result(); int countLinkType = 0; LinkForm link = new LinkForm(); if (count >= 100) { count = 100; } do { DateTime randomDate = DateTime.Today.AddDays(-randomData.Next(range)); countLinkType = rand.Next(maxValue: 5); switch (countLinkType) { case 0: link.CreateDate = randomDate; link.Url = "Тестовая ссылка с типом: " + LinkType.Неизвестно; link.Type = LinkType.Неизвестно; break; case 1: link.CreateDate = randomDate; link.Url = "Тестовая ссылка с типом: " + LinkType.Обучение; link.Type = LinkType.Обучение; break; case 2: link.CreateDate = randomDate; link.Url = "Тестовая ссылка с типом: " + LinkType.азвлечение; link.Type = LinkType.азвлечение; break; case 3: link.CreateDate = randomDate; link.Url = "Тестовая ссылка с типом: " + LinkType.Личное; link.Type = LinkType.Личное; break; case 4: link.CreateDate = randomDate; link.Url = "Тестовая ссылка с типом: " + LinkType.Чтение; link.Type = LinkType.Чтение; break; } AddLink(link); }while (count-- > 1); result.Data = "Готово"; return(result); }
public async Task <ActionResult> Shorten(LinkForm model) { if (!ModelState.IsValid) { ViewData["error"] = "URL is not valid, must start with http, https..."; return(View("~/Views/Home/index.cshtml")); } ViewData["url"] = await _shortenURLService.shortenUrl(model.url); return(View("~/Views/Home/index.cshtml")); }
protected override void OnOK(object sender, EventArgs args) { // Sitecore Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); Item selectionItem = this.Treeview.GetSelectionItem(); if (selectionItem == null) { Context.ClientPage.ClientResponse.Alert("Select an item."); return; } string linkTargetAttributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); string value = this.Querystring.Value; if (value.StartsWith("?", StringComparison.InvariantCulture)) { value = value.Substring(1); } Packet packet = new Packet("link", Array.Empty <string>()); LinkForm.SetAttribute(packet, "text", this.Text); LinkForm.SetAttribute(packet, "linktype", "internal"); LinkForm.SetAttribute(packet, "anchor", this.Anchor); LinkForm.SetAttribute(packet, "querystring", this.Anchor); LinkForm.SetAttribute(packet, "title", this.Title); LinkForm.SetAttribute(packet, "class", this.Class); LinkForm.SetAttribute(packet, "querystring", value); LinkForm.SetAttribute(packet, "target", linkTargetAttributeFromValue); LinkForm.SetAttribute(packet, "id", selectionItem.ID.ToString()); Assert.IsTrue((string.IsNullOrEmpty(selectionItem.ID.ToString()) ? false : ID.IsID(selectionItem.ID.ToString())), "ID doesn't exist."); // Custom this.TrimComboboxControl(this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalTriggerAttName, this.TriggerGoal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalAttributeName, this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalDataAttName, this.GoalData); this.TrimComboboxControl(this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventTriggerAttName, this.TriggerPageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventAttributeName, this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventDataAttName, this.PageEventData); //this.TrimComboboxControl(this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignTriggerAttName, this.TriggerCampaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignAttributeName, this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignDataAttName, this.CampaignData); // Sitecore Context.ClientPage.ClientResponse.SetDialogValue(packet.OuterXml); SheerResponse.CloseWindow(); }
private bool SetJavascriptLinkAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); string str = this.JavascriptCode.Value; if (str.Length > 0 && str.IndexOf("javascript:", StringComparison.InvariantCulture) < 0) { str = "javascript:" + str; } LinkForm.SetAttribute(packet, Attributes.url, str); LinkForm.SetAttribute(packet, Attributes.anchor, string.Empty); return(true); }
private bool SetAnchorLinkAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); string str = this.LinkAnchor.Value; if (str.Length > 0 && str.StartsWith("#", StringComparison.InvariantCulture)) { str = str.Substring(1); } LinkForm.SetAttribute(packet, Attributes.url, str); LinkForm.SetAttribute(packet, Attributes.anchor, str); return(true); }
private bool SetMediaLinkAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); Item selectionItem = this.MediaLinkTreeview.GetSelectionItem(); if (selectionItem == null) { Context.ClientPage.ClientResponse.Alert("Select a media item."); return(false); } string attributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); LinkForm.SetAttribute(packet, Attributes.target, attributeFromValue); LinkForm.SetAttribute(packet, Attributes.id, selectionItem.ID.ToString()); return(true); }
public Result AddLink(LinkForm linkForm) { var result = new Result(); DateTimeOffset createDate = DateTimeOffset.Now; var link = new Link(linkForm.Url, linkForm.Type, createDate); if (string.IsNullOrEmpty(link.Url)) { result.Errors.Add("Ссылка не может быть пустой"); return(result); } LinkViewModel linkViewModel = new LinkViewModel(link); result.Data = linkViewModel; _commonContext.Links.Add(link); _commonContext.SaveChanges(); return(result); }
private bool SetMailToLinkAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); string str = this.MailToLink.Value; string email = StringUtil.GetLastPart(str, ':', str); if (!EmailUtility.IsValidEmailAddress(email)) { SheerResponse.Alert("The e-mail address is invalid.", (string[])Array.Empty <string>()); return(false); } if (!string.IsNullOrEmpty(email)) { email = "mailto:" + email; } LinkForm.SetAttribute(packet, Attributes.url, email ?? string.Empty); LinkForm.SetAttribute(packet, Attributes.anchor, string.Empty); return(true); }
/// <summary> /// Handles a click on the OK button. /// </summary> /// <param name="sender"> /// </param> /// <param name="args"> /// </param> /// <remarks> /// When the user clicks OK, the dialog is closed by calling /// the <see cref="M:Sitecore.Web.UI.Sheer.ClientResponse.CloseWindow">CloseWindow</see> method. /// </remarks> protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); string path = this.GetPath(); string linkTargetAttributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); Packet packet = new Packet("link", Array.Empty <string>()); LinkForm.SetAttribute(packet, "text", this.Text); LinkForm.SetAttribute(packet, "linktype", "external"); LinkForm.SetAttribute(packet, "url", path); LinkForm.SetAttribute(packet, "anchor", string.Empty); LinkForm.SetAttribute(packet, "title", this.Title); LinkForm.SetAttribute(packet, "class", this.Class); LinkForm.SetAttribute(packet, "customattributes", this.CustomAttributes); LinkForm.SetAttribute(packet, "target", linkTargetAttributeFromValue); Context.ClientPage.ClientResponse.SetDialogValue(packet.OuterXml); base.OnOK(sender, args); }
protected override void OnOK(object sender, EventArgs args) { // Sitecore Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); Item selectionItem = this.MediaLinkTreeview.GetSelectionItem(); if (selectionItem == null) { Context.ClientPage.ClientResponse.Alert("Select a media item."); return; } string mediaPath = selectionItem.Paths.MediaPath; string linkTargetAttributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); Packet packet = new Packet("link", Array.Empty <string>()); LinkForm.SetAttribute(packet, "text", this.Text); LinkForm.SetAttribute(packet, "linktype", "media"); LinkForm.SetAttribute(packet, "title", this.Title); LinkForm.SetAttribute(packet, "class", this.Class); LinkForm.SetAttribute(packet, "target", linkTargetAttributeFromValue); LinkForm.SetAttribute(packet, "id", selectionItem.ID.ToString()); // Custom this.TrimComboboxControl(this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalTriggerAttName, this.TriggerGoal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalAttributeName, this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalDataAttName, this.GoalData); this.TrimComboboxControl(this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventTriggerAttName, this.TriggerPageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventAttributeName, this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventDataAttName, this.PageEventData); //this.TrimComboboxControl(this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignTriggerAttName, this.TriggerCampaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignAttributeName, this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignDataAttName, this.CampaignData); // Sitecore SheerResponse.SetDialogValue(packet.OuterXml); SheerResponse.CloseWindow(); }
protected override void OnOK(object sender, EventArgs args) { // Sitecore Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); string mail = this.GetMail(); if (mail == "__Canceled") { SheerResponse.Alert("The e-mail address is invalid.", Array.Empty <string>()); return; } Packet packet = new Packet("link", Array.Empty <string>()); LinkForm.SetAttribute(packet, "text", this.Text); LinkForm.SetAttribute(packet, "linktype", "mailto"); LinkForm.SetAttribute(packet, "url", mail); LinkForm.SetAttribute(packet, "anchor", string.Empty); LinkForm.SetAttribute(packet, "title", this.Title); LinkForm.SetAttribute(packet, "class", this.Class); // Custom this.TrimComboboxControl(this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalTriggerAttName, this.TriggerGoal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalAttributeName, this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalDataAttName, this.GoalData); this.TrimComboboxControl(this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventTriggerAttName, this.TriggerPageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventAttributeName, this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventDataAttName, this.PageEventData); //this.TrimComboboxControl(this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignTriggerAttName, this.TriggerCampaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignAttributeName, this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignDataAttName, this.CampaignData); // Sitecore SheerResponse.SetDialogValue(packet.OuterXml); SheerResponse.CloseWindow(); }
protected override void OnOK(object sender, EventArgs args) { // Sitecore Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); string value = this.Url.Value; if (value.Length > 0 && value.StartsWith("#", StringComparison.InvariantCulture)) { value = value.Substring(1); } Packet packet = new Packet("link", Array.Empty <string>()); LinkForm.SetAttribute(packet, "text", this.Text); LinkForm.SetAttribute(packet, "linktype", "anchor"); LinkForm.SetAttribute(packet, "url", value); LinkForm.SetAttribute(packet, "anchor", value); LinkForm.SetAttribute(packet, "title", this.Title); LinkForm.SetAttribute(packet, "class", this.Class); // Custom this.TrimComboboxControl(this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalTriggerAttName, this.TriggerGoal); LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalAttributeName, this.Goal); //LinkForm.SetAttribute(packet, LinkTrackerConstants.GoalDataAttName, this.GoalData); this.TrimComboboxControl(this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventTriggerAttName, this.TriggerPageEvent); LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventAttributeName, this.PageEvent); //LinkForm.SetAttribute(packet, LinkTrackerConstants.PageEventDataAttName, this.PageEventData); //this.TrimComboboxControl(this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignTriggerAttName, this.TriggerCampaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignAttributeName, this.Campaign); //LinkForm.SetAttribute(packet, LinkTrackerConstants.CampaignDataAttName, this.CampaignData); // Sitecore Context.ClientPage.ClientResponse.SetDialogValue(packet.OuterXml); SheerResponse.CloseWindow(); }
private void InitControls() { string goalValue = this.AnalyticsLinkAttributes[Attributes.goalid]; string eventValue = this.AnalyticsLinkAttributes[Attributes.eventid]; if (!string.IsNullOrWhiteSpace(goalValue)) { this.GoalId.Value = goalValue; } if (!string.IsNullOrWhiteSpace(eventValue)) { this.EventId.Value = eventValue; } string str = string.Empty; string linkAttribute = this.AnalyticsLinkAttributes[Attributes.target]; string linkTargetValue = LinkForm.GetLinkTargetValue(linkAttribute); if (linkTargetValue == "Custom") { str = linkAttribute; this.CustomTarget.Disabled = false; this.Custom.Class = string.Empty; } else { this.CustomTarget.Disabled = true; this.Custom.Class = "disabled"; } this.Text.Value = this.AnalyticsLinkAttributes[Attributes.text]; this.Target.Value = linkTargetValue; this.CustomTarget.Value = str; this.Class.Value = this.AnalyticsLinkAttributes[Attributes._class]; this.Querystring.Value = this.AnalyticsLinkAttributes[Attributes.querystring]; this.Title.Value = this.AnalyticsLinkAttributes[Attributes.title]; this.InitMediaLinkDataContext(); this.InitInternalLinkDataContext(); }
protected override void OnOK(object sender, EventArgs args) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(args, "args"); string path = GetPath(); string attributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(Target.Value, CustomTarget.Value); Packet packet = new Packet("link", new string[0]); LinkForm.SetAttribute(packet, "text", (Control)Text); LinkForm.SetAttribute(packet, "linktype", "external"); LinkForm.SetAttribute(packet, "url", path); LinkForm.SetAttribute(packet, "anchor", string.Empty); LinkForm.SetAttribute(packet, "title", (Control)Title); LinkForm.SetAttribute(packet, "class", (Control)Class); LinkForm.SetAttribute(packet, "target", attributeFromValue); TrimComboboxControl(Campaign); LinkForm.SetAttribute(packet, CampaignTriggerAttName, (Control)TriggerCampaign); LinkForm.SetAttribute(packet, CampaignAttributeName, (Control)Campaign); SheerResponse.SetDialogValue(packet.OuterXml); SheerResponse.CloseWindow(); }
private bool SetExternalLinkAttributes(Packet packet) { Assert.ArgumentNotNull((object)packet, nameof(packet)); string str = this.Url.Value; if (str.Length > 0 && str.IndexOf("://", StringComparison.InvariantCulture) < 0 && !str.StartsWith("/", StringComparison.InvariantCulture)) { str = "http://" + str; } string attributeFromValue = LinkForm.GetLinkTargetAttributeFromValue(this.Target.Value, this.CustomTarget.Value); LinkForm.SetAttribute(packet, Attributes.url, str); LinkForm.SetAttribute(packet, Attributes.anchor, string.Empty); LinkForm.SetAttribute(packet, Attributes.target, attributeFromValue); this.TrimComboboxControl(this.GoalId); LinkForm.SetAttribute(packet, Attributes.goalid, this.GoalId); this.TrimComboboxControl(this.EventId); LinkForm.SetAttribute(packet, Attributes.eventid, this.EventId); return(true); }
public IActionResult AddLink(LinkForm linkForm) { return(Ok(_linkService.AddLink(linkForm))); }