-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThemeSelector.ascx.cs
56 lines (55 loc) · 2.44 KB
/
ThemeSelector.ascx.cs
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
using DevExpress.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControl_ThemeSelector : System.Web.UI.UserControl {
protected void Page_Load(object sender, EventArgs e) {
ThemesContainerRepeater.DataBind();
ShowAllThemesButton.JSProperties["cpThemesListsNames"] = ThemesModel.Current.GetAllGroups().Select(g => GetThemesListClientName(g.Name)).ToList();
ShowAllThemesButton.JSProperties["cpCurrenTheme"] = Utils.CurrentTheme;
}
protected void ThemesList_DataBinding(object sender, EventArgs e) {
ASPxListBox themesList = (ASPxListBox)sender;
RepeaterItem item = themesList.NamingContainer as RepeaterItem;
if(item == null)
return;
ThemeGroupModel group = item.DataItem as ThemeGroupModel;
BindThemesList(themesList, group);
}
void BindThemesList(ASPxListBox themesList, ThemeGroupModel group) {
bool isFirstgroup = group.Name == "FirstGroup";
themesList.Caption = group.Title;
if(isFirstgroup)
themesList.CssClass += " firstGroup";
var dataSource = group.Themes.Select(t => new ListEditItem() {
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);
}
protected void ThemesLists_PreRender(object sender, EventArgs e) {
ASPxListBox themesList = (ASPxListBox)sender;
themesList.UnselectAll();
var selectedItem = themesList.Items.FindByValue(GetThemeTitle(Utils.CurrentTheme));
if(selectedItem != null)
selectedItem.Selected = true;
var jsSerializer = new JavaScriptSerializer();
themesList.JSProperties["cpNewThemes"] = themesList.Items.Cast<ListEditItem>()
.Where(item => ThemesModel.NewThemes.Select(t => t.Title).Contains(item.Text))
.Select(item => item.Text);
}
string GetThemesListClientName(string groupName) {
return "themesList" + groupName;
}
string GetThemeTitle(string themeName) {
return !string.IsNullOrEmpty(themeName) ? themeName : "Default";
}
}