2012-01-19 04:58:32 +01:00
|
|
|
using System.Web.Mvc;
|
|
|
|
|
2011-08-08 23:50:48 +02:00
|
|
|
namespace NzbDrone.Web.Models
|
|
|
|
{
|
2012-01-19 06:01:47 +01:00
|
|
|
public class JsonNotificationResult
|
2011-08-08 23:50:48 +02:00
|
|
|
{
|
2012-01-19 06:01:47 +01:00
|
|
|
private JsonNotificationResult()
|
2011-08-08 23:50:48 +02:00
|
|
|
{
|
|
|
|
Text = string.Empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
public string Text { get; set; }
|
|
|
|
public NotificationType NotificationType { get; set; }
|
|
|
|
|
|
|
|
|
2012-01-19 04:58:32 +01:00
|
|
|
public static JsonResult Info(string title, string text)
|
|
|
|
{
|
2012-01-19 06:01:47 +01:00
|
|
|
return GetJsonResult(NotificationType.Info, title, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static JsonResult Info(string title)
|
|
|
|
{
|
|
|
|
return GetJsonResult(NotificationType.Info, title, string.Empty);
|
2012-01-19 04:58:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static JsonResult Error(string title, string text)
|
|
|
|
{
|
|
|
|
return GetJsonResult(NotificationType.Error, title, text);
|
|
|
|
}
|
|
|
|
|
2012-02-23 23:31:50 +01:00
|
|
|
public static JsonResult Oops(string text)
|
2012-01-19 06:01:47 +01:00
|
|
|
{
|
2012-02-23 23:31:50 +01:00
|
|
|
return GetJsonResult(NotificationType.Error, "Oops!", text);
|
2012-01-19 06:01:47 +01:00
|
|
|
}
|
|
|
|
|
2012-02-26 22:47:04 +01:00
|
|
|
public static JsonResult Queued(string task)
|
|
|
|
{
|
|
|
|
return GetJsonResult(NotificationType.Info, "Added to queue", string.Format("{0} will start soon.", task.Trim()));
|
|
|
|
}
|
|
|
|
|
2012-01-19 06:01:47 +01:00
|
|
|
|
2012-01-19 04:58:32 +01:00
|
|
|
public static JsonResult GetJsonResult(NotificationType notificationType, string title, string text)
|
|
|
|
{
|
|
|
|
return new JsonResult
|
|
|
|
{
|
2012-01-19 06:01:47 +01:00
|
|
|
Data = new JsonNotificationResult { NotificationType = notificationType, Title = title, Text = text },
|
2012-08-30 06:15:30 +02:00
|
|
|
ContentType = "application/json; charset=UTF-8",
|
|
|
|
ContentEncoding = System.Text.Encoding.UTF8,
|
2012-01-19 04:58:32 +01:00
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet
|
|
|
|
};
|
|
|
|
}
|
2011-08-08 23:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum NotificationType
|
|
|
|
{
|
|
|
|
Info,
|
|
|
|
Error
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|