-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeSelector.ascx.vb
61 lines (58 loc) · 2.8 KB
/
ThemeSelector.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
Option Infer On
Imports DevExpress.Web
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Script.Serialization
Imports System.Web.UI
Imports System.Web.UI.WebControls
Partial Public Class UserControl_ThemeSelector
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ThemesContainerRepeater.DataBind()
ShowAllThemesButton.JSProperties("cpThemesListsNames") = ThemesModel.Current.GetAllGroups().Select(Function(g) GetThemesListClientName(g.Name)).ToList()
ShowAllThemesButton.JSProperties("cpCurrenTheme") = Utils.CurrentTheme
End Sub
Protected Sub ThemesList_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
Dim themesList As ASPxListBox = DirectCast(sender, ASPxListBox)
Dim item As RepeaterItem = TryCast(themesList.NamingContainer, RepeaterItem)
If item Is Nothing Then
Return
End If
Dim group As ThemeGroupModel = TryCast(item.DataItem, ThemeGroupModel)
BindThemesList(themesList, group)
End Sub
Private Sub BindThemesList(ByVal themesList As ASPxListBox, ByVal group As ThemeGroupModel)
Dim isFirstgroup As Boolean = group.Name = "FirstGroup"
themesList.Caption = group.Title
If isFirstgroup Then
themesList.CssClass &= " firstGroup"
End If
Dim dataSource = group.Themes.Select(Function(t) New ListEditItem() With { _
.Value = GetThemeTitle(t.Name), _
.Text = t.Title, _
.ImageUrl = Utils.GetColoredSquareUrl(t.PreveiwColor) _
}).ToList()
themesList.ClientInstanceName = GetThemesListClientName(group.Name)
themesList.ClientVisible = isFirstgroup
themesList.Items.Clear()
themesList.Items.AddRange(dataSource)
End Sub
Protected Sub ThemesLists_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Dim themesList As ASPxListBox = DirectCast(sender, ASPxListBox)
themesList.UnselectAll()
Dim selectedItem = themesList.Items.FindByValue(GetThemeTitle(Utils.CurrentTheme))
If selectedItem IsNot Nothing Then
selectedItem.Selected = True
End If
Dim jsSerializer = New JavaScriptSerializer()
themesList.JSProperties("cpNewThemes") = themesList.Items.Cast(Of ListEditItem)().Where(Function(item) ThemesModel.NewThemes.Select(Function(t) t.Title).Contains(item.Text)).Select(Function(item) item.Text)
End Sub
Private Function GetThemesListClientName(ByVal groupName As String) As String
Return "themesList" & groupName
End Function
Private Function GetThemeTitle(ByVal themeName As String) As String
Return If(Not String.IsNullOrEmpty(themeName), themeName, "Default")
End Function
End Class