-
Notifications
You must be signed in to change notification settings - Fork 11
/
EditCustomFields.ascx.vb
executable file
·381 lines (258 loc) · 14.6 KB
/
EditCustomFields.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Namespace Ventrian.PropertyAgent
Partial Public Class EditCustomFields
Inherits PropertyAgentBase
#Region " Private Members "
Dim _currentPage As Integer = 1
Dim _pageRecords As Integer = Null.NullInteger
Dim _customFields As List(Of CustomFieldInfo)
#End Region
#Region " Private Methods "
Private Sub ReadQueryString()
If Not (Request("CurrentPage") Is Nothing) Then
_currentPage = Convert.ToInt32(Request("CurrentPage"))
End If
If Not (Request("PageRecords") Is Nothing) Then
_pageRecords = Convert.ToInt32(Request("PageRecords"))
End If
End Sub
Private Sub BindPageCount()
If (Request.Cookies("PA-CFM-PageSize") IsNot Nothing) Then
If Not (drpRecordsPerPage.Items.FindByValue(Request.Cookies("PA-CFM-PageSize").Value) Is Nothing) Then
drpRecordsPerPage.SelectedValue = Request.Cookies("PA-CFM-PageSize").Value
Return
End If
End If
If (_pageRecords <> Null.NullInteger) Then
If Not (drpRecordsPerPage.Items.FindByValue(_pageRecords.ToString()) Is Nothing) Then
drpRecordsPerPage.SelectedValue = _pageRecords.ToString()
End If
End If
End Sub
Private Sub BindCrumbs()
Dim crumbs As New ArrayList
Dim objCrumbMain As New CrumbInfo
objCrumbMain.Caption = PropertySettings.MainLabel
objCrumbMain.Url = NavigateURL()
crumbs.Add(objCrumbMain)
Dim objCustomFieldManager As New CrumbInfo
objCustomFieldManager.Caption = Localization.GetString("CustomFieldManager", LocalResourceFile)
objCustomFieldManager.Url = NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditCustomFields")
crumbs.Add(objCustomFieldManager)
If (PropertySettings.BreadcrumbPlacement = BreadcrumbType.Portal) Then
For i As Integer = 0 To crumbs.Count - 1
Dim objCrumb As CrumbInfo = crumbs(i)
If (i > 0) Then
Dim objTab As New DotNetNuke.Entities.Tabs.TabInfo
objTab.TabID = -8888 + i
objTab.TabName = objCrumb.Caption
objTab.Url = objCrumb.Url
PortalSettings.ActiveTab.BreadCrumbs.Add(objTab)
End If
Next
End If
If (PropertySettings.BreadcrumbPlacement = BreadcrumbType.Module) Then
rptBreadCrumbs.DataSource = crumbs
rptBreadCrumbs.DataBind()
End If
End Sub
Private Sub BindCustomFields()
Dim PageSize As Integer = Convert.ToInt32(drpRecordsPerPage.SelectedItem.Value)
Dim objCustomFieldController As New CustomFieldController
Localization.LocalizeDataGrid(grdCustomFields, Me.LocalResourceFile)
_customFields = objCustomFieldController.List(Me.ModuleId, Null.NullBoolean)
If (_customFields.Count > 1) Then
' Sort Order must be messed up, fix now..
For i As Integer = 0 To _customFields.Count - 1
Dim objCustomField As CustomFieldInfo = CType(_customFields(i), CustomFieldInfo)
objCustomField.SortOrder = i
objCustomFieldController.Update(objCustomField)
Next
End If
Dim objPagedDataSource As New PagedDataSource
objPagedDataSource.AllowPaging = True
objPagedDataSource.DataSource = _customFields
objPagedDataSource.PageSize = PageSize
objPagedDataSource.CurrentPageIndex = _currentPage - 1
If (_customFields.Count > 0) Then
grdCustomFields.DataSource = objPagedDataSource
grdCustomFields.DataBind()
grdCustomFields.Visible = True
lblNoCustomFields.Visible = False
ctlPagingControl.Visible = True
ctlPagingControl.Visible = True
ctlPagingControl.TotalRecords = _customFields.Count
ctlPagingControl.PageSize = PageSize
ctlPagingControl.CurrentPage = _currentPage
ctlPagingControl.QuerystringParams = PropertySettings.SEOAgentType & "=EditCustomFields"
If (drpRecordsPerPage.SelectedIndex <> 1) Then
ctlPagingControl.QuerystringParams = ctlPagingControl.QuerystringParams & "&PageRecords=" + drpRecordsPerPage.SelectedValue
End If
ctlPagingControl.TabID = TabId
Else
grdCustomFields.Visible = False
lblNoCustomFields.Visible = True
ctlPagingControl.Visible = False
End If
End Sub
#End Region
#Region " Protected Methods "
Protected Function GetCustomFieldEditUrl(ByVal customFieldID As String) As String
Return NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditCustomField", "customFieldID=" & customFieldID)
End Function
#End Region
#Region " Event Handlers "
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
Try
BindCrumbs()
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
ReadQueryString()
If (Page.IsPostBack = False) Then
BindPageCount()
BindCustomFields()
End If
cmdAddCustomField.CssClass = PropertySettings.ButtonClass
cmdReturnToModule.CssClass = PropertySettings.ButtonClass
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub drpRecordsPerPage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drpRecordsPerPage.SelectedIndexChanged
Try
_currentPage = 1
Response.Cookies.Add(New HttpCookie("PA-CFM-PageSize", drpRecordsPerPage.SelectedValue))
Response.Redirect(NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditCustomFields", "PageRecords=" & drpRecordsPerPage.SelectedValue), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdAddCustomField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddCustomField.Click
Try
Response.Redirect(NavigateURL(Me.TabId, "", PropertySettings.SEOAgentType & "=EditCustomField"), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub cmdReturnToModule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReturnToModule.Click
Try
Response.Redirect(NavigateURL(), True)
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub grdCustomFields_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdCustomFields.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim btnUp As ImageButton = CType(e.Item.FindControl("btnUp"), ImageButton)
Dim btnDown As ImageButton = CType(e.Item.FindControl("btnDown"), ImageButton)
Dim objCustomField As CustomFieldInfo = CType(e.Item.DataItem, CustomFieldInfo)
If Not (btnUp Is Nothing And btnDown Is Nothing) Then
If (objCustomField.CustomFieldID = CType(_customFields(0), CustomFieldInfo).CustomFieldID) Then
btnUp.Visible = False
End If
If (objCustomField.CustomFieldID = CType(_customFields(_customFields.Count - 1), CustomFieldInfo).CustomFieldID) Then
btnDown.Visible = False
End If
btnUp.CommandArgument = objCustomField.CustomFieldID.ToString()
btnUp.CommandName = "Up"
btnDown.CommandArgument = objCustomField.CustomFieldID.ToString()
btnDown.CommandName = "Down"
End If
Dim btnPublished As ImageButton = CType(e.Item.FindControl("btnPublished"), ImageButton)
If Not (btnPublished Is Nothing) Then
If (objCustomField.IsPublished) Then
btnPublished.ImageUrl = "~/images/checked.gif"
btnPublished.CommandName = "PublishedChecked"
Else
btnPublished.ImageUrl = "~/images/cancel.gif"
btnPublished.CommandName = "PublishedCancel"
End If
btnPublished.CommandArgument = objCustomField.CustomFieldID.ToString()
End If
Dim btnFeatured As ImageButton = CType(e.Item.FindControl("btnFeatured"), ImageButton)
If Not (btnFeatured Is Nothing) Then
If (objCustomField.IsFeatured) Then
btnFeatured.ImageUrl = "~/images/checked.gif"
btnFeatured.CommandName = "FeaturedChecked"
Else
btnFeatured.ImageUrl = "~/images/cancel.gif"
btnFeatured.CommandName = "FeaturedCancel"
End If
btnFeatured.CommandArgument = objCustomField.CustomFieldID.ToString()
End If
Dim btnLockDown As ImageButton = CType(e.Item.FindControl("btnLockDown"), ImageButton)
If Not (btnLockDown Is Nothing) Then
If (objCustomField.IsLockDown) Then
btnLockDown.ImageUrl = "~/images/checked.gif"
btnLockDown.CommandName = "LockDownChecked"
Else
btnLockDown.ImageUrl = "~/images/cancel.gif"
btnLockDown.CommandName = "LockDownCancel"
End If
btnLockDown.CommandArgument = objCustomField.CustomFieldID.ToString()
End If
End If
End Sub
Private Sub grdCustomFields_ItemCommand(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdCustomFields.ItemCommand
Dim objCustomFieldController As New CustomFieldController
_customFields = objCustomFieldController.List(Me.ModuleId, Null.NullBoolean)
Dim customFieldID As Integer = Convert.ToInt32(e.CommandArgument)
For i As Integer = 0 To _customFields.Count - 1
Dim objCustomField As CustomFieldInfo = CType(_customFields(i), CustomFieldInfo)
If (customFieldID = objCustomField.CustomFieldID) Then
If (e.CommandName = "Up") Then
Dim objCustomFieldToSwap As CustomFieldInfo = CType(_customFields(i - 1), CustomFieldInfo)
Dim sortOrder As Integer = objCustomField.SortOrder
Dim sortOrderPrevious As Integer = objCustomFieldToSwap.SortOrder
objCustomField.SortOrder = sortOrderPrevious
objCustomFieldToSwap.SortOrder = sortOrder
objCustomFieldController.Update(objCustomField)
objCustomFieldController.Update(objCustomFieldToSwap)
End If
If (e.CommandName = "Down") Then
Dim objCustomFieldToSwap As CustomFieldInfo = CType(_customFields(i + 1), CustomFieldInfo)
Dim sortOrder As Integer = objCustomField.SortOrder
Dim sortOrderNext As Integer = objCustomFieldToSwap.SortOrder
objCustomField.SortOrder = sortOrderNext
objCustomFieldToSwap.SortOrder = sortOrder
objCustomFieldController.Update(objCustomField)
objCustomFieldController.Update(objCustomFieldToSwap)
End If
If (e.CommandName = "PublishedChecked") Then
objCustomField.IsPublished = False
objCustomFieldController.Update(objCustomField)
End If
If (e.CommandName = "PublishedCancel") Then
objCustomField.IsPublished = True
objCustomFieldController.Update(objCustomField)
End If
If (e.CommandName = "FeaturedChecked") Then
objCustomField.IsFeatured = False
objCustomFieldController.Update(objCustomField)
End If
If (e.CommandName = "FeaturedCancel") Then
objCustomField.IsFeatured = True
objCustomFieldController.Update(objCustomField)
End If
If (e.CommandName = "LockDownChecked") Then
objCustomField.IsLockDown = False
objCustomFieldController.Update(objCustomField)
End If
If (e.CommandName = "LockDownCancel") Then
objCustomField.IsLockDown = True
objCustomFieldController.Update(objCustomField)
End If
End If
Next
Response.Redirect(Request.RawUrl, True)
End Sub
#End Region
End Class
End Namespace