Skip to content

Commit a73a535

Browse files
committed
Handler and responses added
1 parent 5c8beaf commit a73a535

File tree

6 files changed

+328
-3
lines changed

6 files changed

+328
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Simplify.Web.Modules.Data;
2+
3+
namespace Simplify.Web.MessageBox
4+
{
5+
/// <summary>
6+
/// The HTML message box
7+
/// Usable template files:
8+
/// "Simplify.Web/MessageBox/InfoMessageBox.tpl"
9+
/// "Simplify.Web/MessageBox/ErrorMessageBox.tpl"
10+
/// "Simplify.Web/MessageBox/OkMessageBox.tpl"
11+
/// "Simplify.Web/MessageBox/InlineInfoMessageBox.tpl"
12+
/// "Simplify.Web/MessageBox/InlineErrorMessageBox.tpl"
13+
/// "Simplify.Web/MessageBox/InlineOkMessageBox.tpl"
14+
/// Usable <see cref="StringTable"/> items:
15+
/// "FormTitleMessageBox"
16+
/// Template variables:
17+
/// "Message"
18+
/// "Title"
19+
/// </summary>
20+
public interface IMessageBoxHandler : IHideObjectMembers
21+
{
22+
/// <summary>
23+
/// Generate message box HTML and set to data collector
24+
/// </summary>
25+
/// <param name="text">Text of a message box</param>
26+
/// <param name="status">Status of a message box</param>
27+
/// <param name="title">Title of a message box</param>
28+
void Show(string text, MessageBoxStatus status = MessageBoxStatus.Error, string title = null);
29+
30+
/// <summary>
31+
///Generate message box HTML and set to data collector
32+
/// </summary>
33+
/// <param name="stringTableItemName">Show message from string table item</param>
34+
/// <param name="status">Status of a message box</param>
35+
/// <param name="title">Title of a message box</param>
36+
void ShowSt(string stringTableItemName, MessageBoxStatus status = MessageBoxStatus.Error, string title = null);
37+
38+
/// <summary>
39+
/// Get inline message box HTML
40+
/// </summary>
41+
/// <param name="text">Text of a message box</param>
42+
/// <param name="status">Status of a message box</param>
43+
/// <returns>Message box html</returns>
44+
string GetInline(string text, MessageBoxStatus status = MessageBoxStatus.Error);
45+
46+
/// <summary>
47+
/// Get inline message box HTML
48+
/// </summary>
49+
/// <param name="stringTableItemName">Show message from string table item</param>
50+
/// <param name="status">Status of a message box</param>
51+
/// <returns>Message box html</returns>
52+
string GetInlineSt(string stringTableItemName, MessageBoxStatus status = MessageBoxStatus.Error);
53+
}
54+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using Simplify.Web.Modules.Data;
3+
4+
namespace Simplify.Web.MessageBox
5+
{
6+
/// <summary>
7+
/// The HTML message box
8+
/// Usable template files:
9+
/// "Simplify.Web/MessageBox/InfoMessageBox.tpl"
10+
/// "Simplify.Web/MessageBox/ErrorMessageBox.tpl"
11+
/// "Simplify.Web/MessageBox/OkMessageBox.tpl"
12+
/// "Simplify.Web/MessageBox/InlineInfoMessageBox.tpl"
13+
/// "Simplify.Web/MessageBox/InlineErrorMessageBox.tpl"
14+
/// "Simplify.Web/MessageBox/InlineOkMessageBox.tpl"
15+
/// Usable <see cref="StringTable"/> items:
16+
/// "FormTitleMessageBox"
17+
/// Template variables:
18+
/// "Message"
19+
/// "Title"
20+
/// </summary>
21+
public sealed class MessageBoxHandler : IMessageBoxHandler
22+
{
23+
/// <summary>
24+
/// The message box templates path
25+
/// </summary>
26+
public const string MessageBoxTemplatesPath = "Simplify.Web/MessageBox/";
27+
28+
private readonly ITemplateFactory _templateFactory;
29+
private readonly IStringTable _stringTable;
30+
private readonly IDataCollector _dataCollector;
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="MessageBoxHandler"/> class.
34+
/// </summary>
35+
/// <param name="templateFactory">The template factory.</param>
36+
/// <param name="stringTable">The string table.</param>
37+
/// <param name="dataCollector">The data collector.</param>
38+
public MessageBoxHandler(ITemplateFactory templateFactory, IStringTable stringTable, IDataCollector dataCollector)
39+
{
40+
_templateFactory = templateFactory;
41+
_stringTable = stringTable;
42+
_dataCollector = dataCollector;
43+
}
44+
45+
/// <summary>
46+
/// Generate message box HTML and set to data collector
47+
/// </summary>
48+
/// <param name="text">Text of a message box</param>
49+
/// <param name="status">Status of a message box</param>
50+
/// <param name="title">Title of a message box</param>
51+
public void Show(string text, MessageBoxStatus status = MessageBoxStatus.Error, string title = null)
52+
{
53+
if (string.IsNullOrEmpty(text))
54+
throw new ArgumentNullException(nameof(text));
55+
56+
var templateFile = MessageBoxTemplatesPath;
57+
58+
switch (status)
59+
{
60+
case MessageBoxStatus.Information:
61+
templateFile += "InfoMessageBox.tpl";
62+
break;
63+
64+
case MessageBoxStatus.Error:
65+
templateFile += "ErrorMessageBox.tpl";
66+
break;
67+
68+
case MessageBoxStatus.Ok:
69+
templateFile += "OkMessageBox.tpl";
70+
break;
71+
}
72+
73+
var tpl = _templateFactory.Load(templateFile);
74+
75+
tpl.Set("Message", text);
76+
tpl.Set("Title", string.IsNullOrEmpty(title) ? _stringTable.GetItem("FormTitleMessageBox") : title);
77+
78+
_dataCollector.Add(tpl.Get());
79+
_dataCollector.AddTitle(string.IsNullOrEmpty(title) ? _stringTable.GetItem("FormTitleMessageBox") : title);
80+
}
81+
82+
/// <summary>
83+
///Generate message box HTML and set to data collector
84+
/// </summary>
85+
/// <param name="stringTableItemName">Show message from string table item</param>
86+
/// <param name="status">Status of a message box</param>
87+
/// <param name="title">Title of a message box</param>
88+
public void ShowSt(string stringTableItemName, MessageBoxStatus status = MessageBoxStatus.Error, string title = null)
89+
{
90+
Show(_stringTable.GetItem(stringTableItemName), status, title);
91+
}
92+
93+
/// <summary>
94+
/// Get inline message box HTML
95+
/// </summary>
96+
/// <param name="text">Text of a message box</param>
97+
/// <param name="status">Status of a message box</param>
98+
/// <returns>Message box html</returns>
99+
public string GetInline(string text, MessageBoxStatus status = MessageBoxStatus.Error)
100+
{
101+
if (string.IsNullOrEmpty(text))
102+
throw new ArgumentNullException(nameof(text));
103+
104+
var templateFile = MessageBoxTemplatesPath;
105+
106+
switch (status)
107+
{
108+
case MessageBoxStatus.Information:
109+
templateFile += "InlineInfoMessageBox.tpl";
110+
break;
111+
112+
case MessageBoxStatus.Error:
113+
templateFile += "InlineErrorMessageBox.tpl";
114+
break;
115+
116+
case MessageBoxStatus.Ok:
117+
templateFile += "InlineOkMessageBox.tpl";
118+
break;
119+
}
120+
121+
var tpl = _templateFactory.Load(templateFile);
122+
123+
tpl.Set("Message", text);
124+
125+
return tpl.Get();
126+
}
127+
128+
/// <summary>
129+
/// Get inline message box HTML
130+
/// </summary>
131+
/// <param name="stringTableItemName">Show message from string table item</param>
132+
/// <param name="status">Status of a message box</param>
133+
/// <returns>Message box html</returns>
134+
public string GetInlineSt(string stringTableItemName, MessageBoxStatus status = MessageBoxStatus.Error)
135+
{
136+
return GetInline(_stringTable.GetItem(stringTableItemName), status);
137+
}
138+
}
139+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Simplify.Web.MessageBox
2+
{
3+
/// <summary>
4+
/// MessageBox status
5+
/// </summary>
6+
public enum MessageBoxStatus
7+
{
8+
/// <summary>
9+
/// The information status
10+
/// </summary>
11+
Information = 0,
12+
13+
/// <summary>
14+
/// The error status
15+
/// </summary>
16+
Error = 1,
17+
18+
/// <summary>
19+
/// The OK status
20+
/// </summary>
21+
Ok = 2
22+
}
23+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace Simplify.Web.MessageBox.Responses
2+
{
3+
/// <summary>
4+
/// Provides message box response (generate message box and puts it to the data collector)
5+
/// </summary>
6+
public class MessageBox : ControllerResponse
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="MessageBox" /> class.
10+
/// </summary>
11+
/// <param name="text">The message box text.</param>
12+
/// <param name="status">The message box status.</param>
13+
/// <param name="title">The title.</param>
14+
public MessageBox(string text, MessageBoxStatus status = MessageBoxStatus.Error, string title = null)
15+
{
16+
Text = text;
17+
Status = status;
18+
Title = title;
19+
}
20+
21+
/// <summary>
22+
/// Gets the text.
23+
/// </summary>
24+
/// <value>
25+
/// The text.
26+
/// </value>
27+
public string Text { get; }
28+
29+
/// <summary>
30+
/// Gets the status.
31+
/// </summary>
32+
/// <value>
33+
/// The status.
34+
/// </value>
35+
public MessageBoxStatus Status { get; }
36+
37+
/// <summary>
38+
/// Gets the title.
39+
/// </summary>
40+
/// <value>
41+
/// The title.
42+
/// </value>
43+
public string Title { get; }
44+
45+
/// <summary>
46+
/// Processes this response
47+
/// </summary>
48+
/// <returns></returns>
49+
public override ControllerResponseResult Process()
50+
{
51+
var handler = new MessageBoxHandler(TemplateFactory, StringTableManager, DataCollector);
52+
53+
handler.Show(Text, Status, Title);
54+
55+
return ControllerResponseResult.Default;
56+
}
57+
}
58+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Simplify.Web.MessageBox.Responses
2+
{
3+
/// <summary>
4+
/// Provides inline message box response (generate inline message box and sends it to the user only, without site generation)
5+
/// </summary>
6+
public class MessageBoxInline : ControllerResponse
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="Web.MessageBox.Responses.MessageBox"/> class.
10+
/// </summary>
11+
/// <param name="text">The message box text.</param>
12+
/// <param name="status">The message box status.</param>
13+
public MessageBoxInline(string text, MessageBoxStatus status = MessageBoxStatus.Error)
14+
{
15+
Text = text;
16+
Status = status;
17+
}
18+
19+
/// <summary>
20+
/// Gets the text.
21+
/// </summary>
22+
/// <value>
23+
/// The text.
24+
/// </value>
25+
public string Text { get; }
26+
27+
/// <summary>
28+
/// Gets the status.
29+
/// </summary>
30+
/// <value>
31+
/// The status.
32+
/// </value>
33+
public MessageBoxStatus Status { get; }
34+
35+
/// <summary>
36+
/// Processes this response
37+
/// </summary>
38+
/// <returns></returns>
39+
public override ControllerResponseResult Process()
40+
{
41+
var handler = new MessageBoxHandler(TemplateFactory, StringTableManager, DataCollector);
42+
43+
ResponseWriter.Write(handler.GetInline(Text, Status), Context.Response);
44+
45+
return ControllerResponseResult.RawOutput;
46+
}
47+
}
48+
}

Simplify.Web.MessageBox/Simplify.Web.MessageBox.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
3434
</PropertyGroup>
3535
<ItemGroup>
36+
<Compile Include="IMessageBoxHandler.cs" />
37+
<Compile Include="MessageBoxHandler.cs" />
38+
<Compile Include="MessageBoxStatus.cs" />
3639
<Compile Include="Properties\AssemblyInfo.cs" />
40+
<Compile Include="Responses\MessageBox.cs" />
41+
<Compile Include="Responses\MessageBoxInline.cs" />
3742
</ItemGroup>
3843
<ItemGroup>
3944
<Reference Include="Microsoft.CSharp" />
@@ -67,9 +72,7 @@
6772
<None Include="packages.config" />
6873
<None Include="Simplify.Web.MessageBox.nuspec" />
6974
</ItemGroup>
70-
<ItemGroup>
71-
<Folder Include="Responses\" />
72-
</ItemGroup>
75+
<ItemGroup />
7376
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7477
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7578
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)