-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathEventEdit.ascx.cs
506 lines (452 loc) · 22.9 KB
/
EventEdit.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
// <copyright file="EventEdit.ascx.cs" company="Engage Software">
// Engage: Events
// 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.Events
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Web.UI.WebControls;
using DotNetNuke.Framework;
using DotNetNuke.Services.Exceptions;
using Engage.Events;
using Engage.Util;
using Telerik.Web.UI;
using Globals = DotNetNuke.Common.Globals;
/// <summary>
/// This class contains a collection of methods for adding or editing an Event.
/// </summary>
public partial class EventEdit : ModuleBase
{
/// <summary>
/// Gets the URL to navigate to in order to add a new event.
/// </summary>
/// <value>The URL to navigate to in order to add a new event</value>
private string AddEventUrl
{
get { return this.BuildLinkUrl(this.ModuleId, "EventEdit"); }
}
/// <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)
{
if (!this.PermissionsService.CanManageEvents)
{
this.DenyAccess();
return;
}
base.OnInit(e);
AJAX.RegisterPostBackControl(this.SaveEventButton);
AJAX.RegisterPostBackControl(this.SaveAndCreateNewEventButton);
this.Load += this.Page_Load;
this.SaveEventButton.Click += this.SaveEventButton_Click;
this.SaveAndCreateNewEventButton.Click += this.SaveAndCreateNewEventButton_Click;
this.CancelButton.Click += this.CancelButtonClick;
this.CancelGoHomeButton.Click += this.CancelGoHomeButton_Click;
this.DeleteAction.Delete += this.DeleteAction_Delete;
this.CreateAnotherEventLink.Click += this.CreateAnotherEventLink_Click;
this.RecurringCheckBox.CheckedChanged += this.RecurringCheckbox_CheckedChanged;
this.AllowRegistrationsCheckBox.CheckedChanged += this.AllowRegistrationsCheckBox_CheckedChanged;
this.LimitRegistrationsCheckBox.CheckedChanged += this.LimitRegistrationsCheckBox_CheckedChanged;
this.CapacityMetMessageRadioButtonList.SelectedIndexChanged += this.CapacityMetMessageRadioButtonList_SelectedIndexChanged;
this.RecurrenceEditorValidator.ServerValidate += this.RecurrenceEditorValidator_ServerValidate;
this.UniqueCategoryNameValidator.ServerValidate += this.UniqueCategoryNameValidator_ServerValidate;
}
/// <summary>
/// Handles the CheckedChanged event of the AllowRegistrationsCheckBox 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 AllowRegistrationsCheckBox_CheckedChanged(object sender, EventArgs e)
{
this.LimitRegistrationsPanel.Visible = this.AllowRegistrationsCheckBox.Checked;
}
/// <summary>
/// Handles the CheckedChanged event of the LimitRegistrationsCheckBox 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 LimitRegistrationsCheckBox_CheckedChanged(object sender, EventArgs e)
{
this.RegistrationLimitPanel.Visible = this.LimitRegistrationsCheckBox.Checked;
}
/// <summary>
/// Handles the SelectedIndexChanged event of the CapacityMetMessageRadioButtonList 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 CapacityMetMessageRadioButtonList_SelectedIndexChanged(object sender, EventArgs e)
{
this.CustomCapacityMetMessagePanel.Visible = bool.Parse(this.CapacityMetMessageRadioButtonList.SelectedValue);
}
/// <summary>
/// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
private void Page_Load(object sender, EventArgs e)
{
try
{
if (!this.IsPostBack)
{
this.FillLists();
this.DeleteAction.Visible = this.EventId.HasValue;
this.AllowRegistrationsCheckBox.Checked = ModuleSettings.AllowRegistrationsByDefault.GetValueAsBooleanFor(this).Value;
this.ValidationSummary.HeaderText = this.Localize("ValidationSummary.Header");
if (this.EventId.HasValue)
{
this.BindData();
}
}
this.SuccessModuleMessage.Visible = false;
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the OnClick event of the SaveEventButton 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 SaveEventButton_Click(object sender, EventArgs e)
{
try
{
if (this.Page.IsValid)
{
this.Save();
this.DisplayFinalSuccess();
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the <see cref="Button.Click"/> event of the <see cref="SaveAndCreateNewEventButton"/> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void SaveAndCreateNewEventButton_Click(object sender, EventArgs e)
{
try
{
if (this.Page.IsValid)
{
this.Save();
this.Response.Redirect(this.AddEventUrl, true);
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the <see cref="Button.Click"/> event of the <see cref="CancelButton"/> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void CancelButtonClick(object sender, EventArgs e)
{
this.Response.Redirect(Globals.NavigateURL());
}
/// <summary>
/// Handles the <see cref="Button.Click"/> event of the <see cref="CancelGoHomeButton"/> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void CancelGoHomeButton_Click(object sender, EventArgs e)
{
this.Response.Redirect(Globals.NavigateURL());
}
/// <summary>
/// Handles the <see cref="Events.DeleteAction.Delete"/> event of the <see cref="DeleteAction"/> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void DeleteAction_Delete(object sender, EventArgs e)
{
this.Response.Redirect(Globals.NavigateURL());
}
/// <summary>
/// Handles the <see cref="Button.Click"/> event of the <see cref="CreateAnotherEventLink"/> control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void CreateAnotherEventLink_Click(object sender, EventArgs e)
{
this.Response.Redirect(this.AddEventUrl, true);
}
/// <summary>
/// Handles the ServerValidate event of the RecurrenceEditorValidator control.
/// </summary>
/// <param name="source">The source of the event.</param>
/// <param name="args">The <see cref="System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param>
private void RecurrenceEditorValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = this.RecurrenceEditor.IsValid;
}
/// <summary>
/// Handles the CheckedChanged event of the RecurringCheckBox 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 RecurringCheckbox_CheckedChanged(object sender, EventArgs e)
{
this.RecurrenceEditor.Visible = this.RecurringCheckBox.Checked;
}
/// <summary>
/// Handles the <see cref="CustomValidator.ServerValidate"/> event of the <see cref="UniqueCategoryNameValidator"/> control.
/// </summary>
/// <param name="source">The source of the event.</param>
/// <param name="args">The <see cref="ServerValidateEventArgs"/> instance containing the event data.</param>
private void UniqueCategoryNameValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
// they picked an existing category, or the new category name doesn't exist in the list of this portal's categories
args.IsValid = this.CategoryComboBox.SelectedItem != null ||
!CategoryCollection.Load(this.PortalId).Any(category => category.Name.Equals(args.Value, StringComparison.CurrentCultureIgnoreCase));
}
/// <summary>
/// Gets the custom capacity met message entered for this event.
/// </summary>
/// <returns>The capacity met message to use for this event, or <c>null</c> if the default message is to be used</returns>
private string GetCustomCapacityMetMessage()
{
return this.CapacityMetMessageRadioButtonList.Visible && bool.Parse(this.CapacityMetMessageRadioButtonList.SelectedValue) ? this.CustomCapacityMetMessageTextEditor.Text : null;
}
/// <summary>
/// Gets the ID of the selected category (create a new category if no existing category was selected).
/// </summary>
/// <returns>The ID of the category</returns>
private int GetSelectedCategoryId()
{
int categoryId;
if (int.TryParse(this.CategoryComboBox.SelectedValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out categoryId))
{
return categoryId;
}
var category = Category.Create(this.PortalId, null, this.CategoryComboBox.Text, null);
category.Save(this.UserId);
// if this is a new category and the categories are restricted in the settings, make sure that this category can show up in this module
if (this.CategoryIds.Any())
{
ModuleSettings.Categories.Set(this, ModuleSettings.Categories.GetValueAsStringFor(this) + "," + category.Id.ToString(CultureInfo.InvariantCulture));
}
return category.Id;
}
/// <summary>
/// Gets the capacity for this event.
/// </summary>
/// <returns>This event's capacity</returns>
private int? GetEventCapacity()
{
return this.LimitRegistrationsCheckBox.Checked && this.LimitRegistrationsCheckBox.Visible ? (int?)this.RegistrationLimitTextBox.Value : null;
}
/// <summary>
/// Convert to the hierarchical categories.
/// </summary>
/// <param name="hierarchicalList">The hierarchical list.</param>
/// <param name="categories">The categories.</param>
/// <param name="parentCategory">The parent category.</param>
/// <param name="level">The level.</param>
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Telerik.Web.UI.RadComboBoxItem.#ctor(System.String,System.String)", Justification = "Don't need to localize space")]
private void ToIndentedList(List<RadComboBoxItem> hierarchicalList, List<Category> categories, Category parentCategory, int level)
{
foreach (var category in categories.Where(c => parentCategory == null ? c.ParentId == null : c.ParentId == parentCategory.Id))
{
var listItemText = string.IsNullOrEmpty(category.Name)
? this.Localize("DefaultCategory.Text", this.LocalSharedResourceFile)
: level > 0 ? " " + category.Name : category.Name;
var listItemValue = category.Id.ToString(CultureInfo.InvariantCulture);
RadComboBoxItem listItem = null;
try
{
listItem = new RadComboBoxItem(listItemText, listItemValue);
if (level > 0)
{
var pad = string.IsNullOrEmpty(this.Localize("Indent.Text")) ? '>' : this.Localize("Indent.Text")[0];
listItem.Text = listItem.Text.PadLeft(listItem.Text.Length + level, pad);
}
hierarchicalList.Add(listItem);
}
catch
{
if (listItem != null)
{
listItem.Dispose();
}
throw;
}
var categoryId = category.Id;
if (categories.ToList().Any(c => c.ParentId == categoryId))
{
this.ToIndentedList(hierarchicalList, categories, category, level + 1);
}
}
}
/// <summary>
/// Fills the <see cref="TimeZoneDropDownList"/> and <see cref="CategoryComboBox"/>.
/// </summary>
private void FillLists()
{
this.TimeZoneDropDownList.DataSource = TimeZoneInfo.GetSystemTimeZones();
this.TimeZoneDropDownList.DataTextField = "DisplayName";
this.TimeZoneDropDownList.DataValueField = "Id";
this.TimeZoneDropDownList.DataBind();
this.TimeZoneDropDownList.SetSelectedString(Dnn.Utility.GetUserTimeZone(this.UserInfo, this.PortalSettings).Id);
var categories = (from category in CategoryCollection.Load(this.PortalId)
where !this.CategoryIds.Any() || this.CategoryIds.Contains(category.Id)
select category).ToList();
var indentedList = new List<RadComboBoxItem>();
this.ToIndentedList(indentedList, categories, null, 0);
this.CategoryComboBox.AllowCustomText = this.PermissionsService.CanManageCategories;
this.CategoryComboBox.DataTextField = "Text";
this.CategoryComboBox.DataValueField = "Value";
this.CategoryComboBox.DataSource = indentedList;
this.CategoryComboBox.DataBind();
// don't show the categories if there's only one option
this.CategoryPanel.Visible = this.CategoryComboBox.AllowCustomText || categories.Count() > 1;
}
/// <summary>
/// Displays the final success.
/// </summary>
private void DisplayFinalSuccess()
{
this.SuccessModuleMessage.TextResourceKey = this.EventId.HasValue ? "EditEventSuccess" : "AddEventSuccess";
this.SuccessModuleMessage.Visible = true;
this.EventEditForm.Visible = false;
this.FooterMultiview.SetActiveView(this.FinalFooterView);
}
/// <summary>
/// This method will either update or create an event based on the current context of EventId
/// </summary>
private void Save()
{
if (this.EventId.HasValue)
{
this.Update();
}
else
{
this.Insert();
}
}
/// <summary>
/// This method is responsible for updating an event which already exists in the data store.
/// </summary>
private void Update()
{
int? eventId = this.EventId;
if (!eventId.HasValue)
{
return;
}
Event e = Event.Load(eventId.Value);
if (!this.CanShowEvent(e))
{
return;
}
e.EventStart = this.StartDateTimePicker.SelectedDate.Value;
e.EventEnd = this.EndDateTimePicker.SelectedDate.Value;
e.TimeZoneId = this.TimeZoneDropDownList.SelectedValue;
e.Location = this.EventLocationTextBox.Text;
e.Title = this.EventTitleTextBox.Text;
e.Overview = this.EventOverviewTextEditor.Text;
e.Description = this.EventDescriptionTextEditor.Text;
e.IsFeatured = this.FeaturedCheckBox.Checked;
e.AllowRegistrations = this.AllowRegistrationsCheckBox.Checked;
e.Capacity = this.GetEventCapacity();
e.RecurrenceRule = this.RecurrenceEditor.GetRecurrenceRule(e.EventStart, e.EventEnd);
e.CapacityMetMessage = this.GetCustomCapacityMetMessage();
e.CategoryId = this.GetSelectedCategoryId();
e.Save(this.UserId);
}
/// <summary>
/// Based on the values entered by the user for the event, this method will populate an event object and call the Event object's save method.
/// </summary>
private void Insert()
{
DateTime eventStart = this.StartDateTimePicker.SelectedDate.Value;
DateTime eventEnd = this.EndDateTimePicker.SelectedDate.Value;
Event e = Event.Create(
this.PortalId,
this.ModuleId,
this.UserInfo.Email,
this.EventTitleTextBox.Text,
this.EventOverviewTextEditor.Text,
this.EventDescriptionTextEditor.Text,
eventStart,
eventEnd,
this.TimeZoneDropDownList.SelectedValue,
this.EventLocationTextBox.Text,
this.FeaturedCheckBox.Checked,
this.AllowRegistrationsCheckBox.Checked,
this.RecurrenceEditor.GetRecurrenceRule(eventStart, eventEnd),
this.LimitRegistrationsCheckBox.Checked && this.LimitRegistrationsCheckBox.Visible ? (int?)this.RegistrationLimitTextBox.Value : null,
this.GetCustomCapacityMetMessage(),
this.GetSelectedCategoryId());
e.Save(this.UserId);
}
/// <summary>
/// Based on an EventId, this method populates the <see cref="EventEdit"/> user control with the Event's details.
/// </summary>
private void BindData()
{
int? eventId = this.EventId;
if (!eventId.HasValue)
{
return;
}
Event e = Event.Load(eventId.Value);
if (!this.CanShowEvent(e))
{
return;
}
this.EventTitleTextBox.Text = e.Title;
this.CategoryComboBox.SelectedValue = e.CategoryId.ToString(CultureInfo.InvariantCulture);
this.EventLocationTextBox.Text = e.Location;
this.EventOverviewTextEditor.Text = e.Overview;
this.EventDescriptionTextEditor.Text = e.Description;
this.StartDateTimePicker.SelectedDate = e.EventStart;
this.EndDateTimePicker.SelectedDate = e.EventEnd;
this.FeaturedCheckBox.Checked = e.IsFeatured;
this.RecurringCheckBox.Checked = e.IsRecurring;
this.RecurrenceEditor.Visible = this.RecurringCheckBox.Checked;
this.RecurrenceEditor.SetRecurrenceRule(e.RecurrenceRule);
this.DeleteAction.CurrentEvent = e;
this.AllowRegistrationsCheckBox.Checked = this.LimitRegistrationsPanel.Visible = e.AllowRegistrations;
this.LimitRegistrationsCheckBox.Checked = this.RegistrationLimitPanel.Visible = e.Capacity.HasValue;
this.RegistrationLimitValidator.ValueToCompare = e.AttendeeCount.ToString(CultureInfo.CurrentCulture);
if (e.Capacity.HasValue)
{
this.RegistrationLimitTextBox.Value = e.Capacity.Value;
}
this.RegistrationCountLabel.Visible = true;
this.RegistrationCountLabel.Text = string.Format(
CultureInfo.CurrentCulture,
this.Localize(e.AttendeeCount == 1 ? "Attendee Count (Singular).Format" : "Attendee Count.Format"),
e.AttendeeCount);
var hasCustomCapacityMetMessage = e.CapacityMetMessage != null;
this.CustomCapacityMetMessagePanel.Visible = hasCustomCapacityMetMessage;
this.CapacityMetMessageRadioButtonList.SetSelectedBoolean(hasCustomCapacityMetMessage);
this.CustomCapacityMetMessageTextEditor.Text = e.CapacityMetMessage;
this.TimeZoneDropDownList.SetSelectedString(e.TimeZoneId);
}
}
}