-
Notifications
You must be signed in to change notification settings - Fork 40
/
EventEditCategories.ascx.cs
371 lines (314 loc) · 14.5 KB
/
EventEditCategories.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
#region Copyright
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2018
// by DotNetNuke Corporation
//
// 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.
//
#endregion
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Web.UI.WebControls;
using Components;
using DNNtc;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
namespace DotNetNuke.Modules.Events
{
[DNNtc.ModuleControlProperties("Categories", "Edit Event Categories", DNNtc.ControlType.View, "https://github.com/DNNCommunity/DNN.Events/wiki", false, true)]
public partial class EventEditCategories : EventBase
{
#region Event Handler
private void Page_Load(object sender, EventArgs e)
{
LocalizeAll();
if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) || IsCategoryEditor())
{ }
else
{
Response.Redirect(GetSocialNavigateUrl(), true);
}
// Set the selected theme
SetTheme(pnlEventsModuleCategories);
if (!Page.IsPostBack)
{
SetDefaultValues();
BindData();
}
}
#endregion
#region Private Functions
private void SetDefaultValues()
{
//Back to normal (add) mode
txtCategoryName.Text = "";
txtCategoryColor.Text = "";
txtCategoryFontColor.Text = "";
ViewState.Remove("Category");
cmdUpdate.Visible = false;
cpBackColor.SelectedColor = ColorTranslator.FromHtml(DefaultBackColor);
cpForeColor.SelectedColor = ColorTranslator.FromHtml(DefaultFontColor);
}
#endregion
#region Web Form Designer Generated Code
//This call is required by the Web Form Designer.
[DebuggerStepThrough]
private void InitializeComponent()
{ }
private void Page_Init(object sender, EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
InitializeComponent();
//Add the external Validation.js to the Page
const string csname = "ExtValidationScriptFile";
var cstype = MethodBase.GetCurrentMethod().GetType();
var cstext = "<script src=\"" + ResolveUrl("~/DesktopModules/Events/Scripts/Validation.js") +
"\" type=\"text/javascript\"></script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered(csname))
{
Page.ClientScript.RegisterClientScriptBlock(cstype, csname, cstext, false);
}
const string csname2 = "LoadPreview";
var cstype2 = MethodBase.GetCurrentMethod().GetType();
var cstext2 = "<script type=\"text/javascript\">byid('" + lblPreviewCat.ClientID +
"').innerHTML = byid('" + txtCategoryName.ClientID + "').value;byid('" +
lblPreviewCat.ClientID + "').style.color = byid('" + txtCategoryFontColor.ClientID +
"').value;byid('" + previewpane.ClientID + "').style.backgroundColor = byid('" +
txtCategoryColor.ClientID + "').value;</script>";
Page.ClientScript.RegisterStartupScript(cstype2, csname2, cstext2, false);
var previewScript = "";
previewScript = "CategoryPreviewPane('" + cpBackColor.ClientID + "','" + cpForeColor.ClientID +
"','" + previewpane.ClientID + "','" + lblPreviewCat.ClientID + "','" +
txtCategoryFontColor.ClientID + "','" + txtCategoryColor.ClientID + "','" +
txtCategoryName.ClientID + "','" +
Localization.GetString("InvalidColor", LocalResourceFile) + "');";
const string csname3 = "ColorPicker";
var cstype3 = MethodBase.GetCurrentMethod().GetType();
var cstext3 = "<script type=\"text/javascript\">";
cstext3 += " function HandleColorChange(sender,eventargs) { $get(\"" + txtCategoryColor.ClientID +
"\").value = sender.get_selectedColor(); " + previewScript + "}";
cstext3 += " function HandleColorFontChange(sender,eventargs) { $get(\"" +
txtCategoryFontColor.ClientID + "\").value = sender.get_selectedColor(); " + previewScript +
"}";
cstext3 += " </script>";
if (!Page.ClientScript.IsClientScriptBlockRegistered(csname3))
{
Page.ClientScript.RegisterClientScriptBlock(cstype3, csname3, cstext3, false);
}
txtCategoryName.Attributes.Add(
"onchange", "byid('" + lblPreviewCat.ClientID + "').innerHTML = this.value;");
txtCategoryFontColor.Attributes.Add("onchange", previewScript);
txtCategoryColor.Attributes.Add("onchange", previewScript);
//ColorPicker Icons
}
#endregion
#region Private Area
//Private itemId As Integer
private readonly EventCategoryController _objCtlCategory = new EventCategoryController();
private EventCategoryInfo _objCategory = new EventCategoryInfo();
private ArrayList _colCategories;
private const string DefaultBackColor = "#ffffff";
private const string DefaultFontColor = "#000000";
#endregion
#region Helper Routines
private void LocalizeAll()
{
GrdCategories.Columns[3].HeaderText = Localization.GetString("plCategoryName", LocalResourceFile);
}
private void BindData()
{
var i = 0;
_colCategories = _objCtlCategory.EventsCategoryList(PortalId);
GrdCategories.DataSource = _colCategories;
GrdCategories.DataBind();
if (GrdCategories.Items.Count > 0)
{
GrdCategories.Visible = true;
for (i = 0; i <= GrdCategories.Items.Count - 1; i++)
{
((ImageButton) GrdCategories.Items[i].FindControl("DeleteButton")).Attributes.Add(
"onclick",
"javascript:return confirm('" +
Localization.GetString(
"AreYouSureYouWishToDelete.Text",
LocalResourceFile) +
"');");
}
}
}
#endregion
#region Control Events
protected void GrdCategories_ItemCommand(object source, DataGridCommandEventArgs e)
{
switch (e.CommandName)
{
case "Select":
int category = Convert.ToInt16(GrdCategories.DataKeys[e.Item.ItemIndex]);
_objCategory = _objCtlCategory.EventCategoryGet(category, PortalId);
txtCategoryName.Text = _objCategory.CategoryName;
if (_objCategory.Color != "")
{
txtCategoryColor.Text = _objCategory.Color;
cpBackColor.SelectedColor = ColorTranslator.FromHtml(txtCategoryColor.Text);
}
else
{
txtCategoryColor.Text = "";
cpBackColor.SelectedColor = ColorTranslator.FromHtml(DefaultBackColor);
}
if (_objCategory.FontColor != "")
{
txtCategoryFontColor.Text = _objCategory.FontColor;
cpForeColor.SelectedColor = ColorTranslator.FromHtml(txtCategoryFontColor.Text);
}
else
{
txtCategoryFontColor.Text = "";
cpForeColor.SelectedColor = ColorTranslator.FromHtml(DefaultFontColor);
}
//Remember that we might use update
ViewState.Add("Category", _objCategory.Category.ToString());
cmdUpdate.Visible = true;
BindData();
break;
}
}
protected void GrdCategories_DeleteCommand(object source, DataGridCommandEventArgs e)
{
var category = 0;
category = Convert.ToInt32(GrdCategories.DataKeys[e.Item.ItemIndex]);
divDeleteError.Visible = false;
var objDesktopModule = default(DesktopModuleInfo);
var objModules = new ModuleController();
objDesktopModule = DesktopModuleController.GetDesktopModuleByModuleName("DNN_Events", PortalId);
var lstModules = objModules.GetModulesByDefinition(PortalId, objDesktopModule.FriendlyName);
foreach (ModuleInfo objModule in lstModules)
{
var categories = Settings.ModuleCategoryIDs;
//EventModuleSettings ems = new EventModuleSettings();
//ArrayList categories = ems.GetEventModuleSettings(objModule.ModuleID, null).ModuleCategoryIDs;
if (categories.Contains(category))
{
lblDeleteError.Text =
string.Format(Localization.GetString("lblDeleteError", LocalResourceFile),
objModule.ModuleTitle);
divDeleteError.Visible = true;
return;
}
}
_objCtlCategory.EventsCategoryDelete(category, PortalId);
BindData();
//Be sure we cannot update any more
txtCategoryName.Text = "";
txtCategoryColor.Text = "";
txtCategoryFontColor.Text = "";
ViewState.Remove("Category");
cmdUpdate.Visible = false;
cpBackColor.SelectedColor = ColorTranslator.FromHtml(DefaultBackColor);
cpForeColor.SelectedColor = ColorTranslator.FromHtml(DefaultFontColor);
}
protected void cmdUpdate_Click(object sender, EventArgs e)
{
try
{
// Only Update if the Entered Data is Valid
if (Page.IsValid && !string.IsNullOrEmpty(txtCategoryName.Text))
{
var objCategory = new EventCategoryInfo();
var objSecurity = new PortalSecurity();
var categoryName = "";
// Filter text for non-admins
if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName))
{
categoryName = txtCategoryName.Text;
}
else
{
categoryName =
objSecurity.InputFilter(txtCategoryName.Text, PortalSecurity.FilterFlag.NoScripting);
}
//bind text values to object
objCategory.Category = Convert.ToInt32(ViewState["Category"]);
objCategory.PortalID = PortalId;
objCategory.CategoryName = categoryName;
objCategory.Color = txtCategoryColor.Text;
objCategory.FontColor = txtCategoryFontColor.Text;
_objCtlCategory.EventsCategorySave(objCategory);
SetDefaultValues();
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
BindData();
}
protected void cmdAdd_Click(object sender, EventArgs e)
{
try
{
// Only Update if the Entered Data is Valid
if (Page.IsValid && !string.IsNullOrEmpty(txtCategoryName.Text))
{
var objCategory = new EventCategoryInfo();
var objSecurity = new PortalSecurity();
var categoryName = "";
// Filter text for non-admins
if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName))
{
categoryName = txtCategoryName.Text;
}
else
{
categoryName =
objSecurity.InputFilter(txtCategoryName.Text, PortalSecurity.FilterFlag.NoScripting);
}
//bind text values to object
objCategory.Category = 0;
objCategory.PortalID = PortalId;
objCategory.CategoryName = categoryName;
objCategory.Color = txtCategoryColor.Text;
objCategory.FontColor = txtCategoryFontColor.Text;
_objCtlCategory.EventsCategorySave(objCategory);
SetDefaultValues();
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
BindData();
}
protected void returnButton_Click(object sender, EventArgs e)
{
try
{
Response.Redirect(GetSocialNavigateUrl(), true);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#endregion
}
}