forked from DNNCommunity/DNN.Repository
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DashboardSettings.ascx.cs
197 lines (159 loc) · 6.89 KB
/
DashboardSettings.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
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
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// 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.
//
using System.Web;
using System.Web.UI.WebControls;
using System.IO;
using DotNetNuke;
using DotNetNuke.Security;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Common;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Entities.Modules.Definitions;
using System.Collections.Generic;
using DotNetNuke.Services.Installer.Packages;
namespace DotNetNuke.Modules.Repository
{
public class DashboardSettings : Entities.Modules.ModuleSettingsBase
{
protected DropDownList ddlRepositoryID;
protected RadioButtonList rbStyle;
protected TextBox txtRowCount;
protected System.Web.UI.WebControls.Label lblMessage;
#region " Web Form Designer Generated Code "
//This call is required by the Web Form Designer.
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
}
//NOTE: The following placeholder declaration is required by the Web Form Designer.
//Do not delete or move it.
private System.Object designerPlaceholderDeclaration;
private void Page_Init(System.Object sender, System.EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
InitializeComponent();
}
#endregion
#region "Event Handlers"
private void Page_Load(System.Object sender, System.EventArgs e)
{
// Obtain PortalSettings from Current Context
PortalSettings _portalSettings = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
try {
ModuleController mc = new ModuleController();
TabController tc = new TabController();
PackageController pc = new PackageController();
// Get settings from the database
var moduleInfo = ModuleController.Instance.GetModule(ModuleId, TabId, false);
var settings = moduleInfo.ModuleSettings;
if ((Page.IsPostBack == false)) {
lblMessage.Text = "";
// get a list of repository modules on this portal
ddlRepositoryID.Items.Clear();
RepositoryController repositories = new RepositoryController();
TabController tabs = new TabController();
TabInfo objTab = null;
ModuleInfo objModule = null;
ListItem objItem = null;
// get a list of all of the Repository Modules installed in this
// portal
ModuleDefinitionInfo repModInfo = ModuleDefinitionController.GetModuleDefinitionByFriendlyName("Repository");
PackageInfo package = PackageController.Instance.GetExtensionPackage(PortalId, m => m.Name == "DotNetNuke.Repository");
IDictionary<int, Entities.Tabs.TabInfo> tabsWithModule = tc.GetTabsByPackageID(PortalId, package.PackageID, false);
// first, get a list of all the tabs that contain at least one repository
foreach (Entities.Tabs.TabInfo tab in tabsWithModule.Values) {
// for each tab, get the repository module info
Dictionary<int, ModuleInfo> modules = mc.GetTabModules(tab.TabID);
foreach (ModuleInfo objModule_loopVariable in modules.Values) {
objModule = objModule_loopVariable;
if (objModule.ModuleDefID == repModInfo.ModuleDefID) {
objItem = new ListItem();
objItem.Text = string.Format("{0} : {1}", tab.TabName, objModule.ModuleTitle);
objItem.Value = objModule.ModuleID.ToString();
ddlRepositoryID.Items.Add(objItem);
}
}
}
objItem = new ListItem();
objItem.Text = Localization.GetString("plRepositoryPrompt", this.LocalResourceFile);
objItem.Value = "";
ddlRepositoryID.Items.Insert(0, objItem);
if (!string.IsNullOrEmpty(Convert.ToString(settings["repository"]))) {
ddlRepositoryID.SelectedValue = settings["repository"].ToString();
}
if (!string.IsNullOrEmpty(Convert.ToString(settings["rowcount"]))) {
txtRowCount.Text = Convert.ToString(settings["rowcount"]);
}
if (!string.IsNullOrEmpty(Convert.ToString(settings["style"]))) {
rbStyle.SelectedValue = Convert.ToString(settings["style"]);
}
}
//Module failed to load
} catch (Exception exc) {
Exceptions.ProcessModuleLoadException(this, exc);
}
// Localization
rbStyle.Items[0].Text = Localization.GetString("CategoryListing", LocalResourceFile);
rbStyle.Items[1].Text = Localization.GetString("MultiColumnCategoryListing", LocalResourceFile);
rbStyle.Items[2].Text = Localization.GetString("LatestUploads", LocalResourceFile);
rbStyle.Items[3].Text = Localization.GetString("TopDownloads", LocalResourceFile);
rbStyle.Items[4].Text = Localization.GetString("TopRated", LocalResourceFile);
}
#endregion
#region "Public functions and Subs"
public override void UpdateSettings()
{
try {
ModuleController objModules = new ModuleController();
ListItem item = null;
if (!string.IsNullOrEmpty(ddlRepositoryID.SelectedValue)) {
objModules.UpdateModuleSetting(ModuleId, "repository", Convert.ToInt32(ddlRepositoryID.SelectedValue).ToString());
}
if (!string.IsNullOrEmpty(rbStyle.SelectedValue)) {
objModules.UpdateModuleSetting(ModuleId, "style", Convert.ToString(rbStyle.SelectedValue));
}
if (!string.IsNullOrEmpty(txtRowCount.Text)) {
objModules.UpdateModuleSetting(ModuleId, "rowcount", Convert.ToInt32(txtRowCount.Text).ToString());
}
// Redirect back to the portal home page
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(), true);
//Module failed to load
} catch (Exception exc) {
lblMessage.Text = exc.Message;
}
}
public DashboardSettings()
{
Load += Page_Load;
Init += Page_Init;
}
#endregion
}
}