-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TemplateSettings.ascx.vb
172 lines (148 loc) · 5.85 KB
/
TemplateSettings.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
'
' Bring2mind - http://www.bring2mind.net
' Copyright (c) 2011-2013
' by Bring2mind
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke.Services.Localization.Localization
Imports Bring2mind.DNN.Modules.YAG.Templating
Public Class TemplateSettings
Inherits ModuleBase
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim tmgr As New TemplateManager(PortalSettings, Settings, Settings.Template)
For Each ts As TemplateSetting In tmgr.TemplateSettings.Settings
Dim tr As New TableRow
Dim td As New TableCell
td.CssClass = "SubHead"
td.Width = Unit.Pixel(165)
Dim dnnl As DotNetNuke.UI.UserControls.LabelControl = CType(LoadControl(ResolveUrl("~/controls/LabelControl.ascx")), DotNetNuke.UI.UserControls.LabelControl)
dnnl.Suffix = ":"
dnnl.Text = GetString(ts.Key & ".Text", tmgr.SharedResourcesFile)
dnnl.HelpText = GetString(ts.Key & ".Help", tmgr.SharedResourcesFile)
dnnl.ControlName = "txt" & ts.Key
td.Controls.Add(dnnl)
tr.Cells.Add(td)
td = New TableCell
Select Case ts.ValueType.ToLower
Case "dropdown"
Dim dd As New DropDownList
dd.ID = ts.Key
For Each v As TemplateSettingValue In ts.Values
Dim txt As String = GetString(v.Value, tmgr.SharedResourcesFile)
If String.IsNullOrEmpty(txt) Then txt = v.Value
dd.Items.Add(New ListItem(txt, v.Value))
Next
td.Controls.Add(dd)
Case "integer"
Dim tb As New TextBox
tb.ID = ts.Key
tb.Width = Unit.Pixel(50)
td.Controls.Add(tb)
Case "number"
Dim tb As New TextBox
tb.ID = ts.Key
tb.Width = Unit.Pixel(50)
td.Controls.Add(tb)
Case "truefalse", "10"
Dim chk As New CheckBox
chk.ID = ts.Key
td.Controls.Add(chk)
Case Else
Dim tb As New TextBox
tb.ID = ts.Key
tb.Width = Unit.Pixel(300)
td.Controls.Add(tb)
End Select
tr.Cells.Add(td)
tblSettings.Rows.Add(tr)
Next
If Not IsPostBack Then
DataBind()
End If
End Sub
Public Overrides Sub DataBind()
Dim tmgr As New TemplateManager(PortalSettings, Settings, Settings.Template)
Dim rowIndex As Integer = 0
For Each ts As TemplateSetting In tmgr.TemplateSettings.Settings
Dim tr As TableRow = tblSettings.Rows.Item(rowIndex)
Dim value As String = Settings.TemplateSettings(ts.Key)
If value Is Nothing Then
value = ts.DefaultValue
End If
Select Case ts.ValueType.ToLower
Case "dropdown"
Dim dd As DropDownList = CType(tr.Cells(1).Controls(0), DropDownList)
Try
dd.Items.FindByValue(value).Selected = True
Catch ex As Exception
End Try
Case "integer"
Dim tb As TextBox = CType(tr.Cells(1).Controls(0), TextBox)
tb.Text = value
Case "number"
Dim tb As TextBox = CType(tr.Cells(1).Controls(0), TextBox)
tb.Text = value
Case "truefalse", "10"
Dim chk As CheckBox = CType(tr.Cells(1).Controls(0), CheckBox)
Try
chk.Checked = CBool(value)
Catch ex As Exception
End Try
Case Else
Dim tb As TextBox = CType(tr.Cells(1).Controls(0), TextBox)
tb.Text = value
End Select
rowIndex += 1
Next
End Sub
Private Sub cmdCancel_Click(sender As Object, e As System.EventArgs) Handles cmdCancel.Click
Response.Redirect(DotNetNuke.Common.NavigateURL, False)
End Sub
Private Sub cmdUpdate_Click(sender As Object, e As System.EventArgs) Handles cmdUpdate.Click
Dim tmgr As New TemplateManager(PortalSettings, Settings, Settings.Template)
Dim rowIndex As Integer = 0
For Each ts As TemplateSetting In tmgr.TemplateSettings.Settings
Dim tr As TableRow = tblSettings.Rows.Item(rowIndex)
Select Case ts.ValueType.ToLower
Case "dropdown"
Dim dd As DropDownList = CType(tr.Cells(1).Controls(0), DropDownList)
Settings.SetTemplateSetting(ts.Key, dd.SelectedValue)
Case "integer"
Dim tb As TextBox = CType(tr.Cells(1).Controls(0), TextBox)
Settings.SetTemplateSetting(ts.Key, tb.Text)
Case "number"
Dim tb As TextBox = CType(tr.Cells(1).Controls(0), TextBox)
Settings.SetTemplateSetting(ts.Key, tb.Text)
Case "truefalse"
Dim chk As CheckBox = CType(tr.Cells(1).Controls(0), CheckBox)
Settings.SetTemplateSetting(ts.Key, chk.Checked.ToString.ToLower)
Case "10"
Dim chk As CheckBox = CType(tr.Cells(1).Controls(0), CheckBox)
If chk.Checked Then
Settings.SetTemplateSetting(ts.Key, "1")
Else
Settings.SetTemplateSetting(ts.Key, "0")
End If
Case Else
Dim tb As TextBox = CType(tr.Cells(1).Controls(0), TextBox)
Settings.SetTemplateSetting(ts.Key, tb.Text)
End Select
rowIndex += 1
Next
Settings.SaveTemplateSettings()
Response.Redirect(DotNetNuke.Common.NavigateURL, False)
End Sub
End Class