forked from DNNCommunity/DNN.Events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventEditCategories.ascx.vb
301 lines (235 loc) · 13.5 KB
/
EventEditCategories.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
'
' DotNetNuke® - http://www.dnnsoftware.com
' Copyright (c) 2002-2013
' by DNNCorp
'
' 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.Security
Namespace DotNetNuke.Modules.Events
<DNNtc.ModuleControlProperties("Categories", "Edit Event Categories", DNNtc.ControlType.View, "https://dnnevents.codeplex.com/documentation", False, True)> _
Partial Class EventEditCategories
Inherits EventBase
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
'Add the external Validation.js to the Page
Const csname As String = "ExtValidationScriptFile"
Dim cstype As Type = System.Reflection.MethodBase.GetCurrentMethod().GetType()
Dim cstext As String = "<script src=""" & ResolveUrl("~/DesktopModules/Events/Scripts/Validation.js") & """ type=""text/javascript""></script>"
If Not Page.ClientScript.IsClientScriptBlockRegistered(csname) Then
Page.ClientScript.RegisterClientScriptBlock(cstype, csname, cstext, False)
End If
Const csname2 As String = "LoadPreview"
Dim cstype2 As Type = System.Reflection.MethodBase.GetCurrentMethod().GetType()
Dim cstext2 As String = "<script type=""text/javascript"">byid('" & lblPreviewCat.ClientID & "').innerHTML = byid('" & _
txtCategoryName.ClientID & "').value;byid('" & lblPreviewCat.ClientID & "').style.color = byid('" & _
txtCategoryFontColor.ClientID & "').value;byid('" & previewpane.ClientID & "').style.backgroundColor = byid('" & _
txtCategoryColor.ClientID & "').value;</script>"
Page.ClientScript.RegisterStartupScript(cstype2, csname2, cstext2, False)
Dim previewScript As String
previewScript = "CategoryPreviewPane('" & cpBackColor.ClientID & "','" & cpForeColor.ClientID & "','" & previewpane.ClientID & "','" & lblPreviewCat.ClientID & "','" & txtCategoryFontColor.ClientID & "','" & txtCategoryColor.ClientID & "','" & txtCategoryName.ClientID & "','" + Localization.GetString("InvalidColor", LocalResourceFile) + "');"
Const csname3 As String = "ColorPicker"
Dim cstype3 As Type = System.Reflection.MethodBase.GetCurrentMethod().GetType()
Dim cstext3 As String = "<script type=""text/javascript"">"
cstext3 += " function HandleColorChange(sender,eventargs) { $get(""" & txtCategoryColor.ClientID & """).value = sender.get_selectedColor(); " & previewScript & "}"
cstext3 += " function HandleColorFontChange(sender,eventargs) { $get(""" & txtCategoryFontColor.ClientID & """).value = sender.get_selectedColor(); " & previewScript & "}"
cstext3 += " </script>"
If Not Page.ClientScript.IsClientScriptBlockRegistered(csname3) Then
Page.ClientScript.RegisterClientScriptBlock(cstype3, csname3, cstext3, False)
End If
txtCategoryName.Attributes.Add("onchange", "byid('" & lblPreviewCat.ClientID & "').innerHTML = this.value;")
txtCategoryFontColor.Attributes.Add("onchange", previewScript)
txtCategoryColor.Attributes.Add("onchange", previewScript)
'ColorPicker Icons
End Sub
#End Region
#Region "Private Area"
'Private itemId As Integer
Private ReadOnly _objCtlCategory As New EventCategoryController
Private _objCategory As New EventCategoryInfo
Private _colCategories As ArrayList
Private Const DefaultBackColor As String = "#ffffff"
Private Const DefaultFontColor As String = "#000000"
#End Region
#Region "Event Handler"
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
LocalizeAll()
If PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName.ToString) Or _
IsCategoryEditor() Then
Else
Response.Redirect(GetSocialNavigateUrl(), True)
End If
' Set the selected theme
SetTheme(pnlEventsModuleCategories)
If Not Page.IsPostBack Then
SetDefaultValues()
BindData()
End If
End Sub
#End Region
#Region "Helper Routines"
Private Sub LocalizeAll()
GrdCategories.Columns(3).HeaderText = Localization.GetString("plCategoryName", LocalResourceFile)
End Sub
Private Sub BindData()
Dim i As Integer
_colCategories = _objCtlCategory.EventsCategoryList(PortalId)
GrdCategories.DataSource = _colCategories
GrdCategories.DataBind()
If GrdCategories.Items.Count > 0 Then
GrdCategories.Visible = True
For i = 0 To GrdCategories.Items.Count - 1
CType(GrdCategories.Items(i).FindControl("DeleteButton"), ImageButton).Attributes.Add("onclick", "javascript:return confirm('" + Localization.GetString("AreYouSureYouWishToDelete.Text", LocalResourceFile) + "');")
Next
End If
End Sub
#End Region
#Region "Control Events"
Public Sub GrdCategories_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles GrdCategories.ItemCommand
Select Case e.CommandName
Case "Select"
Dim category As Integer = CType(GrdCategories.DataKeys(e.Item.ItemIndex), Int16)
_objCategory = _objCtlCategory.EventCategoryGet(category, PortalId)
txtCategoryName.Text = _objCategory.CategoryName
If _objCategory.Color <> "" Then
txtCategoryColor.Text = _objCategory.Color
cpBackColor.SelectedColor = ColorTranslator.FromHtml(txtCategoryColor.Text)
Else
txtCategoryColor.Text = ""
cpBackColor.SelectedColor = ColorTranslator.FromHtml(DefaultBackColor)
End If
If _objCategory.FontColor <> "" Then
txtCategoryFontColor.Text = _objCategory.FontColor
cpForeColor.SelectedColor = ColorTranslator.FromHtml(txtCategoryFontColor.Text)
Else
txtCategoryFontColor.Text = ""
cpForeColor.SelectedColor = ColorTranslator.FromHtml(DefaultFontColor)
End If
'Remember that we might use update
ViewState.Add("Category", _objCategory.Category.ToString())
cmdUpdate.Visible = True
BindData()
End Select
End Sub
Public Sub GrdCategories_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles GrdCategories.DeleteCommand
Dim category As Integer
category = CType(GrdCategories.DataKeys(e.Item.ItemIndex), Integer)
divDeleteError.Visible = False
Dim objDesktopModule As Entities.Modules.DesktopModuleInfo
Dim objModules As New Entities.Modules.ModuleController
objDesktopModule = Entities.Modules.DesktopModuleController.GetDesktopModuleByModuleName("DNN_Events", PortalId)
Dim lstModules As ArrayList = objModules.GetModulesByDefinition(PortalId, objDesktopModule.FriendlyName)
For Each objModule As Entities.Modules.ModuleInfo In lstModules
Dim ems As New EventModuleSettings
Dim categories As ArrayList = ems.GetEventModuleSettings(objModule.ModuleID, Nothing).ModuleCategoryIDs
If categories.Contains(category) Then
lblDeleteError.Text = String.Format(Localization.GetString("lblDeleteError", LocalResourceFile), objModule.ModuleTitle)
divDeleteError.Visible = True
Return
End If
Next
_objCtlCategory.EventsCategoryDelete(category, PortalId)
BindData()
'Be sure we cannot update any more
txtCategoryName.Text = ""
txtCategoryColor.Text = ""
txtCategoryFontColor.Text = ""
ViewState.Remove("Category")
cmdUpdate.Visible = False
cpBackColor.SelectedColor = ColorTranslator.FromHtml(DefaultBackColor)
cpForeColor.SelectedColor = ColorTranslator.FromHtml(DefaultFontColor)
End Sub
Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUpdate.Click
Try
' Only Update if the Entered Data is Valid
If Page.IsValid And Not String.IsNullOrEmpty(txtCategoryName.Text) Then
Dim objCategory As New EventCategoryInfo
Dim objSecurity As New PortalSecurity
Dim categoryName As String
' Filter text for non-admins
If (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName.ToString) = True) Then
categoryName = txtCategoryName.Text
Else
categoryName = objSecurity.InputFilter(txtCategoryName.Text, PortalSecurity.FilterFlag.NoScripting)
End If
'bind text values to object
objCategory.Category = CInt(ViewState("Category"))
objCategory.PortalID = PortalId
objCategory.CategoryName = categoryName
objCategory.Color = txtCategoryColor.Text
objCategory.FontColor = txtCategoryFontColor.Text
_objCtlCategory.EventsCategorySave(objCategory)
SetDefaultValues()
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
BindData()
End Sub
Private Sub cmdAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdAdd.Click
Try
' Only Update if the Entered Data is Valid
If Page.IsValid = True And Not String.IsNullOrEmpty(txtCategoryName.Text) Then
Dim objCategory As New EventCategoryInfo
Dim objSecurity As New PortalSecurity
Dim categoryName As String
' Filter text for non-admins
If (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName.ToString) = True) Then
categoryName = txtCategoryName.Text
Else
categoryName = objSecurity.InputFilter(txtCategoryName.Text, PortalSecurity.FilterFlag.NoScripting)
End If
'bind text values to object
objCategory.Category = 0
objCategory.PortalID = PortalId
objCategory.CategoryName = categoryName
objCategory.Color = txtCategoryColor.Text
objCategory.FontColor = txtCategoryFontColor.Text
_objCtlCategory.EventsCategorySave(objCategory)
SetDefaultValues()
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
BindData()
End Sub
Private Sub returnButton_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles returnButton.Click
Try
Response.Redirect(GetSocialNavigateUrl(), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
#End Region
#Region "Private Functions"
Private Sub SetDefaultValues()
'Back to normal (add) mode
txtCategoryName.Text = ""
txtCategoryColor.Text = ""
txtCategoryFontColor.Text = ""
ViewState.Remove("Category")
cmdUpdate.Visible = False
cpBackColor.SelectedColor = ColorTranslator.FromHtml(DefaultBackColor)
cpForeColor.SelectedColor = ColorTranslator.FromHtml(DefaultFontColor)
End Sub
#End Region
End Class
End Namespace