-
Notifications
You must be signed in to change notification settings - Fork 1
/
AttributeDefinitions.ascx.cs
552 lines (481 loc) · 21.5 KB
/
AttributeDefinitions.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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
//Copyright (c) 2004-2007
//by Engage Software ( http://www.engagesoftware.com )
//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.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Lists;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Utilities;
using DotNetNuke.UI.WebControls;
using Globals = DotNetNuke.Common.Globals;
using System.Data;
using Microsoft.ApplicationBlocks.Data;
using System.Text;
using DotNetNuke.Framework.Providers;
using Engage.Dnn.Locator.Data;
using System.Globalization;
namespace Engage.Dnn.Locator
{
partial class AttributeDefinitions : ModuleBase
{
#region Constants
//const int COLUMN_REQUIRED = 7;
//const int COLUMN_VISIBLE = 8;
const int COLUMN_MOVE_DOWN = 3;
const int COLUMN_MOVE_UP = 4;
#endregion
#region Private Methods
private int LocationTypeId
{
get
{
return Convert.ToInt32(lbLocType.SelectedValue, CultureInfo.InvariantCulture);
}
}
private bool IsInEdit
{
get
{
bool b = false;
if ((ViewState["editMode"] != null))
{
b = Convert.ToBoolean(ViewState["editMode"], CultureInfo.InvariantCulture);
}
return b;
}
set
{
ViewState["editMode"] = value;
}
}
private void BindData()
{
foreach (DataGridColumn column in grdLocationTypeAttributes.Columns)
{
if (object.ReferenceEquals(column.GetType(), typeof(CheckBoxColumn)))
{
if (SupportsRichClient() == false)
{
CheckBoxColumn cbColumn = (CheckBoxColumn)column;
cbColumn.CheckedChanged += grdLocationTypeAttributes_ItemCheckedChanged;
}
}
else if (object.ReferenceEquals(column.GetType(), typeof(ImageCommandColumn)))
{
//Manage Delete Confirm JS
ImageCommandColumn imageColumn = (ImageCommandColumn)column;
switch (imageColumn.CommandName)
{
case "Delete":
imageColumn.OnClickJS = Localization.GetString("DeleteItem", LocalResourceFile);
imageColumn.Text = Localization.GetString("Delete", this.LocalResourceFile);
break;
case "Edit":
//The Friendly URL parser does not like non-alphanumeric characters
//so first create the format string with a dummy value and then
//replace the dummy value with the FormatString place holder
string formatString = EditUrl("AttributeDefinitionID", "KEYFIELD", "EditAttributeDefinition", "ltid=" + LocationTypeId);
formatString = formatString.Replace("KEYFIELD", "{0}");
imageColumn.NavigateURLFormatString = formatString;
break;
case "MoveUp":
imageColumn.Text = Localization.GetString("MoveUp", this.LocalResourceFile);
break;
case "MoveDown":
imageColumn.Text = Localization.GetString("MoveDown", this.LocalResourceFile);
break;
}
}
BindGrid();
}
}
private AttributeDefinitionCollection GetAttributes()
{
return LocationType.GetAttributeDefinitionsById(LocationTypeId, false);
}
private bool SupportsRichClient()
{
return DotNetNuke.UI.Utilities.ClientAPI.BrowserSupportsFunctionality(ClientAPI.ClientFunctionality.DHTML);
}
private void DeleteAttribute(int attributeDefinitionId)
{
AttributeDefinitionCollection locationTypeAttributes = GetAttributes();
foreach (AttributeDefinition objAttribute in locationTypeAttributes)
{
if (objAttribute.AttributeDefinitionId == attributeDefinitionId)
{
LocationType.DeleteAttributeDefinition(objAttribute);
break;
}
}
BindGrid();
}
private void MoveAttribute(int index, int destIndex)
{
AttributeDefinitionCollection locationTypeAttributes = GetAttributes();
AttributeDefinition objAttribute = locationTypeAttributes[index];
AttributeDefinition objNext = locationTypeAttributes[destIndex];
int currentOrder = objAttribute.ViewOrder;
int nextOrder = objNext.ViewOrder;
//Swap ViewOrders
objAttribute.ViewOrder = nextOrder;
objNext.ViewOrder = currentOrder;
//'Refresh Grid
//locationTypeAttributes.Sort();
BindGrid();
}
private void MoveAttributeDown(int index)
{
MoveAttribute(index, index + 1);
}
private void MoveAttributeUp(int index)
{
MoveAttribute(index, index - 1);
}
private void BindTypes()
{
DataTable dt= LocationType.GetLocationTypes();
lbLocType.DataTextField = "LocationTypeName";
lbLocType.DataValueField = "LocationTypeId";
lbLocType.DataSource = dt;
lbLocType.DataBind();
if (dt.Rows.Count > 0) lbLocType.SelectedIndex = 0;
SetButtons();
}
private void SetButtons()
{
bool inUse = LocationType.GetLocationTypeInUse(LocationTypeId.ToString(CultureInfo.InvariantCulture));
if (inUse)
{
btnDeleteLocationType.Enabled = false;
btnDeleteLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/delete_disabled_bt.gif";
}
else
{
btnDeleteLocationType.Enabled = true;
btnDeleteLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/cadelete.gif";
}
if (LocationType.GetLocationTypeName(LocationTypeId) == "Default")
{
btnDeleteLocationType.Enabled = false;
btnDeleteLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/delete_disabled_bt.gif";
btnEditLocationType.Enabled = false;
btnEditLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/edit_disabled_bt.gif";
}
else if (inUse == false)
{
btnDeleteLocationType.Enabled = true;
btnDeleteLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/cadelete.gif";
btnEditLocationType.Enabled = true;
btnEditLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/caedit.gif";
}
else
{
btnEditLocationType.Enabled = true;
btnEditLocationType.ImageUrl = "~/desktopmodules/EngageLocator/images/caedit.gif";
}
}
private void BindGrid()
{
//if (Page.IsPostBack == false)
//{
AttributeDefinitionCollection attributes = GetAttributes();
grdLocationTypeAttributes.DataSource = attributes;
grdLocationTypeAttributes.DataBind();
//}
}
private void UpdateAttributes()
{
AttributeDefinitionCollection locationTypeAttributes = GetAttributes();
foreach (AttributeDefinition objAttribute in locationTypeAttributes)
{
if (objAttribute.IsDirty)
{
LocationType.UpdateAttributeDefinition(objAttribute);
}
}
}
/// -----------------------------------------------------------------------------
/// <summary>
/// This method is responsible for taking in posted information from the grid and
/// persisting it to the property definition collection
/// </summary>
/// -----------------------------------------------------------------------------
private void ProcessPostBack()
{
try
{
AttributeDefinitionCollection objAttributes = this.GetAttributes();
string[] aryNewOrder = ClientAPI.GetClientSideReorder(this.grdLocationTypeAttributes.ClientID, this.Page);
// assign vieworder
for (int i = 0; i <= aryNewOrder.Length - 1; i++)
{
objAttributes[Int32.Parse(aryNewOrder[i], CultureInfo.InvariantCulture)].ViewOrder = i;
}
objAttributes.Sort();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region Public Methods
public string DisplayDataType(AttributeDefinition definition)
{
string retValue = Null.NullString;
ListController objListController = new ListController();
ListEntryInfo definitionEntry = objListController.GetListEntryInfo(definition.DataType);
if ((definitionEntry != null))
{
retValue = definitionEntry.Value;
}
return retValue;
}
#endregion
#region Event Handlers
/// -----------------------------------------------------------------------------
/// <summary>
/// Page_Init runs when the control is initialised
/// </summary>
/// -----------------------------------------------------------------------------
private void Page_Init(object sender, System.EventArgs e)
{
Localization.LocalizeDataGrid(ref grdLocationTypeAttributes, this.LocalResourceFile);
BindTypes();
grdLocationTypeAttributes.ItemCommand += new DataGridCommandEventHandler(grdLocationTypeAttributes_ItemCommand);
lbSettings.Visible = IsEditable;
lbImportFile.Visible = IsEditable;
lbManageComments.Visible = IsEditable;
lbManageLocations.Visible = IsEditable;
hdSelect.InnerText = Localization.GetString("hdSelect", LocalResourceFile);
lgTypes.InnerText = Localization.GetString("lgTypes", LocalResourceFile);
lgCustomAttributes.InnerText = Localization.GetString("lgCustomAttributes", LocalResourceFile);
}
/// -----------------------------------------------------------------------------
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
/// -----------------------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
// Global navigation
if (UserInfo.IsSuperUser)
{
lbLocationTypes.Enabled = false;
lbLocationTypes.CssClass = "mnavDisabled";
lbLocationTypes.ImageUrl = "~/desktopmodules/EngageLocator/images/locationTypesBtDisabled.gif";
}
try
{
BindData();
ClientAPI.AddButtonConfirm(btnDeleteLocationType, Localization.GetString("confirmDelete", LocalResourceFile));
}
catch (Exception exc)
{
//Module failed to load
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void grdLocationTypeAttributes_ItemCheckedChanged(object sender, DNNDataGridCheckChangedEventArgs e)
{
string propertyName = e.Field;
bool propertyValue = e.Checked;
bool isAll = e.IsAll;
int index = e.Item.ItemIndex;
AttributeDefinitionCollection attributes = GetAttributes();
AttributeDefinition loctypeAttribute;
if (isAll)
{
//Update All the attributes
foreach (AttributeDefinition loctypeAttributeX in attributes)
{
switch (propertyName)
{
case "Required":
loctypeAttributeX.Required = propertyValue;
break;
case "Visible":
loctypeAttributeX.Visible = propertyValue;
break;
}
}
}
else
{
//Update the indexed property
loctypeAttribute = attributes[index];
switch (propertyName)
{
case "Required":
loctypeAttribute.Required = propertyValue;
break;
case "Visible":
loctypeAttribute.Visible = propertyValue;
break;
}
}
//BindGrid();
}
/// -----------------------------------------------------------------------------
/// <summary>
/// When it is determined that the client supports a rich interactivity the grdLocationTypeAttributes_ItemCreated
/// event is responsible for disabling all the unneeded AutoPostBacks, along with assiging the appropriate
/// client-side script for each event handler
/// </summary>
/// -----------------------------------------------------------------------------
protected void grdLocationTypeAttributes_ItemCreated(object sender, DataGridItemEventArgs e)
{
if (SupportsRichClient())
{
switch (e.Item.ItemType)
{
case ListItemType.Header:
//we combined the header label and checkbox in same place, so it is control 1 instead of 0
//((WebControl)e.Item.Cells[COLUMN_REQUIRED].Controls[1]).Attributes.Add("onclick", "dnn.util.checkallChecked(this," + COLUMN_REQUIRED + ");");
//((CheckBox)e.Item.Cells[COLUMN_REQUIRED].Controls[1]).AutoPostBack = false;
//((WebControl)e.Item.Cells[COLUMN_VISIBLE].Controls[1]).Attributes.Add("onclick", "dnn.util.checkallChecked(this," + COLUMN_VISIBLE + ");");
//((CheckBox)e.Item.Cells[COLUMN_VISIBLE].Controls[1]).AutoPostBack = false;
break;
case ListItemType.AlternatingItem:
case ListItemType.Item:
//((CheckBox)e.Item.Cells[COLUMN_REQUIRED].Controls[0]).AutoPostBack = false;
//((CheckBox)e.Item.Cells[COLUMN_VISIBLE].Controls[0]).AutoPostBack = false;
DotNetNuke.UI.Utilities.ClientAPI.EnableClientSideReorder(e.Item.Cells[COLUMN_MOVE_DOWN].Controls[0], this.Page, false, this.grdLocationTypeAttributes.ClientID);
DotNetNuke.UI.Utilities.ClientAPI.EnableClientSideReorder(e.Item.Cells[COLUMN_MOVE_UP].Controls[0], this.Page, true, this.grdLocationTypeAttributes.ClientID);
break;
}
}
}
protected void grdLocationTypeAttributes_ItemDataBound(object sender, DataGridItemEventArgs e)
{
DataGridItem item = e.Item;
if (item.ItemType == ListItemType.Item | item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.SelectedItem)
{
System.Web.UI.Control imgColumnControl = item.Controls[1].Controls[0];
if (imgColumnControl is ImageButton)
{
ImageButton delImage = (ImageButton)imgColumnControl;
AttributeDefinition loctypeAttribute = (AttributeDefinition)item.DataItem;
switch (loctypeAttribute.AttributeName.ToUpperInvariant())
{
case "LASTNAME":
case "FIRSTNAME":
case "TIMEZONE":
case "PREFERREDLOCALE":
delImage.Visible = false;
break;
default:
delImage.Visible = true;
break;
}
}
}
}
protected void grdLocationTypeAttributes_ItemCommand(object source, DataGridCommandEventArgs e)
{
string commandName = e.CommandName;
//int commandArgument = (int)e.CommandArgument;
int index = e.Item.ItemIndex;
switch (commandName)
{
case "Delete":
//Label l = ((Label)grdLocationTypeAttributes.Items[e.Item.ItemIndex].Cells[0].Controls[1]);
//int attributeDefinitionId = Convert.ToInt32(l.Text);
//DeleteAttribute(attributeDefinitionId);
break;
case "MoveUp":
MoveAttributeUp(index);
break;
case "MoveDown":
MoveAttributeDown(index);
break;
}
}
protected void lbLocType_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
SetButtons();
}
protected void btnCAAdd_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string href = EditUrl("ltid", LocationTypeId.ToString(CultureInfo.InvariantCulture), "EditAttributeDefinition");
Response.Redirect(href, true);
}
protected void cmdUpdate_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
ProcessPostBack();
try
{
UpdateAttributes();
LocationType.ClearCache(LocationTypeId);
BindGrid();
}
catch (Exception exc)
{
//Module failed to load
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void cmdCancel_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(TabId), true);
}
protected void btnCreateLocationType_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
lbLocType.Enabled = false;
btnCreateLocationType.Visible = false;
dvLocationType.Visible = true;
txtEditLocationType.Text = String.Empty;
txtEditLocationType.Focus();
}
protected void btnEditLocationType_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
dvLocationType.Visible = true;
txtEditLocationType.Text = LocationType.GetLocationTypeName(LocationTypeId);
txtEditLocationType.Focus();
lbLocType.Enabled = false;
IsInEdit = true;
}
protected void btnDeleteLocationType_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
DataProvider.Instance().DeleteLocationType(Convert.ToInt32(lbLocType.SelectedItem.Value, CultureInfo.InvariantCulture));
BindTypes();
BindData();
}
protected void btnUpdateLocationType_Click(object sender, EventArgs e)
{
if (IsInEdit)
{
DataProvider.Instance().UpdateLocationType(Convert.ToInt32(lbLocType.SelectedItem.Value, CultureInfo.InvariantCulture), txtEditLocationType.Text);
}
else
{
DataProvider.Instance().InsertLocationType(txtEditLocationType.Text);
}
dvLocationType.Visible = false;
BindTypes();
btnCreateLocationType.Visible = true;
lbLocType.Enabled = true;
IsInEdit = false;
}
protected void btnCancelLocationType_Click(object sender, EventArgs e)
{
btnCreateLocationType.Visible = true;
dvLocationType.Visible = false;
lbLocType.Enabled = true;
IsInEdit = false;
}
#endregion
}
}