-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCategoryMenu.ascx.vb
651 lines (520 loc) · 29.9 KB
/
CategoryMenu.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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
' --- Copyright (c) notice NevoWeb ---
' Copyright (c) 2008 SARL NevoWeb. www.nevoweb.com. BSD License.
' Author: D.C.Lee
' ------------------------------------------------------------------------
' 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.
' ------------------------------------------------------------------------
' This copyright notice may NOT be removed, obscured or modified without written consent from the author.
' --- End copyright notice ---
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports NEvoWeb.Modules.NB_Store.SharedFunctions
Imports System.IO
Namespace NEvoWeb.Modules.NB_Store
Partial Public Class CategoryMenu
Inherits BaseModule
Implements Entities.Modules.IPortable
Private CatID As Integer = 0
Public _chkHideSubMenu As Boolean
Public _txtColumns As String
Public _txtSubLeftHtml As String
Public _txtSubNameTemplate As String
Public _txtSubRightHtml As String
Public _txtSubHeadHtml As String
Public _txtSubSelectCSS As String
Public _txtCSS As String
Public _txtSubMenuSep As String
Public _SubMenuOnly As Boolean = False
Public _ddlDefaultCategory As Integer
Public _txtThumbnailSize As String
Public _TabId As Integer = -1
Public _chkPatchWork As Boolean = False
Public _SelectedCategories As Hashtable
#Region "Events"
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
' menu is running as control in productlist when SubmenuOnly is set to true
If Not _SubMenuOnly Then
_chkHideSubMenu = CType(Settings("chkHideSubMenu"), Boolean)
_chkPatchWork = CType(Settings("chkPatchWork"), Boolean)
_txtColumns = CType(Settings("txtColumns"), String)
_txtSubLeftHtml = CType(Settings("txtSubLeftHtml"), String)
_txtSubNameTemplate = CType(Settings("txtSubNameTemplate"), String)
_txtSubRightHtml = CType(Settings("txtSubRightHtml"), String)
_txtSubHeadHtml = CType(Settings("txtSubHeadHtml"), String)
_txtSubSelectCSS = CType(Settings("txtSubSelectCSS"), String)
_txtSubMenuSep = CType(Settings("txtSep"), String)
_txtCSS = CType(Settings("txtCSS"), String)
_txtThumbnailSize = CType(Settings("txtThumbnailSize"), String)
If IsNumeric(CType(Settings("ddlDefaultCategory"), String)) Then
_ddlDefaultCategory = CType(Settings("ddlDefaultCategory"), Integer)
Else
_ddlDefaultCategory = -1
End If
_TabId = TabId
End If
If _txtThumbnailSize = "" Then _txtThumbnailSize = "100"
If CType(Settings("txtRootSep"), String) <> "" Then
dlRootMenu.SeparatorTemplate = New BaseDisplayTemplate(Server.HtmlDecode(CType(Settings("txtRootSep"), String)))
End If
If _txtSubMenuSep <> "" Then
dlCategoryMenu.SeparatorTemplate = New BaseDisplayTemplate(Server.HtmlDecode(_txtSubMenuSep))
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim StaticCatID As Integer
CatID = _ddlDefaultCategory
StaticCatID = CatID
If Not (Request.QueryString("CatID") Is Nothing) Then
If IsNumeric(Request.QueryString("CatID")) Then
CatID = Request.QueryString("CatID")
If CatID = -1 Then CatID = _ddlDefaultCategory
End If
Else
'get from cookie,
Dim tmp As String = getCookieURLparam(PortalId, "CatID")
tmp = Replace(tmp, "CatID=", "") 'remove prefix
If IsNumeric(tmp) Then
CatID = CInt(tmp)
End If
End If
If Not CType(Settings("chkStaticCategory"), Boolean) Then
StaticCatID = CatID
End If
If (Not (Request.QueryString("ProdID") Is Nothing)) And CType(Settings("chkViewProdHide"), Boolean) And Not _SubMenuOnly Then
'hide the menu if viewing a product
dlCategoryMenu.Visible = False
dlRootMenu.Visible = False
lblBreadcrumbs.Visible = False
Else
If Not Page.IsPostBack Then
_SelectedCategories = New Hashtable
If CatID >= 0 Then
GetSelectedCategories(CatID, _SelectedCategories)
populateList(CatID, StaticCatID)
Else
dlCategoryMenu.Visible = False
dlRootMenu.Visible = False
lblBreadcrumbs.Visible = False
End If
If Not _SubMenuOnly Then
phSecSep1.Controls.Add(New LiteralControl(CType(Settings("txtSectionSep"), String)))
phSecSep2.Controls.Add(New LiteralControl(CType(Settings("txtSectionSep2"), String)))
phSecSep2.Controls.Add(New LiteralControl(CType(Settings("txtSectionSep3"), String)))
ShowTreeMenu()
ShowAccordion()
End If
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Private Sub dlCategoryMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlCategoryMenu.ItemDataBound
Dim itemInfo As NB_Store_CategoriesInfo = CType(e.Item.DataItem, NB_Store_CategoriesInfo)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim phL As PlaceHolder = DirectCast(e.Item.FindControl("phCatLink"), PlaceHolder)
If Not phL Is Nothing Then
phL.Controls.Add(New LiteralControl(BuildhtmlCatLink(_txtSubNameTemplate, _txtSubLeftHtml, _txtSubRightHtml, _txtSubSelectCSS, itemInfo)))
End If
End If
End Sub
Private Sub dlRootMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlRootMenu.ItemDataBound
Dim itemInfo As NB_Store_CategoriesInfo = CType(e.Item.DataItem, NB_Store_CategoriesInfo)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim phL As PlaceHolder = DirectCast(e.Item.FindControl("phCatLink"), PlaceHolder)
If Not phL Is Nothing Then
phL.Controls.Add(New LiteralControl(BuildhtmlCatLink(CType(Settings("txtRootNameTemplate"), String), CType(Settings("txtRootLeftHtml"), String), CType(Settings("txtRootRightHtml"), String), CType(Settings("txtRootSelectCSS"), String), itemInfo)))
End If
End If
End Sub
#End Region
#Region "Methods"
Private Function BuildHtmlCatLink(ByVal NameTemplate As String, ByVal Lefthtml As String, ByVal RightHtml As String, ByVal SelectCSS As String, ByVal itemInfo As NB_Store_CategoriesInfo) As String
Dim strHtmlOut As String = ""
Dim strHtmlLink As String = ""
Dim strHtmlText As String = ""
Dim NonEmptyCat As Integer
Dim reg As New Regex("\s*")
Dim catMsg As String = ""
catMsg = Replace(itemInfo.Message, "<p>&#160;</p>", "") 'remove fck editor gaff!!
If catMsg <> "" Then
catMsg = Regex.Replace(catMsg, "\s*", "")
End If
If CType(Settings("chkSkipBlankCat"), Boolean) And itemInfo.ProductCount = 0 And catMsg = "" Then
NonEmptyCat = GetFirstNonEmptyChild(itemInfo.CategoryID)
Else
NonEmptyCat = itemInfo.CategoryID
End If
If IsNumeric(CType(Settings("lstProductTabs"), String)) Then
If itemInfo.SEOName <> "" Then
strHtmlLink = GetProductListUrlByCatID(PortalId, CType(Settings("lstProductTabs"), Integer), NonEmptyCat, itemInfo.SEOName, GetCurrentCulture)
Else
strHtmlLink = GetProductListUrlByCatID(PortalId, CType(Settings("lstProductTabs"), Integer), NonEmptyCat, itemInfo.CategoryName, GetCurrentCulture)
End If
Else
If itemInfo.SEOName <> "" Then
strHtmlLink = GetProductListUrlByCatID(PortalId, _TabId, NonEmptyCat, itemInfo.SEOName, GetCurrentCulture)
Else
strHtmlLink = GetProductListUrlByCatID(PortalId, _TabId, NonEmptyCat, itemInfo.CategoryName, GetCurrentCulture)
End If
End If
If NameTemplate = "" Then
strHtmlText = Lefthtml & itemInfo.CategoryName & RightHtml
Else
strHtmlText = ReplaceLinkTokens(NameTemplate, Lefthtml, RightHtml, itemInfo, strHtmlLink)
End If
If strHtmlText.StartsWith("<a") Then
'a href already build into template
Return strHtmlText
Else
strHtmlOut = "<a href=""" & strHtmlLink & """ "
If (itemInfo.CategoryID = CatID Or _SelectedCategories.ContainsKey(itemInfo.CategoryID)) And SelectCSS <> "" Then
strHtmlOut &= "class=""" & SelectCSS & """"
End If
strHtmlOut &= ">" & strHtmlText
strHtmlOut &= "</a>"
Return strHtmlOut
End If
End Function
Private Function ReplaceLinkTokens(ByVal NameTemplate As String, ByVal Lefthtml As String, ByVal RightHtml As String, ByVal itemInfo As NB_Store_CategoriesInfo, ByVal strHtmlLink As String) As String
Dim strText As String = ""
strText = Lefthtml & Replace(NameTemplate, "[TAG:CATEGORYNAME]", itemInfo.CategoryName) & RightHtml
strText = Replace(strText, "[TAG:PRODUCTCOUNT]", itemInfo.ProductCount.ToString)
If itemInfo.ImageURL = "" Then
strText = Replace(strText, "[TAG:IMAGE]", itemInfo.CategoryName)
strText = Replace(strText, "[TAG:IMAGEURL]", "")
Else
strText = Replace(strText, "[TAG:IMAGE]", "<img border=""0"" src=""" & StoreInstallPath & "makethumbnail.ashx?Image=" & QueryStringEncode(PRODUCTIMAGESFOLDER & "\" & System.IO.Path.GetFileName(itemInfo.ImageURL)) & "&w=" & _txtThumbnailSize & "&tabid=" & _TabId & """ alt=""" & itemInfo.CategoryName & """/>")
strText = Replace(strText, "[TAG:IMAGEURL]", itemInfo.ImageURL)
End If
strText = Replace(strText, "[TAG:IMAGEURLTHUMB]", StoreInstallPath & "makethumbnail.ashx?Image=" & QueryStringEncode(PRODUCTIMAGESFOLDER & "\" & System.IO.Path.GetFileName(itemInfo.ImageURL)) & "&w=" & _txtThumbnailSize & "&tabid=" & _TabId)
strText = Replace(strText, "[TAG:LINK]", strHtmlLink)
If itemInfo.CategoryID = CatID Then
strText = Replace(strText, "[TAG:CATEGORYNAMECSS]", Replace(itemInfo.CategoryName, " ", "_") & "sel")
Else
strText = Replace(strText, "[TAG:CATEGORYNAMECSS]", Replace(itemInfo.CategoryName, " ", "_"))
End If
Return strText
End Function
Private Sub populateList(ByVal CatID As Integer, ByVal StaticCatID As Integer)
Dim aryList As ArrayList
Dim aryListRoot As ArrayList
Dim objCtrl As New CategoryController
Dim objInfo As NB_Store_CategoriesInfo
If IsNumeric(_txtColumns) Then
dlCategoryMenu.RepeatColumns = _txtColumns
dlRootMenu.RepeatColumns = _txtColumns
Else
dlRootMenu.RepeatColumns = 4
dlCategoryMenu.RepeatColumns = 4
End If
'populate root menu
If Not CType(Settings("chkHideRootMenu"), Boolean) And Not _SubMenuOnly Then
If _chkPatchWork Then
Dim aryPatchList As ArrayList
aryListRoot = New ArrayList
aryPatchList = objCtrl.GetCategories(PortalId, GetCurrentCulture, -1, False, False)
Dim catMsg As String = ""
For Each objCatInfo As NB_Store_CategoriesInfo In aryPatchList
catMsg = Replace(objCatInfo.Message, "<p>&#160;</p>", "") 'remove fck editor gaff!!
If catMsg <> "" Then
catMsg = Regex.Replace(catMsg, "\s*", "")
End If
If objCatInfo.ProductCount > 0 Or catMsg <> "" Then
aryListRoot.Add(objCatInfo)
End If
Next
Else
aryListRoot = objCtrl.GetCategories(PortalId, GetCurrentCulture, 0, False, False)
End If
If Not aryListRoot Is Nothing Then
dlRootMenu.DataSource = aryListRoot
dlRootMenu.DataBind()
End If
dlRootMenu.Visible = True
If CType(Settings("txtRootCSS"), String) <> "" Then
dlRootMenu.CssClass = CType(Settings("txtRootCSS"), String)
End If
If CType(Settings("txtRootHeadHtml"), String) <> "" Then
phRootHead.Controls.Add(New LiteralControl(CType(Settings("txtRootHeadHtml"), String)))
End If
Else
dlRootMenu.Visible = False
End If
If CatID = 0 And CType(Settings("chkHideWhenRoot"), Boolean) Then
dlCategoryMenu.Visible = False
lblBreadcrumbs.Visible = False
Else
lblBreadcrumbs.Visible = False
If Not _chkHideSubMenu Or Not CType(Settings("chkHideBreadCrumb"), Boolean) Then
'populate submenu
aryList = objCtrl.GetCategories(PortalId, GetCurrentCulture, StaticCatID, False, False)
If Not aryList Is Nothing Then
dlCategoryMenu.Visible = True
If aryList.Count = 0 Then
'no more sub categories so display previous one
objInfo = objCtrl.GetCategory(CatID, GetCurrentCulture)
If Not objInfo Is Nothing Then
If objInfo.ParentCategoryID = 0 Then
'parent category hide sub categories
dlCategoryMenu.Visible = False
Else
aryList = objCtrl.GetCategories(PortalId, GetCurrentCulture, objInfo.ParentCategoryID, False, False)
End If
End If
End If
If CType(Settings("chkHideBreadCrumb"), Boolean) Or _SubMenuOnly Then
lblBreadcrumbs.Visible = False
Else
Dim strHtml = BuildBreadCrumbs(CatID, aryList)
If strHtml <> "" Then
lblBreadcrumbs.Controls.Add(New LiteralControl(strHtml))
lblBreadcrumbs.Visible = True
End If
End If
'check if sub menu hidden
If _chkHideSubMenu Then
dlCategoryMenu.Visible = False
Else
'check if the category is empty, if so skip.
If CType(Settings("chkSkipBlankCat"), Boolean) Then
For Each objInfo In aryList
If objInfo.ProductCount = 0 Then
objInfo.CategoryID = GetFirstNonEmptyChild(objInfo.CategoryID)
End If
Next
End If
If _txtCSS <> "" Then
dlCategoryMenu.CssClass = _txtCSS
End If
If _txtSubHeadHtml <> "" Then
Dim PName As String = ""
If aryList.Count > 0 Then
PName = CType(aryList(0), NB_Store_CategoriesInfo).ParentName
Else
Dim objCatInfo As NB_Store_CategoriesInfo = objCtrl.GetCategory(CatID, GetCurrentCulture)
If Not objCatInfo Is Nothing Then
PName = objCatInfo.CategoryName
Else
PName = "Category " & CatID.ToString
End If
End If
phSubHead.Controls.Add(New LiteralControl(Replace(_txtSubHeadHtml, "[TAG:PARENTNAME]", PName)))
End If
dlCategoryMenu.DataSource = aryList
dlCategoryMenu.DataBind()
End If
Else
dlCategoryMenu.Visible = False
End If
End If
End If
End Sub
Private Function GetFirstNonEmptyChild(ByVal CategoryID As Integer) As Integer
'this function gets the first nonempty child category
' or the bottom level category
Dim objCtrl As New CategoryController
Dim aryList2 As ArrayList
aryList2 = objCtrl.GetCategories(PortalId, GetCurrentCulture, CategoryID, False, False)
If aryList2.Count > 0 Then
'has sub cats
If CType(aryList2(0), NB_Store_CategoriesInfo).ProductCount = 0 Then
'has no product, so search for next child
If CType(aryList2(0), NB_Store_CategoriesInfo).CategoryID <> CategoryID Then
Return GetFirstNonEmptyChild(CType(aryList2(0), NB_Store_CategoriesInfo).CategoryID)
Else
Return CategoryID
End If
Else
'has products so display.
Return CType(aryList2(0), NB_Store_CategoriesInfo).CategoryID
End If
Else
'has no sub cats, so display
Return CategoryID
End If
End Function
Private Sub GetSelectedCategories(ByVal CategoryID As Integer, ByRef htList As Hashtable)
Dim objCtrl As New CategoryController
Dim objInfo As NB_Store_CategoriesInfo
objInfo = objCtrl.GetCategory(CategoryID, GetCurrentCulture)
If Not objInfo Is Nothing Then
If Not htList.ContainsKey(CategoryID) Then
htList.Add(CategoryID, objInfo)
If objInfo.ParentCategoryID > 0 And htList.Count < 20 Then ' count is just to make sure we don't get infnate loop
GetSelectedCategories(objInfo.ParentCategoryID, htList)
End If
End If
End If
End Sub
Private Function BuildBreadCrumbs(ByVal CatID As Integer, ByVal aryList As ArrayList) As String
Dim CurrentCatID As Integer = CatID
Dim strHTML As String = ""
Dim objCtrl As New CategoryController
Dim objInfo As NB_Store_CategoriesInfo
Dim CatName As String = ""
Dim CurrentCatName As String = ""
Dim LinkCategoryID As Integer = 0
Dim BreadCrumbCSS As String = ""
Dim BreadCrumbSep As String = ""
Do
If CurrentCatID > 0 Then
objInfo = objCtrl.GetCategory(CurrentCatID, GetCurrentCulture)
If Not objInfo Is Nothing Then
If CType(Settings("chkHideBreadCrumbRoot"), Boolean) And objInfo.ParentName = "" Then
CurrentCatID = objInfo.ParentCategoryID
Else
'get current cart to add as test to end of breadcrumb
If objInfo.CategoryID = CatID Then
CurrentCatName = objInfo.CategoryName
End If
'get category name of parent or take root name
CatName = objInfo.ParentName
'assign parent category to current
CurrentCatID = objInfo.ParentCategoryID
LinkCategoryID = CurrentCatID
If CType(Settings("chkSkipBlankCat"), Boolean) Then
LinkCategoryID = GetFirstNonEmptyChild(LinkCategoryID)
End If
If CatName = "" Then
CatName = Localization.GetString("Root", LocalResourceFile)
End If
If CType(Settings("txtBreadCrumbSep"), String) = "" Then
BreadCrumbSep = " > "
Else
BreadCrumbSep = CType(Settings("txtBreadCrumbSep"), String)
End If
If IsNumeric(CType(Settings("lstProductTabs"), String)) Then
strHTML = "<a href=""" & NavigateURL(CType(Settings("lstProductTabs"), Integer), "", "CatID=" & LinkCategoryID.ToString) & """" & BreadCrumbCSS & ">" & CatName & "</a>" & BreadCrumbSep & strHTML
Else
strHTML = "<a href=""" & NavigateURL(_TabId, "", "CatID=" & LinkCategoryID.ToString) & """" & BreadCrumbCSS & ">" & CatName & "</a>" & BreadCrumbSep & strHTML
End If
End If
Else
CurrentCatID = 0
End If
End If
Loop While CurrentCatID > 0
If strHTML <> "" Then
strHTML &= "<a href=""" & NavigateURL(_TabId, "", "CatID=" & CatID.ToString) & """" & BreadCrumbCSS & ">" & CurrentCatName & "</a>"
End If
If CType(Settings("txtBreadCrumbCSS"), String) <> "" Then
strHTML = "<div class=""" & CType(Settings("txtBreadCrumbCSS"), String) & """>" & strHTML & "</div>"
Else
strHTML = "<div>" & strHTML & "</div>"
End If
Return strHTML
End Function
Private Sub ShowTreeMenu()
If CType(Settings("chkShowTreeMenu"), Boolean) Then
Dim objCtrl As New CategoryController
Dim aryList As ArrayList
Dim strHtml As String = ""
If CType(Settings("txtTreeHeadHtml"), String) <> "" Then
phTreeHead.Controls.Add(New LiteralControl(CType(Settings("txtTreeHeadHtml"), String)))
End If
aryList = objCtrl.GetCategories(PortalId, GetCurrentCulture)
strHtml = BuildTreeMenu(aryList, "", 0, 0)
phTreeMenu.Controls.Add(New LiteralControl(strHtml))
IncludeScripts(PortalId, StoreInstallPath, Page, "categorymenujs.includes", "categorymenustartupjs.includes", "categorymenucss.includes")
End If
End Sub
Private Sub ShowAccordion()
If CType(Settings("chkShowAccordionMenu"), Boolean) Then
Dim objCtrl As New CategoryController
Dim aryList As ArrayList
Dim strHtml As String = ""
If CType(Settings("txtAccordionHeadHtml"), String) <> "" Then
phTreeHead.Controls.Add(New LiteralControl(CType(Settings("txtAccordionHeadHtml"), String)))
End If
aryList = objCtrl.GetCategories(PortalId, GetCurrentCulture)
strHtml = BuildAccordionMenu(aryList, "", 0, -1)
phTreeMenu.Controls.Add(New LiteralControl(strHtml))
IncludeScripts(PortalId, StoreInstallPath, Page, "categorymenujs.includes ", "categorymenustartupjs.includes", "categorymenucss.includes")
End If
End Sub
Private Function BuildTreeMenu(ByVal aryList As ArrayList, ByVal htmlText As String, ByVal ParentID As Integer, ByVal LevelCount As Integer) As String
Dim objCInfo As NB_Store_CategoriesInfo
Dim strHeader As String = ""
Dim strFooter As String = "</ul>"
If ParentID = 0 Then
Dim TreeCSS As String = CType(Settings("txtTreeCSS"), String)
If TreeCSS = "" Then TreeCSS = "treeview"
strHeader &= "<ul id=""NBStoreTreeMenu"" class=""" & TreeCSS & """>"
Else
strHeader &= "<ul>"
End If
For Each objCInfo In aryList
If objCInfo.ParentCategoryID = ParentID And objCInfo.Archived = False And objCInfo.Hide = False Then
htmlText &= "<li>"
htmlText &= BuildHtmlCatLink(CType(Settings("txtTreeNameTemplate"), String), CType(Settings("txtTreeLeftHtml"), String), CType(Settings("txtTreeRightHtml"), String), CType(Settings("txtTreeSelectCSS"), String), objCInfo)
If LevelCount < 50 Then ' stop infinate loop
htmlText &= BuildTreeMenu(aryList, "", objCInfo.CategoryID, LevelCount + 1)
End If
htmlText &= "</li>"
End If
Next
If htmlText <> "" Then
htmlText = strHeader & htmlText & strFooter
End If
Return htmlText
End Function
Private Function BuildAccordionMenu(ByVal aryList As ArrayList, ByVal htmlText As String, ByVal ParentID As Integer, ByVal AccordionLevel As Integer) As String
Dim objCInfo As NB_Store_CategoriesInfo
Dim strHeader As String = ""
Dim strFooter As String = "</ul>"
AccordionLevel += 1
If ParentID = 0 Then
strHeader &= "<ul id=""NBStoreAccordion"" >"
Else
strHeader &= "<ul>"
End If
If AccordionLevel > 1 Then
'clear ul on sub sub level (make only 1 sub level)
strHeader = ""
strFooter = ""
End If
For Each objCInfo In aryList
If objCInfo.ParentCategoryID = ParentID And objCInfo.Archived = False And objCInfo.Hide = False Then
Dim AccCssClass As String = ""
If AccordionLevel > 1 Then
htmlText &= "</li><li>"
Else
htmlText &= "<li>"
End If
If ParentID = 0 Then
AccCssClass = "nbstoremenuhead"
AccordionLevel = 0
Else
AccCssClass = "nbstoremenusub" & AccordionLevel.ToString
End If
htmlText &= BuildHtmlCatLink(CType(Settings("txtAccordionNameTemplate"), String), CType(Settings("txtAccordionLeftHtml"), String), CType(Settings("txtAccordionRightHtml"), String), AccCssClass, objCInfo)
htmlText &= BuildAccordionMenu(aryList, "", objCInfo.CategoryID, AccordionLevel)
If AccordionLevel <= 1 Then
htmlText &= "</li>"
End If
End If
Next
If htmlText <> "" Then
htmlText = strHeader & htmlText & strFooter
End If
Return htmlText
End Function
#Region "Optional Interfaces"
Public Function ExportModule(ByVal ModuleID As Integer) As String Implements Entities.Modules.IPortable.ExportModule
' included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
End Function
Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserID As Integer) Implements Entities.Modules.IPortable.ImportModule
' included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
End Sub
#End Region
#End Region
End Class
End Namespace