2017-11-17 22:25:55 +00:00
|
|
|
|
using System.Web;
|
|
|
|
|
using Xamarin.Forms.Internals;
|
|
|
|
|
|
|
|
|
|
namespace Ooui.Forms
|
|
|
|
|
{
|
|
|
|
|
public class DisplayAlert
|
|
|
|
|
{
|
|
|
|
|
private readonly Button _closeButton;
|
|
|
|
|
private readonly Button _acceptButton;
|
|
|
|
|
private readonly Button _cancelButton;
|
|
|
|
|
|
|
|
|
|
public DisplayAlert(AlertArguments arguments)
|
|
|
|
|
{
|
|
|
|
|
Element = new Div
|
|
|
|
|
{
|
|
|
|
|
ClassName = "modal-dialog"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var content = new Div
|
|
|
|
|
{
|
|
|
|
|
ClassName = "modal-content"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var header = new Div
|
|
|
|
|
{
|
|
|
|
|
ClassName = "modal-header"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_closeButton = new Button
|
|
|
|
|
{
|
|
|
|
|
ClassName = "close"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_closeButton.AppendChild(new Span(HttpUtility.HtmlDecode("×")));
|
|
|
|
|
|
|
|
|
|
var h4 = new Heading(4)
|
|
|
|
|
{
|
|
|
|
|
Text = arguments.Title
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
header.AppendChild(_closeButton);
|
|
|
|
|
header.AppendChild(h4);
|
|
|
|
|
|
|
|
|
|
content.AppendChild(header);
|
|
|
|
|
content.AppendChild(new Div()
|
|
|
|
|
{
|
|
|
|
|
ClassName = "modal-body",
|
|
|
|
|
Text = arguments.Message
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(arguments.Cancel))
|
|
|
|
|
{
|
|
|
|
|
var footer = new Div()
|
|
|
|
|
{
|
|
|
|
|
ClassName = "modal-footer"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_cancelButton = new Button(arguments.Cancel)
|
|
|
|
|
{
|
|
|
|
|
ClassName = "btn btn-default"
|
|
|
|
|
};
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_cancelButton.Click += (s, e) => SetResult(false);
|
2017-11-17 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
footer.AppendChild(_cancelButton);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(arguments.Accept))
|
|
|
|
|
{
|
|
|
|
|
_acceptButton = new Button(arguments.Accept)
|
|
|
|
|
{
|
|
|
|
|
ClassName = "btn btn-default"
|
|
|
|
|
};
|
2017-11-17 22:39:11 +00:00
|
|
|
|
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_acceptButton.Click += (s, e) => SetResult(true);
|
2017-11-17 22:25:55 +00:00
|
|
|
|
footer.AppendChild(_acceptButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content.AppendChild(footer);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 22:39:11 +00:00
|
|
|
|
|
2017-11-17 22:25:55 +00:00
|
|
|
|
Element.AppendChild(content);
|
2017-11-17 22:39:11 +00:00
|
|
|
|
|
|
|
|
|
void SetResult(bool result)
|
|
|
|
|
{
|
|
|
|
|
arguments.SetResult(result);
|
|
|
|
|
}
|
2017-11-17 22:25:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event TargetEventHandler Clicked
|
|
|
|
|
{
|
|
|
|
|
add
|
|
|
|
|
{
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_closeButton.Click += value;
|
2017-11-17 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
if(_cancelButton != null)
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_cancelButton.Click += value;
|
2017-11-17 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
if(_acceptButton != null)
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_acceptButton.Click += value;
|
2017-11-17 22:25:55 +00:00
|
|
|
|
}
|
|
|
|
|
remove
|
|
|
|
|
{
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_closeButton.Click -= value;
|
2017-11-17 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
if (_cancelButton != null)
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_cancelButton.Click -= value;
|
2017-11-17 22:25:55 +00:00
|
|
|
|
|
|
|
|
|
if (_acceptButton != null)
|
2017-12-10 23:07:33 +00:00
|
|
|
|
_acceptButton.Click -= value;
|
2017-11-17 22:25:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public Element Element { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
}
|