-
Notifications
You must be signed in to change notification settings - Fork 20
/
FAQsCategories.ascx.cs
290 lines (260 loc) · 12.5 KB
/
FAQsCategories.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
//
// DotNetNuke® - http://www.dnnsoftware.com
// Copyright (c) 2002-2014
// by DNN Corp
//
// 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.Collections;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Entities.Icons;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.Security;
using Telerik.Web.UI;
namespace DotNetNuke.Modules.FAQs
{
partial class FAQsCategories : PortalModuleBase
{
#region Event Handlers
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Page.IsPostBack == false)
{
BindData();
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the Click event of the cmdAddNew 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>
protected void cmdAddNew_Click(Object sender, EventArgs e)
{
panelAddEdit.Visible = true;
txtCategoryDescription.Text = "";
txtCategoryName.Text = "";
PopulateCategoriesDropDown(-1);
treeCategories.UnselectAllNodes();
cmdDelete.Visible = false;
}
/// <summary>
/// Handles the Click event of the cmdGoBack 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>
protected void cmdGoBack_Click(Object sender, EventArgs e)
{
Response.Redirect(Globals.NavigateURL());
}
/// <summary>
/// Handles the Click event of the cmdUpdate 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>
protected void cmdUpdate_Click(Object sender, EventArgs e)
{
FAQsController faqsController = new FAQsController();
CategoryInfo categoryItem = new CategoryInfo();
PortalSecurity objSecurity = new PortalSecurity();
int parentCategoryId = Convert.ToInt32(drpParentCategory.SelectedValue);
if (parentCategoryId < 0)
parentCategoryId = 0;
// We do not allow for script or markup
categoryItem.FaqCategoryParentId = parentCategoryId;
categoryItem.FaqCategoryName = objSecurity.InputFilter(txtCategoryName.Text, PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting);
categoryItem.FaqCategoryDescription = objSecurity.InputFilter(txtCategoryDescription.Text, PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoMarkup);
categoryItem.ModuleId = ModuleId;
try
{
RadTreeNode node = treeCategories.SelectedNode;
if (node != null)
{
categoryItem.FaqCategoryId = Convert.ToInt32(node.Value);
CategoryInfo originalCategoryItem = faqsController.GetCategory(categoryItem.FaqCategoryId);
categoryItem.ViewOrder = originalCategoryItem.ViewOrder;
faqsController.UpdateCategory(categoryItem);
}
else
{
categoryItem.ViewOrder = 999;
faqsController.AddCategory(categoryItem);
}
faqsController.ReorderCategory(categoryItem.FaqCategoryParentId, ModuleId);
Response.Redirect(Request.RawUrl);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the Click event of the cmdDelete 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>
protected void cmdDelete_Click(Object sender, EventArgs e)
{
FAQsController faqsController = new FAQsController();
try
{
RadTreeNode node = treeCategories.SelectedNode;
if (node != null)
{
int faqCategoryId = Convert.ToInt32(node.Value);
faqsController.DeleteCategory(faqCategoryId);
}
Response.Redirect(Request.RawUrl);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
/// <summary>
/// Handles the Click event of the cmdCancel 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>
protected void cmdCancel_Click(System.Object sender, System.EventArgs e)
{
panelAddEdit.Visible = false;
}
/// <summary>
/// Handles the NodeDataBound event of the treeCategories control (adds Tooltip)
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">instance containing the event data.</param>
protected void treeCategories_NodeDataBound(object sender, RadTreeNodeEventArgs e)
{
e.Node.ToolTip = (string)DataBinder.Eval(e.Node.DataItem, "FaqCategoryDescription");
e.Node.Value = DataBinder.Eval(e.Node.DataItem, "FaqCategoryId").ToString();
e.Node.ImageUrl = IconController.IconURL("folder");
}
/// <summary>
/// Handles the NodeClick event of the treeCategories control
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">instance containing the event data.</param>
protected void treeCategories_NodeClick(object sender, RadTreeNodeEventArgs e)
{
int faqCategoryId = Convert.ToInt32(e.Node.Value);
EditCategory(faqCategoryId);
cmdDelete.Visible = true;
}
protected void treeCategories_HandleDrop(object sender, RadTreeNodeDragDropEventArgs e)
{
FAQsController FAQsController = new FAQsController();
RadTreeNode sourceNode = e.SourceDragNode;
RadTreeNode destNode = e.DestDragNode;
RadTreeViewDropPosition dropPosition = e.DropPosition;
if (destNode == null || sourceNode == destNode || sourceNode.IsAncestorOf(destNode))
return;
int sourceFaqCategoryId = Convert.ToInt32(sourceNode.Value);
CategoryInfo sourceCategory = FAQsController.GetCategory(sourceFaqCategoryId);
int destFaqCategoryId = Convert.ToInt32(destNode.Value);
CategoryInfo destCategory = FAQsController.GetCategory(destFaqCategoryId);
switch (dropPosition)
{
case RadTreeViewDropPosition.Over: // child
// Change Treeview
sourceNode.Owner.Nodes.Remove(sourceNode);
destNode.Nodes.Add(sourceNode);
// Change the ParentId of Source in database
sourceCategory.FaqCategoryParentId = destCategory.FaqCategoryId;
sourceCategory.ViewOrder = 999;
FAQsController.UpdateCategory(sourceCategory);
break;
case RadTreeViewDropPosition.Above: // sibling - above
sourceNode.Owner.Nodes.Remove(sourceNode);
destNode.InsertBefore(sourceNode);
sourceCategory.FaqCategoryParentId = destCategory.FaqCategoryParentId;
sourceCategory.ViewOrder = destCategory.ViewOrder - 1;
FAQsController.UpdateCategory(sourceCategory);
break;
case RadTreeViewDropPosition.Below: // sibling - below
sourceNode.Owner.Nodes.Remove(sourceNode);
destNode.InsertAfter(sourceNode);
sourceCategory.FaqCategoryParentId = destCategory.FaqCategoryParentId;
sourceCategory.ViewOrder = destCategory.ViewOrder + 1;
FAQsController.UpdateCategory(sourceCategory);
break;
}
FAQsController.ReorderCategory(sourceCategory.FaqCategoryParentId, ModuleId);
panelAddEdit.Visible = false;
}
#endregion
#region Private Methods
private void BindData()
{
FAQsController FAQsController = new FAQsController();
IEnumerable<CategoryInfo> cats = FAQsController.ListCategoriesHierarchical(ModuleId, false);
// treeCategories fails with int? FaqCategoryParentId
// define a temp class that has no nullables
// set null ints to Null.NullInt
var lst = new List<CategoryInfoTreeNode>();
foreach (CategoryInfo cat in cats)
{
lst.Add(cat.ToTreeNode());
}
treeCategories.Nodes.Clear();
treeCategories.DataTextField = "FaqCategoryName";
treeCategories.DataFieldID = "FaqCategoryId";
treeCategories.DataFieldParentID = "FaqCategoryParentId";
treeCategories.DataSource = lst;
treeCategories.DataBind();
if (!IsPostBack && treeCategories.Nodes.Count > 0)
treeCategories.Nodes[0].Selected = true;
}
private void EditCategory(int faqCategoryId)
{
FAQsController faqsController = new FAQsController();
panelAddEdit.Visible = true;
PopulateCategoriesDropDown(faqCategoryId);
CategoryInfo categoryItem = faqsController.GetCategory(faqCategoryId);
int? parentCategoryId = categoryItem.FaqCategoryParentId;
drpParentCategory.SelectedValue = (parentCategoryId == null ? "-1" : parentCategoryId.ToString());
txtCategoryName.Text = categoryItem.FaqCategoryName;
txtCategoryDescription.Text = categoryItem.FaqCategoryDescription;
}
/// <summary>
/// Populates the (Parent-)categories drop down.
/// </summary>
private void PopulateCategoriesDropDown(int faqCategoryId)
{
drpParentCategory.Items.Clear();
drpParentCategory.Items.Add(new ListItem(Localization.GetString("SelectParentCategory.Text", this.LocalResourceFile), "-1"));
FAQsController FAQsController = new FAQsController();
foreach (CategoryInfo category in FAQsController.ListCategoriesHierarchical(ModuleId, false))
{
if (faqCategoryId != category.FaqCategoryId)
drpParentCategory.Items.Add(new ListItem(new string('.', category.Level * 3) + category.FaqCategoryName, category.FaqCategoryId.ToString()));
}
}
#endregion
}
}