-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUrlSettings.ascx.cs
133 lines (111 loc) · 9.43 KB
/
UrlSettings.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
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
//
// Christoc.com - http://www.christoc.com
// Copyright (c) 2014-2024
// by Christoc.com
//
using System;
using System.Web.UI.WebControls;
using DotNetNuke.Services.Exceptions;
using Christoc.Modules.dnnsimplearticle.Components;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Urls;
using System.Collections.Generic;
namespace Christoc.Modules.dnnsimplearticle
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The Settings class manages Module Settings
/// </summary>
/// -----------------------------------------------------------------------------
public partial class UrlSettings : dnnsimplearticleSettingsBase, IExtensionUrlProviderSettingsControl
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
LocalResourceFile = "~/DesktopModules/dnnsimplearticle/App_LocalResources/UrlSettings.ascx.resx";
}
//public void LoadSettings()
void IExtensionUrlProviderSettingsControl.LoadSettings()
{
if (!IsPostBack)
{
if (Provider != null)
{
chkHideArticlePagePath.Checked = GetSafeBool(Constants.HideArticlePathPageSettingName, false);
lblHideArticlePagePath.Text = Localization.GetString("HideArticlePagePath.Text", LocalResourceFile);
cboArticlePage.SelectedPage = GetSafeTab(Constants.ArticlePageTabIdSettingName, null);
lblArticlePage.Text = Localization.GetString("ArticlePageTabId", LocalResourceFile);
txtDateFormat.Text = GetSafeString(Constants.UrlDateFormatSettingName, "");
lblDateFormat.Text = Localization.GetString("DateFormat", LocalResourceFile);
}
else
{
throw new ArgumentNullException("ExtensionUrlProviderInfo is null on LoadSettings()");
}
}
}
public ExtensionUrlProviderInfo Provider { get; set; }
//public Dictionary<string, string> SaveSettings()
Dictionary<string, string> IExtensionUrlProviderSettingsControl.SaveSettings()
{
var settings = new Dictionary<string, string>();
settings.Add(Constants.HideArticlePathPageSettingName, chkHideArticlePagePath.Checked.ToString());
if (cboArticlePage.SelectedPage != null)
{
settings.Add(Constants.ArticlePageTabIdSettingName, cboArticlePage.SelectedPage.TabID.ToString());
}
//txtDateFormat
//if (string.IsNullOrEmpty(txtDateFormat.Text) == false)
//{
settings.Add(Constants.UrlDateFormatSettingName, txtDateFormat.Text);
//}
return settings;
}
#region private helper methods
private string GetSafeString(string settingName, string defaultValue)
{
string raw = defaultValue;
if (Provider != null && Provider.Settings != null && Provider.Settings.ContainsKey(settingName))
{
raw = Provider.Settings[settingName];
}
return raw;
}
private TabInfo GetSafeTab(string settingName, TabInfo defaultValue)
{
TabInfo result = defaultValue;
int tabId = GetSafeInt(settingName, -1);
if (tabId > 0)
{
TabController tc = new TabController();
result = tc.GetTab(tabId, this.PortalId, false);
}
return result;
}
private int GetSafeInt(string settingName, int defaultValue)
{
int result = defaultValue;
string raw = null;
if (Provider != null && Provider.Settings != null && Provider.Settings.ContainsKey(settingName))
{
raw = Provider.Settings[settingName];
}
if (string.IsNullOrEmpty(raw) == false) int.TryParse(raw, out result);
return result;
}
private bool GetSafeBool(string settingName, bool defaultValue)
{
bool result = defaultValue;
string raw = null;
if (Provider != null && Provider.Settings != null && Provider.Settings.ContainsKey(settingName))
{
raw = Provider.Settings[settingName];
}
if (string.IsNullOrEmpty(raw) == false) bool.TryParse(raw, out result);
return result;
}
#endregion
}
}