-
Notifications
You must be signed in to change notification settings - Fork 3
/
ModuleBase.cs
289 lines (257 loc) · 15.3 KB
/
ModuleBase.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
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
// <copyright file="ModuleBase.cs" company="Engage Software">
// Engage: Dashboard - http://www.engagemodules.com
// Copyright (c) 2004-2008
// by Engage Software ( http://www.engagesoftware.com )
// </copyright>
// 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.
namespace Engage.Dnn.Dashboard
{
using System;
using System.Globalization;
using System.Web;
using System.Web.UI;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Framework;
using DotNetNuke.Security;
using DotNetNuke.Services.Localization;
using Globals = DotNetNuke.Common.Globals;
/// <summary>
/// Contains base functionality
/// </summary>
public class ModuleBase : PortalModuleBase, IActionable
{
/// <summary>
/// Path to the DesktopModules folder for this module.
/// Add ~ to be beginning if you want ASP.NET to make it fully relative.
/// Starts and ends with path separators, that is, "/".
/// </summary>
protected const string DesktopModuleFolderName = "/DesktopModules/EngageDashboard/";
/// <summary>
/// Path to the resource file for resources that apply to multiple controls within this module.
/// </summary>
protected const string DashboardResourceFile = "~" + DesktopModuleFolderName + "App_LocalResources/Dashboard.resx";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when a <see cref="DashboardItem"/> Date Range is hidden.
/// </summary>
protected const string ShowDateRange = "showDateRange";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when a <see cref="DashboardItem"/> Details Panel is hidden.
/// </summary>
protected const string ShowDetails = "showDetails";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when a <see cref="DashboardItem"/> Date Range is shown.
/// </summary>
protected const string HideDateRange = "hideDateRange";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when a <see cref="DashboardItem"/> Details Panel is shown.
/// </summary>
protected const string HideDetails = "hideDetails";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when the Install Charting Support text is hidden.
/// </summary>
protected const string LearnMore = "learnMore";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when the Install Charting Support text is shown.
/// </summary>
protected const string LearnLess = "learnLess";
/// <summary>
/// Path to the folder that contains JavaScript in this module
/// </summary>
private const string JavaScriptResourcePath = "Engage.Dnn.Dashboard.JavaScript.";
/// <summary>
/// The URL to the JQuery library script.
/// </summary>
private const string JQueryResourcePath = "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js";
/// <summary>
/// The path to the embedded resource of the JavaScript file for this module.
/// </summary>
private const string DashboardScriptResourcePath = JavaScriptResourcePath + "EngageDashboard.js";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when explanatory text is hidden.
/// </summary>
private const string ShowExplanatoryText = "showExplanatoryText";
/// <summary>
/// Name of JavaScript variable registered by <see cref="RegisterScripts"/> which holds the text to display when explanatory text is shown.
/// </summary>
private const string HideExplanatoryText = "hideExplanatoryText";
/// <summary>
/// Gets the module actions.
/// </summary>
/// <value>The module actions.</value>
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection actions = new ModuleActionCollection();
// Add Online Help Action
if (HostSettings.GetHostSetting("EnableModuleOnLineHelp") == "Y" && Engage.Utility.HasValue(this.ModuleConfiguration.HelpUrl))
{
ModuleAction helpAction = new ModuleAction(this.GetNextActionID());
helpAction.Title = Localization.GetString(ModuleActionType.OnlineHelp, Localization.GlobalResourceFile);
helpAction.CommandName = ModuleActionType.OnlineHelp;
helpAction.CommandArgument = string.Empty;
helpAction.Icon = "action_help.gif";
helpAction.Url = Globals.FormatHelpUrl(this.ModuleConfiguration.HelpUrl, this.PortalSettings, this.ModuleConfiguration.FriendlyName);
helpAction.Secure = SecurityAccessLevel.Edit;
helpAction.UseActionEvent = true;
helpAction.Visible = true;
helpAction.NewWindow = true;
actions.Add(helpAction);
}
return actions;
}
}
/// <summary>
/// Gets the base URL for this application.
/// </summary>
/// <value>The application URL.</value>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "Usage is ASP.NET markup or NavigateUrl, shouldn't be strongly typed")]
protected static string ApplicationUrl
{
get
{
return HttpContext.Current.Request.ApplicationPath == "/" ? string.Empty : HttpContext.Current.Request.ApplicationPath;
}
}
/// <summary>
/// Gets a value indicating whether the current user has edit rights to this module.
/// </summary>
/// <value><c>true</c> if the current user can edit the module; otherwise, <c>false</c>.</value>
protected bool IsAdmin
{
get
{
return this.Request.IsAuthenticated && PortalSecurity.HasNecessaryPermission(SecurityAccessLevel.Edit, this.PortalSettings, this.ModuleConfiguration, this.UserInfo.Username);
}
}
/// <summary>
/// Gets the closest parent of this control which is a <see cref="PortalModuleBase"/>.
/// </summary>
/// <returns>The closest parent of this control which is a <see cref="PortalModuleBase"/></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Casting using 'as' operator would be cumbersome and probably less performant")]
protected PortalModuleBase ParentPortalModuleBase
{
get
{
Control parentControl = this.Parent;
while (parentControl != null && !(parentControl is PortalModuleBase))
{
parentControl = parentControl.Parent;
}
return (PortalModuleBase)parentControl;
}
}
/// <summary>
/// Sets up the date range controls to the default of one month ago to today, if the date range is not already set.
/// </summary>
/// <param name="dashboardItem">A <see cref="DashboardItem"/> with a date range</param>
protected static void SetupDateRangeControls(DashboardItem dashboardItem)
{
dashboardItem.BeginDate = dashboardItem.BeginDate ?? DateTime.Today.AddMonths(-1);
dashboardItem.EndDate = dashboardItem.EndDate ?? DateTime.Today;
}
/// <summary>
/// Gets the toggle behavior for explanatory text.
/// </summary>
/// <param name="clientId">The client id.</param>
/// <returns>A string containing a JavaScript call.</returns>
protected static string GetToggleBehavior(string clientId)
{
return GetToggleBehavior(clientId, ShowExplanatoryText, HideExplanatoryText);
}
/// <summary>
/// Gets the toggle behavior.
/// </summary>
/// <param name="clientId">The client id.</param>
/// <param name="showTextVariableName">Name of a JavaScript variable that has been defined which holds the text to display in the link when the content is hidden.</param>
/// <param name="hideTextVariableName">Name of a JavaScript variable that has been defined which holds the text to display in the link when the content is being displayed.</param>
/// <returns>A string containing a JavaScript call.</returns>
protected static string GetToggleBehavior(string clientId, string showTextVariableName, string hideTextVariableName)
{
return string.Format(CultureInfo.InvariantCulture, "toggleElementVisibility(this, '{0}', '{1}', '{2}');", clientId, showTextVariableName, hideTextVariableName);
}
/// <summary>
/// Builds a URL for this TabId, using the given querystring parameters.
/// </summary>
/// <param name="moduleId">The module id of the module for which the control key is being used.</param>
/// <param name="controlKey">The control key to determine which control to load.</param>
/// <returns>
/// A URL to the current TabId, with the given querystring parameters
/// </returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "Usage is NavigateUrl, shouldn't be strongly typed")]
protected string BuildLinkUrl(int moduleId, ControlKey controlKey)
{
return this.BuildLinkUrl("modId=" + moduleId.ToString(CultureInfo.InvariantCulture), "key=" + controlKey.ToString());
}
/// <summary>
/// Builds a URL for this TabId, using the given querystring parameters.
/// </summary>
/// <param name="moduleId">The module id of the module for which the control key is being used.</param>
/// <param name="controlKey">The control key to determine which control to load.</param>
/// <param name="queryStringParameters">Any other querystring parameters.</param>
/// <returns>
/// A URL to the current TabId, with the given querystring parameters
/// </returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "Usage is NavigateUrl, shouldn't be strongly typed")]
protected string BuildLinkUrl(int moduleId, ControlKey controlKey, params string[] queryStringParameters)
{
Array.Resize(ref queryStringParameters, queryStringParameters.Length + 2);
queryStringParameters[queryStringParameters.Length - 1] = "modId=" + moduleId.ToString(CultureInfo.InvariantCulture);
queryStringParameters[queryStringParameters.Length - 2] = "key=" + controlKey.ToString();
return this.BuildLinkUrl(queryStringParameters);
}
/// <summary>
/// Builds a URL for this TabId, using the given querystring parameters.
/// </summary>
/// <param name="queryStringParameters">The qs parameters.</param>
/// <returns>A URL to the current TabId, with the given querystring parameters</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1055:UriReturnValuesShouldNotBeStrings", Justification = "Usage is NavigateUrl, shouldn't be strongly typed")]
protected string BuildLinkUrl(params string[] queryStringParameters)
{
return Globals.NavigateURL(this.TabId, string.Empty, queryStringParameters);
}
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Init"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.RegisterScripts();
if (AJAX.IsInstalled())
{
AJAX.RegisterScriptManager();
}
}
/// <summary>
/// Registers the client script includes for this module.
/// </summary>
private void RegisterScripts()
{
this.Page.ClientScript.RegisterClientScriptInclude(typeof(ModuleBase), "jquery 1.2.6", JQueryResourcePath);
this.Page.ClientScript.RegisterClientScriptResource(typeof(ModuleBase), DashboardScriptResourcePath);
this.Page.ClientScript.RegisterStartupScript(typeof(ModuleBase), "jQueryNoConflict", "jQuery(document).ready(function(){jQuery.noConflict();});", true);
this.RegisterLinkTextResources();
}
/// <summary>
/// Registers JavaScript variables with the text to use when switching between hidden and shown states using <see cref="GetToggleBehavior(string)"/> or <see cref="GetToggleBehavior(string,string,string)"/>.
/// </summary>
private void RegisterLinkTextResources()
{
this.Page.ClientScript.RegisterHiddenField(ShowExplanatoryText, Localization.GetString("What's This.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(HideExplanatoryText, Localization.GetString("Hide What's This.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(ShowDetails, Localization.GetString("DetailsLink.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(HideDetails, Localization.GetString("Hide DetailsLink.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(ShowDateRange, Localization.GetString("DateRangeLink.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(HideDateRange, Localization.GetString("Hide DateRangeLink.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(LearnMore, Localization.GetString("Learn More.Text", DashboardResourceFile));
this.Page.ClientScript.RegisterHiddenField(LearnLess, Localization.GetString("Learn Less.Text", DashboardResourceFile));
}
}
}