-
Notifications
You must be signed in to change notification settings - Fork 11
/
ItemDisplayOptions.ascx.cs
387 lines (343 loc) · 16.8 KB
/
ItemDisplayOptions.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
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
// <copyright file="ItemDisplayOptions.ascx.cs" company="Engage Software">
// Engage: Publish
// Copyright (c) 2004-2013
// 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.Publish
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Framework;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
/// <summary>
/// The main settings for Engage: Publish, loads the settings controls for the chosen display type
/// </summary>
public partial class ItemDisplayOptions : ModuleSettingsBase
{
private ModuleSettingsBase _currentSettingsBase;
public int CacheTime
{
get
{
object o = this.Settings["CacheTime"];
if (o != null)
{
return Convert.ToInt32(o.ToString(), CultureInfo.InvariantCulture);
}
int defaultCacheSetting = ModuleBase.GetDefaultCacheSetting(this.PortalId);
if (defaultCacheSetting > 0)
{
return defaultCacheSetting;
}
return 0;
}
}
public override void LoadSettings()
{
base.LoadSettings();
try
{
if (this.Page.IsPostBack == false)
{
this.ddlChooseDisplayType.Items.Add(
new ListItem(Localization.GetString("CustomDisplay", this.LocalResourceFile), "CustomDisplay"));
this.ddlChooseDisplayType.Items.Add(
new ListItem(Localization.GetString("ArticleDisplay", this.LocalResourceFile), "ArticleDisplay"));
this.ddlChooseDisplayType.Items.Add(
new ListItem(Localization.GetString("CategoryNLevels", this.LocalResourceFile), "CategoryNLevels"));
this.ddlChooseDisplayType.Items.Add(
new ListItem(Localization.GetString("CategorySearch", this.LocalResourceFile), "CategorySearch"));
this.ddlChooseDisplayType.Items.Add(
new ListItem(Localization.GetString("CategoryFeatureDisplay", this.LocalResourceFile), "CategoryFeatureDisplay"));
this.ddlChooseDisplayType.Items.Add(
new ListItem(Localization.GetString("CategoryDisplay", this.LocalResourceFile), "CategoryDisplay"));
this.ddlChooseDisplayType.Items.Add(new ListItem(Localization.GetString("ItemListing", this.LocalResourceFile), "ItemListing"));
this.ddlChooseDisplayType.Items.Insert(0, new ListItem(Localization.GetString("ChooseOne", this.LocalResourceFile), string.Empty));
this.SetOptions();
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
public override void UpdateSettings()
{
try
{
var modules = new ModuleController();
if (this.ddlChooseDisplayType.SelectedIndex > 0)
{
modules.UpdateTabModuleSetting(this.TabModuleId, "DisplayType", this.ddlChooseDisplayType.SelectedValue);
}
modules.UpdateTabModuleSetting(this.TabModuleId, "LogBreadCrumb", this.chkLogBreadcrumb.Checked ? "true" : "false");
modules.UpdateTabModuleSetting(this.TabModuleId, "Overrideable", this.chkOverrideable.Checked ? "true" : "false");
//// && ddlChooseDisplayType.SelectedValue != "ItemListing" ? "true" : "false"));
modules.UpdateTabModuleSetting(this.TabModuleId, "AllowTitleUpdate", this.chkAllowTitleUpdate.Checked ? "true" : "false");
modules.UpdateTabModuleSetting(this.TabModuleId, "CacheTime", this.txtCacheTime.Text.Trim());
modules.UpdateTabModuleSetting(this.TabModuleId, "SupportWLW", this.chkEnableWLWSupport.Checked ? "true" : "false");
////foreach (ModuleSettingsBase settingsControl in settingsChildren)
////{
//// settingsControl.UpdateSettings();
////}
this._currentSettingsBase.UpdateSettings();
if (this.divArticleDisplay.Visible && this.divArticleDisplay.Controls.Count > 0)
{
var articleOverrideSettings = this.divArticleDisplay.Controls[0] as ModuleSettingsBase;
if (articleOverrideSettings != null)
{
articleOverrideSettings.UpdateSettings();
}
}
if (this.divCategoryDisplay.Visible && this.divCategoryDisplay.Controls.Count > 0)
{
var categoryOverrideSettings = this.divCategoryDisplay.Controls[0] as ModuleSettingsBase;
if (categoryOverrideSettings != null)
{
categoryOverrideSettings.UpdateSettings();
}
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <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.Load += this.Page_Load;
this.btnConfigure.Click += this.BtnConfigureClick;
this.ddlChooseDisplayType.SelectedIndexChanged += this.DdlChooseDisplayTypeSelectedIndexChanged;
var moduleCssUrl = this.ResolveUrl("Module.css");
PageBase.RegisterStyleSheet(this.Page, moduleCssUrl, true);
if (AJAX.IsInstalled())
{
AJAX.RegisterScriptManager();
}
}
/// <summary>
/// Gets a value indicating whether the given display type supports QueryString overriding.
/// </summary>
/// <param name="selectedDisplayType">Display type of the selected.</param>
/// <returns><c>true</c> if the given display type supports QueryString overriding, otherwise <c>false</c></returns>
private static bool SupportsOverride(string selectedDisplayType)
{
return selectedDisplayType == "ArticleDisplay" || selectedDisplayType == "CategoryDisplay" || selectedDisplayType == "CustomDisplay" ||
selectedDisplayType == "ItemListing" || string.IsNullOrEmpty(selectedDisplayType);
}
/// <summary>
/// Handles the Click event of the btnConfigure control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Member",
Justification = "Controls use lower case prefix")]
private void BtnConfigureClick(object sender, EventArgs e)
{
this.pnlConfigureOverrideable.Visible = true;
}
private ModuleSettingsBase CreateSettingsControl(string controlName)
{
var settingsControl = (ModuleSettingsBase)this.LoadControl(controlName);
settingsControl.ModuleConfiguration = new ModuleController().GetModule(this.ModuleId, this.TabId);
settingsControl.ModuleId = this.ModuleId;
settingsControl.TabModuleId = this.TabModuleId;
settingsControl.ID = Path.GetFileNameWithoutExtension(controlName);
var overrideableSettingsControl = settingsControl as OverrideableDisplayOptionsBase;
if (overrideableSettingsControl != null)
{
overrideableSettingsControl.ForceSetInitialValues = true;
}
settingsControl.LoadSettings();
return settingsControl;
}
/// <summary>
/// Handles the SelectedIndexChanged event of the ddlChooseDisplayType control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Member",
Justification = "Controls use lower case prefix")]
private void DdlChooseDisplayTypeSelectedIndexChanged(object sender, EventArgs e)
{
this.DisplaySettingsControl();
}
private void DisplaySettingsControl()
{
if (this.ddlChooseDisplayType.SelectedItem == null)
{
return;
}
if (this.phControls.Controls.Count > 0)
{
this.phControls.Controls.Clear();
}
string selectedDisplayType = this.ddlChooseDisplayType.SelectedValue;
switch (selectedDisplayType)
{
case "CustomDisplay":
this.LoadSettingsControl("controls/CustomDisplayOptions.ascx" /*, "CustomDisplayOptions"*/);
break;
case "ArticleDisplay":
this.LoadSettingsControl("articlecontrols/ArticleDisplayOptions.ascx" /*, "ArticleDisplayOptions"*/);
// configure ShowArticle=true
break;
case "CategoryDisplay":
this.LoadSettingsControl("categorycontrols/CategoryDisplayOptions.ascx" /*, "CategoryDisplayOptions"*/);
break;
case "CategoryNLevels":
this.LoadSettingsControl("categorycontrols/CategoryNLevelsOptions.ascx" /*, "CategoryNLevelsOptions"*/);
break;
case "CategoryFeatureDisplay":
this.LoadSettingsControl("categorycontrols/CategoryFeatureOptions.ascx" /*, "CategoryFeatureOptions"*/);
break;
case "CategorySearch":
this.LoadSettingsControl("categorycontrols/CategorySearchOptions.ascx" /*, "CategorySearchOptions"*/);
break;
case "ItemListing":
this.LoadSettingsControl("controls/ItemListingOptions.ascx" /*, "ItemListingOptions"*/);
break;
default:
break;
}
if (selectedDisplayType == "CustomDisplay")
{
this.shCategoryDisplay.Visible = false;
this.shCategoryDisplay.IsExpanded = false;
this.divCategoryDisplay.Controls.Clear();
}
else
{
this.shCategoryDisplay.Visible = true;
this.shCategoryDisplay.IsExpanded = true;
this.divCategoryDisplay.Controls.Clear();
this.divCategoryDisplay.Controls.Add(this.CreateSettingsControl("controls/CustomDisplayOptions.ascx"));
}
if (selectedDisplayType == "ArticleDisplay")
{
this.shArticleDisplay.Visible = false;
this.shArticleDisplay.IsExpanded = false;
this.divArticleDisplay.Controls.Clear();
}
else
{
this.shArticleDisplay.Visible = true;
// only expand one of the sections if both are displayed. BD
// we are making Article Display the choice which is closed if both are shown, because article display doesn't do any callbacks (presently),
// so you don't have the problem of making a settings change and then the callback un-expands what you were working on.
this.shArticleDisplay.IsExpanded = !this.shCategoryDisplay.IsExpanded;
this.divArticleDisplay.Controls.Clear();
this.divArticleDisplay.Controls.Add(this.CreateSettingsControl("articlecontrols/ArticleDisplayOptions.ascx"));
}
// Currently on Article, Category and the new Custom Display (subject to change) allows override on querystring.
bool supportsOverride = SupportsOverride(selectedDisplayType);
this.chkOverrideable.Enabled = supportsOverride;
if (!supportsOverride)
{
this.chkOverrideable.Checked = false;
}
this.btnConfigure.Visible = supportsOverride;
}
private void LoadSettingsControl(string controlName)
{
this.phControls.EnableViewState = false;
this._currentSettingsBase = this.CreateSettingsControl(controlName);
this.phControls.Controls.Add(this._currentSettingsBase);
}
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void Page_Load(object sender, EventArgs e)
{
try
{
// by now ViewState has been restored so we can set the Settings control.
this.DisplaySettingsControl();
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void SetOptions()
{
object o = this.Settings["DisplayType"];
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
ListItem li = this.ddlChooseDisplayType.Items.FindByValue(this.Settings["DisplayType"].ToString());
if (li != null)
{
li.Selected = true;
}
}
o = this.Settings["Overrideable"];
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
bool overrideable;
if (bool.TryParse(this.Settings["Overrideable"].ToString(), out overrideable))
{
this.chkOverrideable.Checked = overrideable;
}
}
else
{
// default to checked when not set.
this.chkOverrideable.Checked = true;
}
o = this.Settings["AllowTitleUpdate"];
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
bool allowTitleUpdate;
if (bool.TryParse(this.Settings["AllowTitleUpdate"].ToString(), out allowTitleUpdate))
{
this.chkAllowTitleUpdate.Checked = allowTitleUpdate;
}
}
o = this.Settings["CacheTime"];
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
this.txtCacheTime.Text = o.ToString();
}
else
{
this.txtCacheTime.Text = this.CacheTime.ToString(CultureInfo.InvariantCulture);
}
o = this.Settings["LogBreadCrumb"];
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
this.chkLogBreadcrumb.Checked = o.ToString().Equals("true");
}
o = this.Settings["SupportWLW"];
if (o != null && !string.IsNullOrEmpty(o.ToString()))
{
bool supportWlw;
if (bool.TryParse(this.Settings["SupportWLW"].ToString(), out supportWlw))
{
this.chkEnableWLWSupport.Checked = supportWlw;
}
}
else
{
// default to not checked when not set.
this.chkEnableWLWSupport.Checked = false;
}
}
}
}