forked from DNN-Connect/DNNQA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question.ascx.cs
535 lines (451 loc) · 17.3 KB
/
Question.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
//
// 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.
//
using System;
using System.Linq;
using System.Web.UI.HtmlControls;
using DotNetNuke.DNNQA.Components.Views;
using DotNetNuke.DNNQA.Controls;
using DotNetNuke.Framework;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.Web.Client.ClientResourceManagement;
using DotNetNuke.Web.Mvp;
using DotNetNuke.Web.UI.WebControls;
using WebFormsMvp;
using System.Web.UI.WebControls;
using DotNetNuke.DNNQA.Components.Models;
using DotNetNuke.DNNQA.Components.Common;
using DotNetNuke.DNNQA.Components.Presenters;
using DotNetNuke.DNNQA.Components.Entities;
namespace DotNetNuke.DNNQA
{
/// <summary>
/// This is the question detail view. It displays the original question and then a collection of answers (can be paged). It also provides an area for the user to provide an answer to the question as well as provides the user interface for post 'moderation' type tasks to be performed.
/// </summary>
[PresenterBinding(typeof(QuestionPresenter))]
public partial class Question : ModuleView<QuestionModel>, IQuestionView
{
#region Members
// ReSharper disable InconsistentNaming
protected UI.UserControls.TextEditor teContent;
// ReSharper restore InconsistentNaming
/// <summary>
///
/// </summary>
public int LastAnswerPostId
{
get
{
if (Model.ColAnswers.Count > 0)
{
return (from p in Model.ColAnswers
orderby p.CreatedDate descending
select p).FirstOrDefault().PostId;
}
return 0;
}
}
#endregion
#region Public Events
public event EventHandler<QuestionEventArgs<Literal, Voting, Literal, DnnBinaryImage, Literal, DnnBinaryImage, Literal, Controls.Tags, HtmlGenericControl, Literal, Literal, Literal, Literal, Literal, Comments, Literal, Literal>> QuestionDataBound;
public event EventHandler<AddAnswerEventArgs<PostInfo>> Save;
public event EventHandler Subscribe;
public event EventHandler<FlagPostEventArgs<ModerationLogInfo>> FlagPost;
public event EventHandler<DeletePostEventArgs<ModerationLogInfo>> DeletePost;
public event EventHandler<AcceptAnswerEventArgs<int, int, int>> AcceptAnswer;
public event EventHandler<AnswersEventArgs<Literal, PostInfo, Literal, Voting, Image, HtmlGenericControl, Literal, Literal, LinkButton, Literal, DnnBinaryImage, Comments, Literal, DnnBinaryImage>> ItemDataBound;
public event EventHandler<PagerChangedEventArgs<LinkButton, string>> PagerChanged;
#endregion
#region Constructor
public Question()
{
AutoDataBind = false;
}
#endregion
#region Event Handlers
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Utils.SetQuestionPageMeta((CDefault)Page, Model.Question, ModuleContext);
//ClientResourceManager.RegisterScript(Page, "http://s7.addthis.com/js/250/addthis_widget.js#domready"); //pubid=
if (Model.EnableLinkedIn)
{
ClientResourceManager.RegisterScript(Page, "https://platform.linkedin.com/in.js");
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdSaveClick(object sender, EventArgs e)
{
var content = teContent.Text.Trim();
// TODO: integrate module setting here for min char count.
if (content.Length > 2)
{
Model.NewPost = new PostInfo { Body = teContent.Text };
Save(this, new AddAnswerEventArgs<PostInfo>(Model.NewPost));
}
else
{
UI.Skins.Skin.AddModuleMessage(this, "Invalid body", ModuleMessage.ModuleMessageType.RedError);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdSubscribeClick(object sender, EventArgs e)
{
Subscribe(sender, e);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdAcceptClick(object sender, EventArgs e)
{
var button = (LinkButton) sender;
var postId = Convert.ToInt32(button.CommandArgument);
AcceptAnswer(this, new AcceptAnswerEventArgs<int, int, int>(postId, ModuleContext.PortalSettings.UserId, Model.Question.PostId));
//// force rebind
//rptAnswers.DataSource = Model.ColAnswers;
//rptAnswers.DataBind();
//cmdMore.CommandArgument = "1";
//cmdBack.CommandArgument = "0";
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdFlagQuestionClick(object sender, EventArgs e)
{
// verify the user can still flag a question (operation threshold, what they have done today, etc.)
var objModeration = new ModerationLogInfo
{
ModLogTypeId = Convert.ToInt32(rblstFlagQuestion.SelectedValue),
PostId = Model.Question.PostId
};
if (objModeration.ModLogTypeId == (int)Constants.ModerationLogType.FlagOther)
{
objModeration.Notes = txtFlagQuestionOther.Text;
}
FlagPost(this, new FlagPostEventArgs<ModerationLogInfo>(objModeration));
Response.Redirect(Links.ViewQuestion(Model.Question.PostId, Model.Question.Title, ModuleContext.PortalSettings.ActiveTab, ModuleContext.PortalSettings), true);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdDeleteQuestionClick(object sender, EventArgs e)
{
// verify the user can still flag a question (operation threshold, what they have done today, etc.)
var objModeration = new ModerationLogInfo
{
ModLogTypeId = Convert.ToInt32(rblstDeleteQuestion.SelectedValue),
PostId = Model.Question.PostId
};
if (objModeration.ModLogTypeId == (int)Constants.ModerationLogType.DeleteOther)
{
objModeration.Notes = txtDeleteQuestionOther.Text;
}
DeletePost(this, new DeletePostEventArgs<ModerationLogInfo>(objModeration));
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdFlagAnswerClick(object sender, EventArgs e)
{
// verify the user can still flag a question (operation threshold, what they have done today, etc.)
if (tempId.Text.Trim() != string.Empty)
{
var objModeration = new ModerationLogInfo
{
ModLogTypeId = Convert.ToInt32(rblstAnswerFlag.SelectedValue),
PostId = Convert.ToInt32(tempId.Text)
};
if (objModeration.ModLogTypeId == (int)Constants.ModerationLogType.FlagOther)
{
objModeration.Notes = txtFlagQuestionOther.Text;
}
FlagPost(this, new FlagPostEventArgs<ModerationLogInfo>(objModeration));
rptAnswers.DataSource = Model.ColAnswers;
rptAnswers.DataBind();
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdUndoFlagClick(object sender, EventArgs e)
{
if (tempId.Text.Trim() != string.Empty)
{
var objModeration = new ModerationLogInfo
{
ModLogTypeId = (int) Constants.ModerationLogType.RemoveFlag,
PostId = Convert.ToInt32(tempId.Text)
};
FlagPost(this, new FlagPostEventArgs<ModerationLogInfo>(objModeration));
if (Model.Question.PostId == objModeration.PostId)
{
// undoing a flagged question
Response.Redirect(Links.ViewQuestion(Model.Question.PostId, Model.Question.Title, ModuleContext.PortalSettings.ActiveTab, ModuleContext.PortalSettings), true);
}
else
{
// undoing a flagged answer
rptAnswers.DataSource = Model.ColAnswers;
rptAnswers.DataBind();
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdDeleteAnswerClick(object sender, EventArgs e)
{
// verify the user can still flag a question (operation threshold, what they have done today, etc.)
if (tempId.Text.Trim() != string.Empty)
{
var objModeration = new ModerationLogInfo
{
ModLogTypeId = Convert.ToInt32(rblstAnswerDelete.SelectedValue),
PostId = Convert.ToInt32(tempId.Text)
};
if (objModeration.ModLogTypeId == (int)Constants.ModerationLogType.DeleteOther)
{
objModeration.Notes = txtDeleteQuestionOther.Text;
}
DeletePost(this, new DeletePostEventArgs<ModerationLogInfo>(objModeration));
}
}
/// <summary>
/// Handles formatting of individual items
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void RptAnswersItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var body = (Literal)e.Item.FindControl("litBody");
var question = (PostInfo)e.Item.DataItem;
var date = (Literal)e.Item.FindControl("litDate");
var answervoting = (Voting)e.Item.FindControl("dqaAnswerVote");
var imgAccepted = (Image) e.Item.FindControl("imgAccepted");
var ulAnswersMenu = (HtmlGenericControl)e.Item.FindControl("ulAnswersMenu");
var litEditAnswer = (Literal)e.Item.FindControl("litEditAnswer");
var litFlagAnswer = (Literal)e.Item.FindControl("litFlagAnswer");
var cmdAccept = (LinkButton)e.Item.FindControl("cmdAccept");
var litDeleteAnswer = (Literal)e.Item.FindControl("litDeleteAnswer");
var dbiAUser = (DnnBinaryImage) e.Item.FindControl("dbiAUser");
var edited = (Literal)e.Item.FindControl("litAEdited");
var dbiAEditUser = (DnnBinaryImage)e.Item.FindControl("dbiAEditUser");
var qaAnswerComment = (Comments)e.Item.FindControl("qaAnswerComment");
ItemDataBound(this, new AnswersEventArgs<Literal, PostInfo, Literal, Voting, Image, HtmlGenericControl, Literal, Literal, LinkButton, Literal, DnnBinaryImage, Comments, Literal, DnnBinaryImage>(body, question, date, answervoting, imgAccepted, ulAnswersMenu, litEditAnswer, litFlagAnswer, cmdAccept, litDeleteAnswer, dbiAUser, qaAnswerComment, edited, dbiAEditUser));
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void CmdPagingClick(object sender, EventArgs e)
{
var linkButton = (LinkButton)sender;
PagerChanged(sender, new PagerChangedEventArgs<LinkButton, string>(linkButton, ""));
rptAnswers.DataSource = Model.ColAnswers;
rptAnswers.DataBind();
cmdMore.CommandArgument = (Model.CurrentPage + 1).ToString();
cmdBack.CommandArgument = (Model.CurrentPage - 1).ToString();
}
#endregion
#region Public Methods
/// <summary>
///
/// </summary>
public void Refresh()
{
dgqHeaderNav.ModContext = ModuleContext;
hlLogin.NavigateUrl = Model.LoginUrl;
BindListItems();
QuestionDataBound(this, new QuestionEventArgs<Literal, Voting, Literal, DnnBinaryImage, Literal, DnnBinaryImage, Literal, Controls.Tags, HtmlGenericControl, Literal, Literal, Literal, Literal, Literal, Comments, Literal, Literal>(litTitle, dqaQuestionVote, litBody, dbiUser, litAsked, dbiEditUser, litEdited, dqaTag, questionMenu, litEditQuestion, litFlagQuestion, litCloseQuestion, litProtect, litDeleteQuestion, qaQuestionComment, litAnswerCount, litSocialSharing));
//var obj = Model.Privileges.Single(s => s.Key == Constants.Privileges.Flag.ToString());
// tie to user
litQInform.Text = @"<span>" + 10 + @"</span> " + Localization.GetString("RemainingFlags", LocalResourceFile);
litAInform.Text = @"<span>" + 10 + @"</span> " + Localization.GetString("RemainingFlags", LocalResourceFile);
rptAnswers.DataSource = Model.ColAnswers;
rptAnswers.DataBind();
divLogin.Visible = ModuleContext.PortalSettings.UserId < 1;
switch (Model.SortBy.ToLower())
{
case "oldest":
hlOldest.CssClass = "qaSortSel";
break;
case "active":
hlActive.CssClass = "qaSortSel";
break;
//case "votes":
// hlVotes.CssClass = "qaSortSel";
// break;
default: // votes
hlVotes.CssClass = "qaSortSel";
break;
}
hlOldest.NavigateUrl = Links.ViewQuestionSorted(ModuleContext, Model.Question.PostId, "oldest");
hlActive.NavigateUrl = Links.ViewQuestionSorted(ModuleContext, Model.Question.PostId, "active");
hlVotes.NavigateUrl = Links.ViewQuestion(Model.Question.PostId, Model.Question.Title, ModuleContext.PortalSettings.ActiveTab, ModuleContext.PortalSettings);
if (Page.IsPostBack) return;
cmdMore.CommandArgument = "1";
cmdBack.CommandArgument = "0";
}
/// <summary>
///
/// </summary>
/// <param name="enabled"></param>
public void SaveEnabled(bool enabled)
{
if (!enabled)
{
//if (Model.Question.CreatedUserId == ModuleContext.PortalSettings.UserId)
//{
// UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("AnswerOwnQuestion", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
//}
//else
//{
UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("NoRemoveNewUser", LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning);
//}
cmdSave.Enabled = false;
}
}
/// <summary>
/// Determines the mode the 'subscribe' button will be setup for (this is based on the user being subscribed to the question)
/// </summary>
/// <param name="subscribed"></param>
public void SubscribeButtonMode(bool subscribed)
{
if (subscribed)
{
cmdSubscribe.Text = Localization.GetString("cmdUnsubscribe", LocalResourceFile);
cmdSubscribe.CommandName = "unsubscribe";
}
else
{
cmdSubscribe.Text = Localization.GetString("cmdSubscribe", LocalResourceFile);
cmdSubscribe.CommandName = "subscribe";
}
}
/// <summary>
///
/// </summary>
/// <param name="show"></param>
public void ShowAnswerArea(bool show)
{
divAddAnswer.Visible = ModuleContext.PortalSettings.UserId > 0;
}
/// <summary>
///
/// </summary>
/// <param name="show"></param>
public void ShowBackButton(bool show)
{
cmdBack.Visible = show;
}
/// <summary>
///
/// </summary>
/// <param name="show"></param>
public void ShowNextButton(bool show)
{
cmdMore.Visible = show;
}
#endregion
#region Private Methods
/// <summary>
/// This localizes text that is bound to radio button lists.
/// </summary>
private void BindListItems()
{
rblstFlagQuestion.Items.Clear();
rblstDeleteQuestion.Items.Clear();
rblstAnswerFlag.Items.Clear();
rblstAnswerDelete.Items.Clear();
var liLow = new ListItem
{
Text = Localization.GetString("LowQuality", LocalResourceFile),
Value = ((int)Constants.ModerationLogType.FlagLowQuality).ToString()
};
rblstFlagQuestion.Items.Insert(0, liLow);
rblstAnswerFlag.Items.Insert(0, liLow);
liLow.Value = ((int) Constants.ModerationLogType.DeleteLowQuality).ToString();
rblstDeleteQuestion.Items.Insert(0, liLow);
rblstAnswerDelete.Items.Insert(0, liLow);
var liSpam = new ListItem
{
Text = Localization.GetString("Spam", LocalResourceFile),
Value = ((int)Constants.ModerationLogType.FlagSpam).ToString()
};
rblstFlagQuestion.Items.Insert(1, liSpam);
rblstAnswerFlag.Items.Insert(1, liSpam);
liSpam.Value = ((int)Constants.ModerationLogType.FlagOutOfContext).ToString();
rblstDeleteQuestion.Items.Insert(1, liSpam);
rblstAnswerDelete.Items.Insert(1, liSpam);
var liBelong = new ListItem
{
Text = Localization.GetString("DoesntBelong", LocalResourceFile),
Value = ((int)Constants.ModerationLogType.DeleteOutOfContext).ToString()
};
rblstFlagQuestion.Items.Insert(2, liBelong);
rblstAnswerFlag.Items.Insert(2, liBelong);
liBelong.Value = ((int)Constants.ModerationLogType.DeleteSpam).ToString();
rblstDeleteQuestion.Items.Insert(2, liBelong);
rblstAnswerDelete.Items.Insert(2, liBelong);
var liOther = new ListItem
{
Text = Localization.GetString("Other", LocalResourceFile),
Value = ((int)Constants.ModerationLogType.FlagOther).ToString()
};
rblstFlagQuestion.Items.Insert(3, liOther);
rblstAnswerFlag.Items.Insert(3, liOther);
liOther.Value = ((int)Constants.ModerationLogType.DeleteOther).ToString();
rblstDeleteQuestion.Items.Insert(3, liOther);
rblstAnswerDelete.Items.Insert(3, liOther);
rblstFlagQuestion.SelectedIndex = 0;
rblstAnswerFlag.SelectedIndex = 0;
rblstDeleteQuestion.SelectedIndex = 0;
rblstAnswerDelete.SelectedIndex = 0;
}
#endregion
}
}