11using System ;
22using Simplify . Web . Modules . Data ;
33
4- namespace Simplify . Web . MessageBox
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
522{
623 /// <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"
24+ /// The message box templates path
2025 /// </summary>
21- public sealed class MessageBoxHandler : IMessageBoxHandler
22- {
23- /// <summary>
24- /// The message box templates path
25- /// </summary>
26- public const string MessageBoxTemplatesPath = "App_Packages/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- }
26+ public const string MessageBoxTemplatesPath = "App_Packages/Simplify.Web.MessageBox/" ;
4427
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 ) ) ;
28+ private readonly ITemplateFactory _templateFactory ;
29+ private readonly IStringTable _stringTable ;
30+ private readonly IDataCollector _dataCollector ;
5531
56- var templateFile = MessageBoxTemplatesPath ;
57-
58- switch ( status )
59- {
60- case MessageBoxStatus . Information :
61- templateFile += "InfoMessageBox.tpl" ;
62- break ;
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+ }
6344
64- case MessageBoxStatus . Error :
65- templateFile += "ErrorMessageBox.tpl" ;
66- break ;
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 ) ) ;
6755
68- case MessageBoxStatus . Ok :
69- templateFile += "OkMessageBox.tpl" ;
70- break ;
71- }
56+ var templateFile = MessageBoxTemplatesPath ;
7257
73- var tpl = _templateFactory . Load ( templateFile ) ;
58+ switch ( status )
59+ {
60+ case MessageBoxStatus . Information :
61+ templateFile += "InfoMessageBox.tpl" ;
62+ break ;
7463
75- tpl . Set ( "Message" , text ) ;
76- tpl . Set ( "Title" , string . IsNullOrEmpty ( title ) ? _stringTable . GetItem ( "FormTitleMessageBox" ) : title ) ;
64+ case MessageBoxStatus . Error :
65+ templateFile += "ErrorMessageBox.tpl" ;
66+ break ;
7767
78- _dataCollector . Add ( tpl . Get ( ) ) ;
79- _dataCollector . AddTitle ( string . IsNullOrEmpty ( title ) ? _stringTable . GetItem ( "FormTitleMessageBox" ) : title ) ;
68+ case MessageBoxStatus . Ok :
69+ templateFile += "OkMessageBox.tpl" ;
70+ break ;
8071 }
8172
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- Show ( _stringTable . GetItem ( stringTableItemName ) , status , title ) ;
90-
91- /// <summary>
92- /// Get inline message box HTML
93- /// </summary>
94- /// <param name="text">Text of a message box</param>
95- /// <param name="status">Status of a message box</param>
96- /// <returns>Message box html</returns>
97- public string GetInline ( string ? text , MessageBoxStatus status = MessageBoxStatus . Error )
98- {
99- if ( string . IsNullOrEmpty ( text ) )
100- throw new ArgumentNullException ( nameof ( text ) ) ;
73+ var tpl = _templateFactory . Load ( templateFile ) ;
10174
102- var templateFile = MessageBoxTemplatesPath ;
75+ tpl . Set ( "Message" , text ) ;
76+ tpl . Set ( "Title" , string . IsNullOrEmpty ( title ) ? _stringTable . GetItem ( "FormTitleMessageBox" ) : title ) ;
10377
104- switch ( status )
105- {
106- case MessageBoxStatus . Information :
107- templateFile += "InlineInfoMessageBox.tpl" ;
108- break ;
78+ _dataCollector . Add ( tpl . Get ( ) ) ;
79+ _dataCollector . AddTitle ( string . IsNullOrEmpty ( title ) ? _stringTable . GetItem ( "FormTitleMessageBox" ) : title ) ;
80+ }
10981
110- case MessageBoxStatus . Error :
111- templateFile += "InlineErrorMessageBox.tpl" ;
112- break ;
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+ Show ( _stringTable . GetItem ( stringTableItemName ) , status , title ) ;
11390
114- case MessageBoxStatus . Ok :
115- templateFile += "InlineOkMessageBox.tpl" ;
116- break ;
117- }
91+ /// <summary>
92+ /// Get inline message box HTML
93+ /// </summary>
94+ /// <param name="text">Text of a message box</param>
95+ /// <param name="status">Status of a message box</param>
96+ /// <returns>Message box html</returns>
97+ public string GetInline ( string ? text , MessageBoxStatus status = MessageBoxStatus . Error )
98+ {
99+ if ( string . IsNullOrEmpty ( text ) )
100+ throw new ArgumentNullException ( nameof ( text ) ) ;
118101
119- var tpl = _templateFactory . Load ( templateFile ) ;
102+ var templateFile = MessageBoxTemplatesPath ;
120103
121- tpl . Set ( "Message" , text ) ;
104+ switch ( status )
105+ {
106+ case MessageBoxStatus . Information :
107+ templateFile += "InlineInfoMessageBox.tpl" ;
108+ break ;
122109
123- return tpl . Get ( ) ;
110+ case MessageBoxStatus . Error :
111+ templateFile += "InlineErrorMessageBox.tpl" ;
112+ break ;
113+
114+ case MessageBoxStatus . Ok :
115+ templateFile += "InlineOkMessageBox.tpl" ;
116+ break ;
124117 }
125118
126- /// <summary>
127- /// Get inline message box HTML
128- /// </summary>
129- /// <param name="stringTableItemName">Show message from string table item</param>
130- /// <param name="status">Status of a message box</param>
131- /// <returns>Message box html</returns>
132- public string GetInlineSt ( string stringTableItemName , MessageBoxStatus status = MessageBoxStatus . Error ) =>
133- GetInline ( _stringTable . GetItem ( stringTableItemName ) , status ) ;
119+ var tpl = _templateFactory . Load ( templateFile ) ;
120+
121+ tpl . Set ( "Message" , text ) ;
122+
123+ return tpl . Get ( ) ;
134124 }
125+
126+ /// <summary>
127+ /// Get inline message box HTML
128+ /// </summary>
129+ /// <param name="stringTableItemName">Show message from string table item</param>
130+ /// <param name="status">Status of a message box</param>
131+ /// <returns>Message box html</returns>
132+ public string GetInlineSt ( string stringTableItemName , MessageBoxStatus status = MessageBoxStatus . Error ) =>
133+ GetInline ( _stringTable . GetItem ( stringTableItemName ) , status ) ;
135134}
0 commit comments