forked from DNNCommunity/DNN.IFrame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IframeOptions.ascx.cs
630 lines (573 loc) · 22.5 KB
/
IframeOptions.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/*
* DNN Corp. - http://www.dnnsoftware.com
* Copyright (c) 2016
* by DNN Corp.
*
* 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 DotNetNuke.Modules.IFrame.Components;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Framework;
using DotNetNuke.Framework.JavaScriptLibraries;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DotNetNuke.Modules.IFrame.UI
{
public partial class IframeOptions : PortalModuleBase
{
#region Private Properties
private ModuleController _moduleController = null;
protected ModuleController ModuleController
{
get
{
if (_moduleController == null)
_moduleController = new ModuleController();
return _moduleController;
}
}
private ParametersController _parametersController = null;
protected ParametersController ParametersController
{
get
{
if (_parametersController == null)
_parametersController = new ParametersController();
return _parametersController;
}
}
protected bool HashParameterSet
{
get { return Convert.ToBoolean(ViewState["HashParameterSet"]); }
set { ViewState["HashParameterSet"] = value; }
}
protected string LocalSharedResourceFile
{
get { return string.Format("{0}{1}/{2}", ControlPath, Localization.LocalResourceDirectory, Localization.LocalSharedResourceFile); }
}
#endregion
#region Settings
private string Source
{
get { return Convert.ToString(Settings["Source"]); }
set { UpdateTextSetting("Source", value); }
}
private string UrlType
{
get { return Convert.ToString(Settings["UrlType"]); }
set { UpdateTextSetting("UrlType", value); }
}
private string Width
{
get { return Convert.ToString(Settings["Width"]); }
set { UpdateTextSetting("Width", value); }
}
private string Height
{
get { return Convert.ToString(Settings["Height"]); }
set { UpdateTextSetting("Height", value); }
}
private bool AutoHeight
{
get
{
bool autoHeight;
try
{
object o = Settings["AutoHeight"];
if (o == null)
autoHeight = false;
else
autoHeight = Convert.ToBoolean(o);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid AutoHeight value: {0}", Settings["AutoHeight"]), ex);
Exceptions.LogException(ex1);
autoHeight = false;
}
return autoHeight;
}
set { UpdateBooleanSetting("AutoHeight", value); }
}
private Scrolling Scrolling
{
get
{
Scrolling scrolling;
try
{
object o = Settings["Scrolling"];
if (o == null)
scrolling = Scrolling.Auto;
else
scrolling = (Scrolling)Convert.ToInt32(o);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid Scrolling value: {0}", Settings["Scrolling"]), ex);
Exceptions.LogException(ex1);
scrolling = Scrolling.Auto;
}
return scrolling;
}
set { UpdateIntegerSetting("Scrolling", Convert.ToInt32(value)); }
}
private bool Border
{
get
{
bool border;
try
{
border = Convert.ToBoolean(Settings["Border"]);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid Border value: {0}", Settings["Border"]), ex);
Exceptions.LogException(ex1);
border = false;
}
return border;
}
set { UpdateBooleanSetting("Border", value); }
}
private bool AllowTransparency
{
get
{
bool allowTransparency;
try
{
allowTransparency = Convert.ToBoolean(Settings["AllowTransparency"]);
}
catch (Exception ex)
{
Exception ex1 = new Exception(string.Format("Invalid Border value: {0}", Settings["AllowTransparency"]), ex);
Exceptions.LogException(ex1);
allowTransparency = false;
}
return allowTransparency;
}
set { UpdateBooleanSetting("AllowTransparency", value); }
}
private string Name
{
get { return Convert.ToString(Settings["Name"]); }
set { UpdateTextSetting("Name", value); }
}
private string ToolTip
{
get { return Convert.ToString(Settings["ToolTip"]); }
set { UpdateTextSetting("ToolTip", value); }
}
private string CssStyle
{
get { return Convert.ToString(Settings["CssStyle"]); }
set { UpdateTextSetting("CssStyle", value); }
}
private string OnLoadJavaScript
{
get { return Convert.ToString(Settings["OnLoadJavaScript"]); }
set { UpdateTextSetting("OnLoadJavaScript", value); }
}
#endregion
#region Events (Page)
protected override void OnInit(EventArgs e)
{
JavaScript.RequestRegistration(CommonJs.DnnPlugins);
ClientAPI.RegisterClientReference(Page, ClientAPI.ClientNamespaceReferences.dnn);
if (AJAX.IsEnabled())
{
ScriptManager.GetCurrent(Page).RegisterPostBackControl(UpdateParameterButton);
ScriptManager.GetCurrent(Page).RegisterPostBackControl(UpdateButton);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
// Assign values
SourceUrl.Url = Source;
SourceUrl.UrlType = UrlType;
WidthTextBox.Text = Width;
HeightTextBox.Text = Height;
AutoHeightCheckBox.Checked = AutoHeight;
BorderCheckBox.Checked = Border;
AllowTransparencyCheckBox.Checked = AllowTransparency;
NameTextBox.Text = Name;
ToolTipTextBox.Text = ToolTip;
CssStyleTextBox.Text = CssStyle;
JavascriptTextBox.Text = (AutoHeight ? string.Empty : OnLoadJavaScript);
UpdateParameterButton.Text = Localization.GetString("AddParameter", LocalResourceFile);
JavaScriptPanel.Visible = (!(AutoHeight));
Localization.LocalizeDataGrid(ref ParametersGrid, LocalResourceFile);
BindData();
}
}
protected override void OnPreRender(EventArgs e)
{
StringBuilder scriptBuilder = new StringBuilder();
scriptBuilder.Append("jQuery(function ($, Sys) {\r\n");
scriptBuilder.Append(" function setUpIFrameOptionTabs() {\r\n");
scriptBuilder.Append(" $(\"#");
scriptBuilder.Append(IFrameOptionTabs.ClientID);
scriptBuilder.Append("\").dnnTabs();\r\n");
scriptBuilder.Append(" }\r\n");
// This jQuery script adds a confirmation dialog to the delete buttons in the parameter grid.
// The text for the parameter name is taken from the cell with the style class "ConfirmData", this
// is only used a selector and does not apply the form stylings
scriptBuilder.Append(" function confirmDelete() {\r\n");
scriptBuilder.Append(" $(\".dnnGrid .DeleteButton\").each(function() {\r\n");
scriptBuilder.Append(" $(this).dnnConfirm({\r\n");
scriptBuilder.Append(" text: \"Are you sure you want to delete '\" + $(\".ConfirmData\", $(this).parents(\"tr\")).text() + \"'?\",\r\n");
scriptBuilder.Append(" yesText: \"Yes\",\r\n");
scriptBuilder.Append(" noText: \"No\",\r\n");
scriptBuilder.Append(" title: \"Confirm\",\r\n");
scriptBuilder.Append(" dialogClass: \"dnnFormPopup\",\r\n");
scriptBuilder.Append(" isButton: true\r\n");
scriptBuilder.Append(" });\r\n");
scriptBuilder.Append(" });\r\n");
scriptBuilder.Append(" }\r\n");
scriptBuilder.Append(" $(document).ready(function () {\r\n");
scriptBuilder.Append(" setUpIFrameOptionTabs();\r\n");
scriptBuilder.Append(" Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function () {\r\n");
scriptBuilder.Append(" setUpIFrameOptionTabs();\r\n");
scriptBuilder.Append(" });\r\n");
scriptBuilder.Append(" Sys.Application.add_load(function () {\r\n");
scriptBuilder.Append(" confirmDelete();");
scriptBuilder.Append(" });\r\n");
scriptBuilder.Append(" });\r\n");
scriptBuilder.Append("}(jQuery, window.Sys));\r\n");
if (!(Page.ClientScript.IsStartupScriptRegistered("IFrameOptionTabs")))
Page.ClientScript.RegisterStartupScript(GetType(), "IFrameOptionTabs", scriptBuilder.ToString(), true);
DisplayOrHideParameterFormPanels();
}
public void ScrollingDropDownList_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
try
{
DropDownList scrollingDropDownList = (DropDownList)sender;
for (int i = 0; i < Enum.GetNames(typeof(Scrolling)).Length; i++)
{
ListItem li = new ListItem();
li.Value = Convert.ToString(i);
li.Text = Localization.GetString(string.Format("Scrolling.{0}.Text", Enum.GetNames(typeof(Scrolling))[i]), LocalSharedResourceFile);
scrollingDropDownList.Items.Add(li);
}
scrollingDropDownList.SelectedValue = Convert.ToString(Convert.ToInt32(Scrolling));
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
try
{
Source = SourceUrl.Url;
UrlType = SourceUrl.UrlType;
Width = WidthTextBox.Text;
Height = HeightTextBox.Text;
AutoHeight = AutoHeightCheckBox.Checked;
Scrolling = (Scrolling)Convert.ToInt32(ScrollingDropDownList.SelectedValue);
Border = BorderCheckBox.Checked;
AllowTransparency = AllowTransparencyCheckBox.Checked;
Name = NameTextBox.Text;
ToolTip = ToolTipTextBox.Text;
CssStyle = CssStyleTextBox.Text;
OnLoadJavaScript = (JavaScriptPanel.Visible ? JavascriptTextBox.Text : string.Empty);
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(), true);
Response.Clear();
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void CancelButton_Click(object sender, EventArgs e)
{
try
{
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(), true);
Response.Clear();
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
#endregion
#region Events (Controls)
protected void AutoHeightCheckBox_CheckedChanged(object sender, EventArgs e)
{
CheckBox autoHeightCheckBox = (CheckBox)sender;
JavaScriptPanel.Visible = (!(autoHeightCheckBox.Checked));
}
#endregion
#region Events (Parameters)
protected void ParametersGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
{
try
{
DataGrid parametersGrid = (DataGrid)sender;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
Label typeLabel = (Label)e.Item.FindControl("TypeLabel");
if (typeLabel != null)
typeLabel.Text = Localization.GetString(string.Format("ParameterType.{0}.Text", typeLabel.Text), LocalSharedResourceFile);
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void EditButton_Click(object sender, ImageClickEventArgs e)
{
try
{
ImageButton editButton = (ImageButton)sender;
ParametersInfo parameter = ParametersController.GetParameter(Convert.ToInt32(editButton.CommandArgument));
ParameterTypeDropDownList.SelectedValue = Convert.ToString(Convert.ToInt32(parameter.Type));
ParameterNameTextBox.Text = parameter.Name;
ParameterValueTextBox.Text = parameter.Argument;
UseAsHashCheckBox.Checked = parameter.UseAsHash;
UpdateParameterButton.Text = Localization.GetString("UpdateParameter", LocalResourceFile);
UpdateParameterButton.CommandArgument = editButton.CommandArgument;
DisplayOrHideParameterFormPanels();
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void DeleteButton_Click(object sender, ImageClickEventArgs e)
{
try
{
ImageButton deleteButton = (ImageButton)sender;
if (deleteButton != null)
{
ParametersInfo parameter = ParametersController.GetParameter(Convert.ToInt32(deleteButton.CommandArgument));
ParametersController.DropParameter(parameter);
BindData();
}
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void ParameterTypeDropDownList_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
try
{
DropDownList parameterTypeDropDownList = (DropDownList)sender;
for (int i = 0; i < Enum.GetNames(typeof(ParameterType)).Length; i++)
{
ListItem li = new ListItem();
li.Value = Convert.ToString(i);
li.Text = li.Text = Localization.GetString(string.Format("ParameterType.{0}.Text", Enum.GetNames(typeof(ParameterType))[i]), LocalSharedResourceFile);
parameterTypeDropDownList.Items.Add(li);
}
parameterTypeDropDownList.SelectedValue = "0";
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
}
protected void ParameterTypeDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DisplayOrHideParameterFormPanels();
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void UseAsHashCheckBox_CheckedChanged(object sender, EventArgs e)
{
try
{
DisplayOrHideParameterFormPanels();
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void UpdateParameterButton_Click(object sender, EventArgs e)
{
try
{
LinkButton updateParameterButton = (LinkButton)sender;
ParametersInfo parameter;
if (updateParameterButton.CommandArgument == "-1")
parameter = new ParametersInfo();
else
parameter = ParametersController.GetParameter(Convert.ToInt32(updateParameterButton.CommandArgument));
parameter.ModuleID = ModuleId;
parameter.Type = (ParameterType)Convert.ToInt32(ParameterTypeDropDownList.SelectedValue);
parameter.Name = ParameterNameTextBox.Text;
parameter.Argument = (ParameterValuePanel.Visible ? ParameterValueTextBox.Text : null);
parameter.UseAsHash = UseAsHashCheckBox.Checked;
if (updateParameterButton.CommandArgument == "-1")
ParametersController.AddParameter(parameter);
else
ParametersController.ChangeParameter(parameter);
ResetParametersForm(true);
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
protected void ResetParametersFormButton_Click(object sender, EventArgs e)
{
try
{
ResetParametersForm(false);
}
catch (Exception ex)
{
Exceptions.ProcessModuleLoadException(this, ex);
}
}
#endregion
#region Private Methods
private void BindData()
{
List<ParametersInfo> parameters = (List<ParametersInfo>)ParametersController.GetParameters(ModuleId);
if ((parameters == null) || (parameters.Count == 0))
{
ParametersMessage.Visible = true;
ParametersGrid.Visible = false;
}
else
{
ParametersMessage.Visible = false;
ParametersGrid.Visible = true;
ParametersGrid.DataSource = parameters;
ParametersGrid.DataBind();
ParametersMessage.Visible = false;
HashParameterSet = false;
foreach (ParametersInfo p in parameters)
{
if (p.UseAsHash)
{
HashParameterSet = true;
break;
}
}
}
}
private void DisplayOrHideParameterFormPanels()
{
switch ((ParameterType)Convert.ToInt32(ParameterTypeDropDownList.SelectedValue))
{
case ParameterType.StaticValue:
case ParameterType.PassThrough:
case ParameterType.UserCustomProperty:
case ParameterType.FormPassThrough:
ParameterValuePanel.Visible = true;
break;
default:
ParameterValuePanel.Visible = false;
break;
}
UseAsHashPanel.Visible = ((!(HashParameterSet)) || ((UpdateParameterButton.CommandArgument != "-1") && (UseAsHashCheckBox.Checked)));
ParameterValuePanel.Visible = (!(UseAsHashCheckBox.Checked)) && ParameterValuePanel.Visible;
}
private void ResetParametersForm(bool bindData)
{
ParameterTypeDropDownList.SelectedValue = "0";
ParameterNameTextBox.Text = string.Empty;
ParameterValueTextBox.Text = string.Empty;
ParameterValuePanel.Visible = true;
UseAsHashCheckBox.Checked = false;
ParametersGrid.SelectedIndex = -1;
if (bindData)
BindData();
UpdateParameterButton.Text = Localization.GetString("AddParameter", LocalResourceFile);
UpdateParameterButton.CommandArgument = "-1";
DisplayOrHideParameterFormPanels();
}
private void UpdateTextSetting(string setting, string settingValue)
{
if (Settings[setting] == null)
{
if (!(string.IsNullOrEmpty(settingValue)))
ModuleController.UpdateModuleSetting(ModuleId, setting, settingValue);
}
else
{
if (!(string.IsNullOrEmpty(settingValue)))
ModuleController.UpdateModuleSetting(ModuleId, setting, settingValue);
else
ModuleController.DeleteModuleSetting(ModuleId, setting);
}
}
private void UpdateIntegerSetting(string setting, int? settingValue)
{
if (Settings[setting] == null)
{
if (settingValue != null)
{
ModuleController.UpdateModuleSetting(ModuleId, setting, settingValue.ToString());
}
}
else
{
if (settingValue != null)
ModuleController.UpdateModuleSetting(ModuleId, setting, settingValue.ToString());
else
ModuleController.DeleteModuleSetting(ModuleId, setting);
}
}
private void UpdateBooleanSetting(string setting, bool settingValue)
{
if (Settings[setting] == null)
{
if (settingValue)
ModuleController.UpdateModuleSetting(ModuleId, setting, settingValue.ToString());
}
else
{
if (settingValue)
ModuleController.UpdateModuleSetting(ModuleId, setting, settingValue.ToString());
else
ModuleController.DeleteModuleSetting(ModuleId, setting);
}
}
#endregion
}
}