-
-
Notifications
You must be signed in to change notification settings - Fork 780
Expand file tree
/
Copy pathSettings.ascx.cs
More file actions
298 lines (253 loc) · 12.6 KB
/
Copy pathSettings.ascx.cs
File metadata and controls
298 lines (253 loc) · 12.6 KB
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace Dnn.Modules.Console
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.UI.WebControls;
using Dnn.Modules.Console.Components;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Instrumentation;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Web.Common;
using DotNetNuke.Web.UI.WebControls.Internal;
using Microsoft.Extensions.Logging;
/// <summary>Loads and saves the module settings.</summary>
public partial class Settings : ModuleSettingsBase
{
private static readonly ILogger Logger = DnnLoggingController.GetLogger<Settings>();
/// <inheritdoc />
public override void LoadSettings()
{
try
{
if (this.Page.IsPostBack == false)
{
if (this.Settings.ContainsKey("ParentTabId") && !string.IsNullOrEmpty(Convert.ToString(this.Settings["ParentTabId"])))
{
var tabId = Convert.ToInt32(this.Settings["ParentTabId"]);
this.ParentTab.SelectedPage = TabController.Instance.GetTab(tabId, this.PortalId);
}
foreach (string val in ConsoleController.GetSizeValues())
{
this.DefaultSize.AddItem(Localization.GetString(val, this.LocalResourceFile), val);
}
this.SelectDropDownListItem(ref this.DefaultSize, "DefaultSize");
this.SelectDropDownListItem(ref this.modeList, "Mode");
if (this.Settings.ContainsKey("AllowSizeChange"))
{
this.AllowResize.Checked = Convert.ToBoolean(this.Settings["AllowSizeChange"]);
}
foreach (var val in ConsoleController.GetViewValues())
{
this.DefaultView.AddItem(Localization.GetString(val, this.LocalResourceFile), val);
}
this.SelectDropDownListItem(ref this.DefaultView, "DefaultView");
if (this.Settings.ContainsKey("IncludeParent"))
{
this.IncludeParent.Checked = Convert.ToBoolean(this.Settings["IncludeParent"]);
}
if (this.Settings.ContainsKey("AllowViewChange"))
{
this.AllowViewChange.Checked = Convert.ToBoolean(this.Settings["AllowViewChange"]);
}
if (this.Settings.ContainsKey("ShowTooltip"))
{
this.ShowTooltip.Checked = Convert.ToBoolean(this.Settings["ShowTooltip"]);
}
if (this.Settings.ContainsKey("OrderTabsByHierarchy"))
{
this.OrderTabsByHierarchy.Checked = Convert.ToBoolean(this.Settings["OrderTabsByHierarchy"]);
}
if (this.Settings.ContainsKey("IncludeHiddenPages"))
{
this.IncludeHiddenPages.Checked = Convert.ToBoolean(this.Settings["IncludeHiddenPages"]);
}
if (this.Settings.ContainsKey("ConsoleWidth"))
{
this.ConsoleWidth.Text = Convert.ToString(this.Settings["ConsoleWidth"]);
}
this.SwitchMode();
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
/// <inheritdoc />
public override void UpdateSettings()
{
try
{
// validate console width value
var width = string.Empty;
if (this.ConsoleWidth.Text.Trim().Length > 0)
{
try
{
width = Unit.Parse(this.ConsoleWidth.Text.Trim()).ToString();
}
catch (Exception exc)
{
Logger.SettingsParseWidthException(exc);
throw new Exception("ConsoleWidth value is invalid. Value must be numeric.");
}
}
if (this.ParentTab.SelectedItemValueAsInt == Null.NullInteger)
{
ModuleController.Instance.DeleteModuleSetting(this.ModuleId, "ParentTabID");
}
else
{
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "ParentTabID", this.ParentTab.SelectedItem.Value);
}
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "Mode", this.modeList.SelectedValue);
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "DefaultSize", this.DefaultSize.SelectedValue);
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "AllowSizeChange", this.AllowResize.Checked.ToString(CultureInfo.InvariantCulture));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "DefaultView", this.DefaultView.SelectedValue);
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "AllowViewChange", this.AllowViewChange.Checked.ToString(CultureInfo.InvariantCulture));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "ShowTooltip", this.ShowTooltip.Checked.ToString(CultureInfo.InvariantCulture));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "OrderTabsByHierarchy", this.OrderTabsByHierarchy.Checked.ToString(CultureInfo.InvariantCulture));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "IncludeHiddenPages", this.IncludeHiddenPages.Checked.ToString(CultureInfo.InvariantCulture));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "IncludeParent", this.IncludeParent.Checked.ToString(CultureInfo.InvariantCulture));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, "ConsoleWidth", width);
foreach (RepeaterItem item in this.tabs.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
var tabPath = (item.FindControl("tabPath") as HiddenField).Value;
var visibility = (item.FindControl("tabVisibility") as DnnComboBox).SelectedValue;
var key = string.Format("TabVisibility{0}", tabPath.Replace("//", "-"));
ModuleController.Instance.UpdateModuleSetting(this.ModuleId, key, visibility);
}
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <inheritdoc />
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.tabs.ItemDataBound += this.TabsItemDataBound;
this.modeList.SelectedIndexChanged += this.ModeListSelectedIndexChanged;
this.ParentTab.UndefinedItem = new ListItem(DynamicSharedConstants.Unspecified, string.Empty);
}
private void BindTabs(int tabId, bool includeParent)
{
List<TabInfo> tempTabs = TabController.GetTabsBySortOrder(this.PortalId).OrderBy(t => t.Level).ThenBy(t => t.HasChildren).ToList();
IList<TabInfo> tabList = new List<TabInfo>();
IList<int> tabIdList = new List<int>();
tabIdList.Add(tabId);
if (includeParent)
{
TabInfo consoleTab = TabController.Instance.GetTab(tabId, this.PortalId);
if (consoleTab != null)
{
tabList.Add(consoleTab);
}
}
foreach (TabInfo tab in tempTabs)
{
bool canShowTab = TabPermissionController.CanViewPage(tab) &&
!tab.IsDeleted &&
(tab.StartDate < DateTime.Now || tab.StartDate == Null.NullDate);
if (!canShowTab)
{
continue;
}
if (tabIdList.Contains(tab.ParentId))
{
if (!tabIdList.Contains(tab.TabID))
{
tabIdList.Add(tab.TabID);
}
tabList.Add(tab);
}
}
this.tabs.DataSource = tabList;
this.tabs.DataBind();
}
private void SwitchMode()
{
int parentTabId = -1;
if (this.Settings.ContainsKey("ParentTabID") && !string.IsNullOrEmpty(Convert.ToString(this.Settings["ParentTabID"])))
{
parentTabId = Convert.ToInt32(this.Settings["ParentTabID"]);
}
switch (this.modeList.SelectedValue)
{
case "Normal":
this.parentTabRow.Visible = true;
this.includeParentRow.Visible = true;
this.tabVisibilityRow.Visible = false;
break;
case "Profile":
this.parentTabRow.Visible = false;
this.includeParentRow.Visible = false;
this.tabVisibilityRow.Visible = true;
parentTabId = this.PortalSettings.UserTabId;
break;
case "Group":
this.parentTabRow.Visible = true;
this.includeParentRow.Visible = true;
this.tabVisibilityRow.Visible = true;
break;
}
this.ParentTab.SelectedPage = TabController.Instance.GetTab(parentTabId, this.PortalId);
this.BindTabs(parentTabId, this.IncludeParent.Checked);
}
private void ModeListSelectedIndexChanged(object sender, EventArgs e)
{
this.SwitchMode();
}
private void TabsItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var tab = (TabInfo)e.Item.DataItem;
DnnComboBox visibilityDropDown = (DnnComboBox)e.Item.FindControl("tabVisibility");
var tabLabel = (Label)e.Item.FindControl("tabLabel");
var tabPathField = (HiddenField)e.Item.FindControl("tabPath");
visibilityDropDown.Items.Clear();
visibilityDropDown.AddItem(this.LocalizeText("AllUsers"), "AllUsers");
if (this.modeList.SelectedValue == "Profile")
{
visibilityDropDown.AddItem(this.LocalizeText("Friends"), "Friends");
visibilityDropDown.AddItem(this.LocalizeText("User"), "User");
}
else
{
visibilityDropDown.AddItem(this.LocalizeText("Owner"), "Owner");
visibilityDropDown.AddItem(this.LocalizeText("Members"), "Members");
}
tabLabel.Text = tab.TabName;
tabPathField.Value = tab.TabPath;
var key = string.Format("TabVisibility{0}", tab.TabPath.Replace("//", "-"));
this.SelectDropDownListItem(ref visibilityDropDown, key);
}
}
private void SelectDropDownListItem(ref DnnComboBox ddl, string key)
{
if (this.Settings.ContainsKey(key))
{
ddl.ClearSelection();
var selItem = ddl.FindItemByValue(Convert.ToString(this.Settings[key]));
if (selItem != null)
{
selItem.Selected = true;
}
}
}
}
}