-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallToAction.ascx.cs
92 lines (69 loc) · 2.54 KB
/
CallToAction.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using Telerik.Sitefinity.Libraries.Model;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Web.UI;
namespace SitefinityWebApp.Widgets.General {
[Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesigner(typeof(SitefinityWebApp.Widgets.General.Designer.CallToActionDesigner))]
public partial class CallToAction : System.Web.UI.UserControl, ICustomWidgetVisualization {
#region Properties
public Guid ImageId { get; set; }
public Guid PageId { get; set; }
public string Description { get; set; }
public bool IsEmpty {
get {
return (PageId == Guid.Empty && ImageId == Guid.Empty && Description.IsNullOrEmpty());
}
}
public string EmptyLinkText {
get {
return "Please set the properties for this widget in the designer.";
}
}
#endregion
#region Events
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack)
BindData();
}
#endregion
#region Methods
/// <summary>
/// Bind our properties to the controls
/// </summary>
private void BindData() {
// Resolve the PageId to an url
if (PageId != Guid.Empty) {
var page = GetPage(PageId);
if (page != null)
lnkNavigateTo.NavigateUrl = page.GetUrl();
}
// Resolve the ImageId to an url
if (ImageId != Guid.Empty) {
var image = GetImage(ImageId);
if (image != null)
imgThumbnail.ImageUrl = image.MediaUrl;
}
// Fill in the description
litDescription.Text = Description;
}
/// <summary>
/// Get Image by Guid from Library
/// </summary>
/// <param name="imageId"></param>
/// <returns></returns>
private Image GetImage(Guid imageId) {
var manager = LibrariesManager.GetManager();
return (imageId != Guid.Empty) ? manager.GetImage(imageId) : null;
}
/// <summary>
/// Returns a PageNode object from a Guid
/// </summary>
private PageNode GetPage(Guid pageId) {
var manager = PageManager.GetManager();
return (pageId != Guid.Empty) ? manager.GetPageNode(pageId) : null;
}
#endregion
}
}