-
Notifications
You must be signed in to change notification settings - Fork 50
/
AnnouncementsEdit.ascx.cs
315 lines (270 loc) · 12.1 KB
/
AnnouncementsEdit.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
#region License
//
// DotNetNuke® - http://www.dotnetnuke.com
// Copyright (c) 2002-2012
// 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
#region Usings
using System;
using System.Data.SqlTypes;
using System.Globalization;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using DotNetNuke.Framework.JavaScriptLibraries;
using DotNetNuke.Modules.Announcements.Components.Business;
using DotNetNuke.Modules.Announcements.Components.Common;
using DotNetNuke.Modules.Announcements.MVP.Models;
using DotNetNuke.Modules.Announcements.MVP.Presenters;
using DotNetNuke.Modules.Announcements.MVP.Views;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Web.Client;
using DotNetNuke.Web.Client.ClientResourceManagement;
using DotNetNuke.Web.Mvp;
using DotNetNuke.Web.UI.WebControls.Internal;
using WebFormsMvp;
#endregion
namespace DotNetNuke.Modules.Announcements
{
/// <summary>
/// The EditAnnouncements PortalModuleBase is used to manage Announcements
/// </summary>
/// <remarks>
/// </remarks>
[PresenterBinding(typeof(AnnouncementsEditPresenter))]
public partial class AnnouncementsEdit : ModuleView<AnnouncementsEditModel>, IAnnouncementsEdit
{
public event EventHandler GetSettings;
public event EventHandler<EditItemEventArgs> GetItem;
public event EventHandler GetAnnouncement;
public event EventHandler<EditItemEventArgs> DeleteAnnouncement;
public event EventHandler<EditItemEventArgs> UpdateAnnouncement;
protected UI.UserControls.LabelControl plTitle;
protected DotNetNuke.Web.UI.WebControls.DnnFilePickerUploader urlImage;
protected UI.UserControls.TextEditor teDescription;
protected UI.UserControls.UrlControl ctlURL;
protected UI.UserControls.ModuleAuditControl ctlAudit;
protected UI.UserControls.URLTrackingControl ctlTracking;
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
JavaScript.RequestRegistration(CommonJs.DnnPlugins);
ClientResourceManager.RegisterStyleSheet(Page, Globals.ApplicationPath + "/DesktopModules/Announcements/AnnouncementsEdit.css", FileOrder.Css.ModuleCss);
cmdDelete.Click += CmdDeleteClick;
cmdUpdate.Click += CmdUpdateClick;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
GetSettings(this, EventArgs.Empty);
GetItem(this, new EditItemEventArgs(Request.QueryString["ItemID"]));
GetAnnouncement(this, new EditItemEventArgs(Model.ItemId));
ApplySettings();
if (Page.IsPostBack == false)
{
BindForm();
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// cmdDelete_Click runs when the delete button is clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks></remarks>
private void CmdDeleteClick(object sender, EventArgs e)
{
try
{
DeleteAnnouncement(this, new EditItemEventArgs(Model.ItemId));
Response.Redirect(ReturnURL, false);
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// cmdUpdate_Click runs when the update button is clicked
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks></remarks>
private void CmdUpdateClick(object sender, EventArgs e)
{
try
{
// verify data
if (Page.IsValid)
{
AnnouncementInfo announcement;
if (Model.IsAddMode)
{
// new item, create new announcement
announcement = new AnnouncementInfo
{
ItemID = Model.ItemId,
ModuleID = ModuleContext.ModuleId,
PortalID = ModuleContext.PortalId,
CreatedByUserID = ModuleContext.PortalSettings.UserId,
CreatedOnDate = DateTime.UtcNow
};
}
else
{
// updating existing item, load it
announcement = Model.AnnouncementInfo;
}
announcement.Title = txtTitle.Text;
announcement.ImageSource = urlImage.FilePath;
announcement.Description = teDescription.Text;
announcement.URL = ctlURL.Url;
announcement.PublishDate = GetDateTimeValue(publishDate, DateTime.UtcNow);
announcement.ExpireDate = GetDateTimeValue(expireDate);
announcement.LastModifiedByUserID = ModuleContext.PortalSettings.UserId;
announcement.LastModifiedOnDate = DateTime.UtcNow;
if (!string.IsNullOrWhiteSpace(txtViewOrder.Text))
{
announcement.ViewOrder = Convert.ToInt32(txtViewOrder.Text);
}
UpdateAnnouncement(this, new EditItemEventArgs(announcement));
// url tracking
var objUrls = new UrlController();
objUrls.UpdateUrl(ModuleContext.PortalId, ctlURL.Url, ctlURL.UrlType, ctlURL.Log, ctlURL.Track, ModuleContext.ModuleId, ctlURL.NewWindow);
// redirect back to page
Response.Redirect(ReturnURL, true);
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void BindForm()
{
if (!Model.IsAddMode)
{
if (Model.AnnouncementInfo != null)
{
txtTitle.Text = Model.AnnouncementInfo.Title;
urlImage.FilePath = Model.AnnouncementInfo.ImageSource;
teDescription.Text = Model.AnnouncementInfo.Description;
ctlURL.Url = Model.AnnouncementInfo.URL;
if (!Null.IsNull(Model.AnnouncementInfo.ViewOrder))
{
txtViewOrder.Text = Convert.ToString(Model.AnnouncementInfo.ViewOrder);
}
if ((!Null.IsNull(Model.AnnouncementInfo.PublishDate)) &&
(Model.AnnouncementInfo.PublishDate != (DateTime)SqlDateTime.Null))
{
var portalDateTime = TimeZoneInfo.ConvertTimeFromUtc(Model.AnnouncementInfo.PublishDate.Value, ModuleContext.PortalSettings.TimeZone);
publishDate.SelectedDate = portalDateTime;
}
if ((!Null.IsNull(Model.AnnouncementInfo.ExpireDate)) &&
(Model.AnnouncementInfo.ExpireDate != (DateTime)SqlDateTime.Null))
{
var portalDateTime = TimeZoneInfo.ConvertTimeFromUtc(Model.AnnouncementInfo.ExpireDate.Value, ModuleContext.PortalSettings.TimeZone);
expireDate.SelectedDate = portalDateTime;
}
var user = UserController.Instance.GetCurrentUserInfo();
var userPreferredCulture = CultureInfo.InvariantCulture;
if (user != null && !string.IsNullOrWhiteSpace(user.Profile.PreferredLocale))
{
userPreferredCulture = new CultureInfo(user.Profile.PreferredLocale);
}
ctlAudit.CreatedDate = TimeZoneInfo.ConvertTimeFromUtc(Model.AnnouncementInfo.CreatedOnDate, ModuleContext.PortalSettings.TimeZone).ToString(userPreferredCulture);
ctlAudit.CreatedByUser = Model.AnnouncementInfo.CreatedByUserID.ToString(CultureInfo.InvariantCulture);
ctlAudit.LastModifiedByUser = Model.AnnouncementInfo.LastModifiedByUserID.ToString(CultureInfo.InvariantCulture);
ctlAudit.LastModifiedDate = TimeZoneInfo.ConvertTimeFromUtc(Model.AnnouncementInfo.LastModifiedOnDate, ModuleContext.PortalSettings.TimeZone).ToString(userPreferredCulture);
ctlTracking.URL = Model.AnnouncementInfo.URL;
ctlTracking.ModuleID = ModuleContext.ModuleId;
}
}
}
private void ApplySettings()
{
teDescription.Height = Model.Settings.EditorHeight;
cancelHyperLink.NavigateUrl = ReturnURL;
urlImage.FileFilter = Globals.glbImageFileTypes;
ctlURL.ShowLog = true;
ctlURL.ShowNewWindow = true;
ctlURL.ShowTrack = true;
ctlURL.ShowUsers = true;
cmdDelete.Visible = !Model.IsAddMode;
ctlAudit.Visible = !Model.IsAddMode;
ctlTracking.Visible = !Model.IsAddMode;
}
protected string ActiveDnnTab
{
get
{
var activeTab = Request.QueryString["activeTab"];
if (!string.IsNullOrEmpty(activeTab))
{
var tabControl = FindControl(activeTab);
if (tabControl != null)
{
return tabControl.ClientID;
}
}
return string.Empty;
}
}
private string ReturnURL
{
get
{
var returnValue = UrlUtils.ValidReturnUrl(Request.Params["ReturnURL"]);
if (string.IsNullOrEmpty(returnValue))
returnValue = Globals.NavigateURL();
return returnValue;
}
}
private DateTime? GetDateTimeValue(DnnDatePicker dnnDatePicker)
{
DateTime? resultValue = null;
if (dnnDatePicker.SelectedDate != null)
{
resultValue = dnnDatePicker.SelectedDate;
}
if (resultValue.HasValue)
{
return TimeZoneInfo.ConvertTimeToUtc(resultValue.Value, ModuleContext.PortalSettings.TimeZone);
}
return null;
}
private DateTime? GetDateTimeValue(DnnDateTimePicker dnnDatePicker, DateTime defaultValue)
{
DateTime? resultValue = GetDateTimeValue(dnnDatePicker);
if (!resultValue.HasValue)
{
resultValue = defaultValue;
}
return resultValue;
}
}
}