This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CustomPropertiesViewer.ascx.vb
183 lines (163 loc) · 8.17 KB
/
CustomPropertiesViewer.ascx.vb
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Imports System.Xml
Imports System.Collections.Generic
Namespace DNNStuff.Aggregator
Partial Public Class CustomPropertiesViewer
Inherits System.Web.UI.UserControl
#Region " Public Properties"
Private _properties As Dictionary(Of String, CustomProperty)
Private _description As String
Public Property Properties() As Dictionary(Of String, CustomProperty)
Get
Return _properties
End Get
Set(ByVal value As Dictionary(Of String, CustomProperty))
_properties = value
End Set
End Property
Public Property Description() As String
Get
Return _description
End Get
Set(ByVal value As String)
_description = value
End Set
End Property
#End Region
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblDescription.Text = Description
LoadProperties()
End Sub
''' <summary>
''' Capture settings from controls and save to properties dictionary
''' </summary>
''' <remarks></remarks>
Public Sub SetProperties()
For Each prop As CustomProperty In Properties.Values
Select Case prop.Type
Case PropertyType.String
Dim tb As TextBox = DirectCast(FindControl("tb" & prop.Name), TextBox)
If tb IsNot Nothing Then
prop.Value = tb.Text
End If
Case PropertyType.Html
Dim tb As TextBox = DirectCast(FindControl("tb" & prop.Name), TextBox)
If tb IsNot Nothing Then
prop.Value = Server.HtmlEncode(tb.Text)
End If
Case PropertyType.Boolean
Dim cb As CheckBox = DirectCast(FindControl("cb" & prop.Name), CheckBox)
If cb IsNot Nothing Then
prop.Value = cb.Checked.ToString.ToLower
End If
Case PropertyType.Choice, PropertyType.Directory, PropertyType.Files
Dim ddl As DropDownList = DirectCast(FindControl("ddl" & prop.Name), DropDownList)
If ddl IsNot Nothing Then
prop.Value = ddl.SelectedValue
End If
End Select
Next
End Sub
Private Sub LoadProperties()
If Properties IsNot Nothing Then
If Properties.Count > 0 Then
For Each prop As CustomProperty In Properties.Values
Dim trProp As HtmlTableRow = New HtmlTableRow
Dim tdCaption As HtmlTableCell = New HtmlTableCell
Dim tdPrompt As HtmlTableCell = New HtmlTableCell
' style rows, cells
trProp.VAlign = "Top"
tdCaption.VAlign = "Top"
tdPrompt.Align = "Left"
' add label
Dim l As New DotNetNuke.UI.WebControls.PropertyLabelControl
l.ID = prop.Name & "_Help"
l.Caption = prop.Caption & " :"
l.Font.Bold = True
If prop.Help.Length > 0 Then
l.HelpText = "<div class=""Help"">" & prop.Help & "</div>"
End If
Dim prompt As Control = Nothing
' prompt
Select Case prop.Type
Case PropertyType.String
Dim tb As New TextBox
tb.ID = "tb" & prop.Name
tb.Columns = Convert.ToInt32(prop.Columns)
tb.Rows = Convert.ToInt32(prop.Rows)
If tb.Rows > 1 Then tb.TextMode = TextBoxMode.MultiLine
tb.Text = prop.Value
prompt = tb
Case PropertyType.Html
Dim tb As New TextBox
tb.ID = "tb" & prop.Name
tb.Columns = Convert.ToInt32(prop.Columns)
tb.Rows = Convert.ToInt32(prop.Rows)
If tb.Rows > 1 Then tb.TextMode = TextBoxMode.MultiLine
tb.Text = Server.HtmlDecode(prop.Value)
prompt = tb
Case PropertyType.Boolean
Dim cb As New CheckBox
cb.ID = "cb" & prop.Name
Boolean.TryParse(prop.Value, cb.Checked)
prompt = cb
Case PropertyType.Choice
Dim ddl As New DropDownList
ddl.ID = "ddl" & prop.Name
Dim li As ListItem
For Each ch As CustomPropertyChoice In prop.Choices
li = New ListItem(ch.Caption, ch.Value)
li.Selected = (li.Value = prop.Value)
ddl.Items.Add(li)
Next
prompt = ddl
Case PropertyType.Directory
Dim ddl As New DropDownList
ddl.ID = "ddl" & prop.Name
Dim dir As New IO.DirectoryInfo(MapPath(prop.Directory))
Dim li As ListItem
For Each subdir As IO.DirectoryInfo In dir.GetDirectories
If Not subdir.Name.StartsWith("_") Then
li = New ListItem(StrConv(subdir.Name.Replace("-", " "), VbStrConv.ProperCase), subdir.Name)
li.Selected = (li.Value = prop.Value)
ddl.Items.Add(li)
End If
Next
prompt = ddl
Case PropertyType.Files
Dim ddl As New DropDownList
ddl.ID = "ddl" & prop.Name
Dim dir As New IO.DirectoryInfo(MapPath(prop.Directory))
Dim li As ListItem
For Each subfile As IO.FileInfo In dir.GetFiles
If Not subfile.Name.StartsWith("_") Then
li = New ListItem(subfile.Name, subfile.Name)
li.Selected = (li.Value = prop.Value)
ddl.Items.Add(li)
End If
Next
prompt = ddl
End Select
l.EditControl = prompt
Dim div As New Panel()
div.CssClass = "dnnFormItem"
div.Controls.Add(l)
div.Controls.Add(prompt)
pnlProperties.Controls.Add(div)
Next
Else
LoadNoProperties()
End If
Else
LoadNoProperties()
End If
End Sub
Private Sub LoadNoProperties()
Dim trProp As HtmlTableRow = New HtmlTableRow
Dim tdCaption As HtmlTableCell = New HtmlTableCell
Dim l As New LiteralControl(DotNetNuke.Services.Localization.Localization.GetString("NoCustomSettings", ResolveUrl("App_LocalResources/Aggregator")))
tdCaption.Controls.Add(l)
trProp.Cells.Add(tdCaption)
tblProperties.Rows.Add(trProp)
End Sub
End Class
End Namespace