-
Notifications
You must be signed in to change notification settings - Fork 1
/
Details.ascx.cs
165 lines (146 loc) · 7.02 KB
/
Details.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
// <copyright file="Details.ascx.cs" company="Engage Software">
// Engage: Locator - http://www.engagemodules.com
// Copyright (c) 2004-2008
// 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.Locator
{
using System;
using System.Globalization;
using AjaxControlToolkit;
using Data;
using DotNetNuke.Common;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using Rating = UserFeedback.Rating;
/// <summary>
/// A control which displays details about a particular location
/// </summary>
public partial class Details : ModuleBase
{
/// <summary>
/// Gets a value indicating whether this module instance is set to display the location details field.
/// </summary>
/// <value><c>true</c> if this module instance is set to display the location details field; otherwise, <c>false</c>.</value>
protected bool ShowLocationDetails
{
get
{
object setting = new ModuleController().GetTabModuleSettings(this.TabModuleId)["ShowLocationDetails"];
return setting != null && setting.ToString() == "DetailsPage";
}
}
/// <summary>
/// Gets the ID of the location being displayed.
/// </summary>
/// <value>The location ID.</value>
private int LocationId
{
get { return Convert.ToInt32(this.Request.QueryString["lid"], CultureInfo.InvariantCulture); }
}
/// <summary>
/// Raises the <see cref="ModuleBase.Init"/> event.
/// </summary>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += this.Page_Load;
this.BackButton.Click += this.BackButton_Click;
this.SubmitButton.Click += this.SubmitButton_Click;
this.RatingControl.Changed += this.RatingControl_Changed;
string commentSubmittedLocalizationKey = this.CommentModerationEnabled ? "lblCommentSubmittedModerated" : "lblCommentSubmitted";
this.CommentSubmittedLabel.Text = Localization.GetString(commentSubmittedLocalizationKey, this.LocalResourceFile);
}
/// <summary>
/// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindData();
}
this.lbSettings.Visible
= this.lbImportFile.Visible
= this.lbManageLocations.Visible
= this.lbLocationTypes.Visible
= this.lbManageComments.Visible
= this.IsEditable;
this.ShowCommentEntryButton.Visible = this.AddCommentSection.Visible = this.CommentsEnabled;
this.RatingUpdatePanel.Visible = this.RatingsEnabled;
}
/// <summary>
/// Handles the Click event of the BackButton 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 BackButton_Click(object sender, EventArgs e)
{
this.Response.Redirect(Globals.NavigateURL(this.TabId));
}
/// <summary>
/// Handles the Click event of the SubmitButton 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 SubmitButton_Click(object sender, EventArgs e)
{
if (!this.Page.IsValid)
{
return;
}
bool commentApproved = !this.CommentModerationEnabled;
Location.InsertComment(this.LocationId, this.CommentTextBox.Text, this.SubmittedByTextBox.Text, commentApproved);
this.CommentTextBox.Text = this.SubmittedByTextBox.Text = string.Empty;
Location location = Location.GetLocation(this.LocationId);
this.CommentsRepeater.DataSource = location.GetComments(true);
this.CommentsRepeater.DataBind();
this.CommentSubmittedLabel.Visible = true;
}
/// <summary>
/// Handles the Changed event of the RatingControl control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="AjaxControlToolkit.RatingEventArgs"/> instance containing the event data.</param>
private void RatingControl_Changed(object sender, RatingEventArgs e)
{
Rating.AddRating(
this.LocationId,
this.UserId == -1 ? null : (int?)this.UserId,
int.Parse(e.Value, CultureInfo.InvariantCulture),
DataProvider.ModuleQualifier);
this.RatingControl.ReadOnly = true;
}
/// <summary>
/// Fills this control with information about this location
/// </summary>
private void BindData()
{
Location location = Location.GetLocation(this.LocationId);
this.LocationNameLabel.Text = location.Name;
this.LocationNameLink.Text = location.Website;
this.LocationNameLink.NavigateUrl = location.Website;
this.LocationDetailsLabel.Text = location.LocationDetails;
this.LocationAddress1Label.Text = location.FullAddress;
this.PhoneNumberLabel.Text = location.Phone;
this.LocationAddress3Label.Text = location.Address3;
this.RatingControl.CurrentRating = (int)Math.Round(location.AverageRating);
this.CommentsRepeater.DataSource = location.GetComments(true).Tables[0];
this.CommentsRepeater.DataBind();
if (this.CommentsRepeater.Items.Count == 0)
{
this.CommentsRepeater.Visible = false;
}
this.CustomAttributeRepeater.DataSource = location.GetAttributes();
this.CustomAttributeRepeater.DataBind();
}
}
}