-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTokenSettings.ascx.cs
164 lines (153 loc) · 5.56 KB
/
TokenSettings.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
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using Satrabel.OpenBlocks.Token;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SatraBel.OpenBlocks
{
public partial class TokenSettings : System.Web.UI.UserControl
{
public string LocalResourceFile { get; set; }
public int PortalId { get; set; }
protected string PostBackStr;
protected string CloseDialogStr;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
/*
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "alert(\"hello\")", "");
string callbackScript = "<script type=\"text/javascript\">function CallServer(arg, context)" + "{ " + cbReference + ";}</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript);
*/
PostBackStr = Page.ClientScript.GetPostBackEventReference(Page, "EditorClose");
if (Page.IsPostBack)
{
string eventArg = Request["__EVENTARGUMENT"];
if (eventArg == "EditorClose")
{
CloseDialogStr = "<script type=\"text/javascript\">" +
"window.parent.EditorCloseCallBack('" + GetToken() + "');" +
"</script>";
}
}
try
{
if (!Page.IsPostBack)
{
foreach (var item in TokenProvider.GetProviderList())
{
ddlTokens.Items.Add(new ListItem(item.FriendlyName));
}
foreach (TokenConfigurator conf in phConfigurator.Controls)
{
conf.Visible = ddlTokens.SelectedValue == conf.ID;
}
}
}
catch (Exception exc) // Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
LocalResourceFile = ResXFile;
//PortalId =
foreach (var provider in TokenProvider.GetProviderList())
{
if (!string.IsNullOrEmpty(provider.Configurator))
{
var ctrl = this.LoadControl(provider.Configurator);
TokenConfigurator conf = ctrl as TokenConfigurator;
if (conf != null)
{
conf.PortalId = PortalId;
conf.LocalResourceFile = LocalResourceFile;
conf.ID = provider.FriendlyName;
phConfigurator.Controls.Add(ctrl);
}
}
}
}
#region Base Method Implementations
public void LoadSettings(Hashtable settings)
{
try
{
if (!Page.IsPostBack)
{
foreach (var item in TokenProvider.GetProviderList())
{
ddlTokens.Items.Add(new ListItem(item.FriendlyName));
}
ddlTokens.SelectedValue = (string)settings["TokenProvider"];
foreach (TokenConfigurator conf in phConfigurator.Controls)
{
conf.Visible = ddlTokens.SelectedValue == conf.ID;
conf.LoadSettings(settings);
}
}
}
catch (Exception exc) // Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
public Hashtable SaveSettings()
{
Hashtable settings = new Hashtable();
settings.Add("TokenProvider", ddlTokens.SelectedValue);
foreach (TokenConfigurator conf in phConfigurator.Controls)
{
var sets = conf.SaveSettings();
foreach (DictionaryEntry set in sets)
{
settings.Add((string)set.Key, (string)set.Value);
}
if (conf.Visible)
{
settings.Add("Token", conf.getToken());
}
}
return settings;
}
#endregion
protected void ddlTokens_SelectedIndexChanged(object sender, EventArgs e)
{
var provider = TokenProvider.Instance(ddlTokens.SelectedValue);
foreach (TokenConfigurator conf in phConfigurator.Controls)
{
conf.Visible = ddlTokens.SelectedValue == conf.ID;
}
}
public string GetToken()
{
foreach (TokenConfigurator conf in phConfigurator.Controls)
{
if (conf.Visible)
{
return conf.getToken();
}
}
return "";
}
protected string ResXFile
{
get
{
return
this.ResolveUrl(
string.Format(
"~/DesktopModules/Satrabel/Widget/{0}/TokenSettings.ascx.resx",
Localization.LocalResourceDirectory));
}
}
}
}