Working on validation for forms, issues with server side, not sure how to post back model with AJAX submit, yet.

Split out settings model to support validation.
pull/4/head
markus101 14 years ago
parent 6690139616
commit 6e66a7a27f

@ -142,6 +142,7 @@
<HintPath>D:\OpenSource\sabscripts\SABSync\References\SubSonic.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using SubSonic.SqlGeneration.Schema;
namespace NzbDrone.Core.Repository.Quality
@ -23,6 +24,7 @@ namespace NzbDrone.Core.Repository.Quality
public string AllowedString { get; set; }
[DisplayName("Cutoff")]
[Required(ErrorMessage = "Valid Cutoff is Required")]
public QualityTypes Cutoff { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]

@ -5,6 +5,7 @@ using System.Threading;
using System.Web;
using System.Web.Mvc;
using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Web.Models;
@ -53,7 +54,7 @@ namespace NzbDrone.Web.Controllers
public ActionResult Indexers()
{
ViewData["viewName"] = "Indexers";
return View("Index", new SettingsModel
return View("Index", new IndexerSettingsModel
{
NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, false),
NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false),
@ -68,30 +69,22 @@ namespace NzbDrone.Web.Controllers
public ActionResult Downloads()
{
ViewData["viewName"] = "Downloads";
return View("Index", new SettingsModel
{
//Sync Frequency
//Download Propers?
//Retention
//SAB Host/IP
//SAB Port
//SAB APIKey
//SAB Username
//SAB Password
//SAB Category
//SAB Priority
SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)),
DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)),
Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)),
SabHost = _configProvider.GetValue("SabHost", "localhost", false),
SabPort = Convert.ToInt32(_configProvider.GetValue("SabPort", "8080", true)),
SabApiKey = _configProvider.GetValue("SabApiKey", String.Empty, false),
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false),
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false),
SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false),
//SabPriority = _configProvider.GetValue("SabPriority", String.Empty, false)
});
var model = new DownloadSettingsModel
{
SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)),
DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)),
Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)),
SabHost = _configProvider.GetValue("SabHost", "localhost", false),
SabPort = Convert.ToInt32(_configProvider.GetValue("SabPort", "8080", true)),
SabApiKey = _configProvider.GetValue("SabApiKey", String.Empty, false),
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false),
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false),
SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false),
SabPriority = (SabnzbdPriorityType)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.GetValue("SabPriority", "Normal", true)),
};
return View("Index", model);
}
public ActionResult Quality()
@ -109,7 +102,7 @@ namespace NzbDrone.Web.Controllers
var userProfiles = _qualityProvider.GetAllProfiles().Where(q => q.UserProfile).ToList();
var profiles = _qualityProvider.GetAllProfiles().ToList();
var defaultQualityProfileId = Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", profiles[0].ProfileId, true));
var selectList = new SelectList(profiles, "ProfileId", "Name");
@ -150,10 +143,6 @@ namespace NzbDrone.Web.Controllers
try
{
_configProvider.SeriesRoot = data.TvFolder;
_configProvider.SetValue("NzbMatrixUsername", data.NzbMatrixUsername);
_configProvider.SetValue("NzbMatrixApiKey", data.NzbMatrixApiKey);
_configProvider.SetValue("NzbsOrgUId", data.NzbsOrgUId);
_configProvider.SetValue("NzbsOrgHash", data.NzbsOrgHash);
}
catch (Exception)
{
@ -191,7 +180,7 @@ namespace NzbDrone.Web.Controllers
return Content("Error Saving Settings, please fix any errors");
}
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
@ -199,7 +188,7 @@ namespace NzbDrone.Web.Controllers
}
[HttpPost]
public ActionResult SaveIndexers(SettingsModel data)
public ActionResult SaveIndexers(IndexerSettingsModel data)
{
try
{
@ -245,52 +234,59 @@ namespace NzbDrone.Web.Controllers
}
[HttpPost]
public ActionResult SaveDownloads(SettingsModel data)
public ActionResult SaveDownloads(DownloadSettingsModel data)
{
try
if (ModelState.IsValid)
{
if (data.SyncFrequency > 15)
_configProvider.SetValue("SyncFrequency", data.SyncFrequency.ToString());
try
{
if (data.SyncFrequency > 15)
_configProvider.SetValue("SyncFrequency", data.SyncFrequency.ToString());
_configProvider.SetValue("DownloadPropers", data.DownloadPropers.ToString());
_configProvider.SetValue("DownloadPropers", data.DownloadPropers.ToString());
if (data.Retention > 0)
_configProvider.SetValue("Retention", data.Retention.ToString());
if (data.Retention > 0)
_configProvider.SetValue("Retention", data.Retention.ToString());
if (data.SabHost != null)
_configProvider.SetValue("SabHost", data.SabHost);
if (data.SabHost != null)
_configProvider.SetValue("SabHost", data.SabHost);
if (data.SabPort > 0)
_configProvider.SetValue("SabPort", data.SabPort.ToString());
if (data.SabPort > 0)
_configProvider.SetValue("SabPort", data.SabPort.ToString());
if (data.SabApiKey != null)
_configProvider.SetValue("SabApiKey", data.SabApiKey);
if (data.SabApiKey != null)
_configProvider.SetValue("SabApiKey", data.SabApiKey);
if (data.SabUsername != null)
_configProvider.SetValue("SabUsername", data.SabUsername);
if (data.SabUsername != null)
_configProvider.SetValue("SabUsername", data.SabUsername);
if (data.SabPassword != null)
_configProvider.SetValue("SabPassword", data.SabPassword);
if (data.SabPassword != null)
_configProvider.SetValue("SabPassword", data.SabPassword);
if (data.SabCategory != null)
_configProvider.SetValue("SabCategory", data.SabCategory);
if (data.SabCategory != null)
_configProvider.SetValue("SabCategory", data.SabCategory);
//if (data.SabPriority != null)
// _configProvider.SetValue("SabPriority", data.SabPriority.ToString());
}
catch (Exception e)
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
_configProvider.SetValue("SabPriority", data.SabPriority.ToString());
return Content("Error Saving Settings, please fix any errors");
}
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
return Content("Settings Saved.");
}
return Content("Settings Saved.");
catch (Exception e)
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
return Content("Error Saving Settings, please fix any errors");
}
}
//ViewData["viewName"] = "Downloads";
//return View("Index", data);
return Content("Error Saving Settings, please fix any errors");
}
[HttpPost]
@ -314,14 +310,14 @@ namespace NzbDrone.Web.Controllers
profile.Allowed = new List<QualityTypes>();
foreach (var quality in profile.AllowedString.Split(','))
{
var qType = (QualityTypes)Enum.Parse(typeof (QualityTypes), quality);
var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality);
profile.Allowed.Add(qType);
}
//If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit
if (!profile.Allowed.Contains(profile.Cutoff))
throw new InvalidOperationException("Invalid Cutoff Value");
//profile.Cutoff = profile.Allowed.Last();
//profile.Cutoff = profile.Allowed.Last();
if (profile.ProfileId > 0)
_qualityProvider.Update(profile);
@ -334,6 +330,7 @@ namespace NzbDrone.Web.Controllers
catch (Exception e)
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
@ -347,9 +344,9 @@ namespace NzbDrone.Web.Controllers
}
[HttpPost]
public ActionResult SortedList(List<object > items)
public ActionResult SortedList(List<object> items)
{
return Content("Settings Saved.");
}
}
}
}

@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Core.Model;
namespace NzbDrone.Web.Models
{
public class DownloadSettingsModel
{
[Required]
[Range(15, 120, ErrorMessage = "Must be between 15 and 120 minutes")]
[DataType(DataType.Text)]
[DisplayName("Sync Frequency")]
public int SyncFrequency
{
get;
set;
}
[DisplayName("Download Propers")]
public bool DownloadPropers
{
get;
set;
}
[Required (ErrorMessage = "Please enter a valid number")]
[DataType(DataType.Text)]
[DisplayName("Retention")]
public int Retention
{
get;
set;
}
[Required (ErrorMessage = "Please enter a valid host")]
[DataType(DataType.Text)]
[DisplayName("SABnzbd Host")]
public String SabHost
{
get;
set;
}
[Required(ErrorMessage = "Please enter a valid port")]
[DataType(DataType.Text)]
[DisplayName("SABnzbd Port")]
public int SabPort
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd API Key")]
public String SabApiKey
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Username")]
public String SabUsername
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Password")]
public String SabPassword
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Category")]
public String SabCategory
{
get;
set;
}
[Required(ErrorMessage = "Please select a valid priority")]
[DataType(DataType.Text)]
[DisplayName("SABnzbd Priority")]
public SabnzbdPriorityType SabPriority
{
get;
set;
}
public SelectList PrioritySelectList = new SelectList(new string[] { "Low", "Normal", "High" });
}
}

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using NzbDrone.Core.Repository;
namespace NzbDrone.Web.Models
{
public class IndexerSettingsModel
{
[DataType(DataType.Text)]
[DisplayName("NZBMatrix Username")]
public String NzbMatrixUsername
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBMatrix API Key")]
public String NzbMatrixApiKey
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBs.Org UID")]
public String NzbsOrgUId
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBs.Org Hash")]
public String NzbsOrgHash
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBsRus UID")]
public String NzbsrusUId
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBsRus Hash")]
public String NzbsrusHash
{
get;
set;
}
public List<Indexer> Indexers
{
get;
set;
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

@ -30,156 +30,156 @@ namespace NzbDrone.Web.Models
#endregion
#region Indexer Settings
[DataType(DataType.Text)]
[DisplayName("NZBMatrix Username")]
public String NzbMatrixUsername
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBMatrix API Key")]
public String NzbMatrixApiKey
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBs.Org UID")]
public String NzbsOrgUId
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBs.Org Hash")]
public String NzbsOrgHash
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBsRus UID")]
public String NzbsrusUId
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("NZBsRus Hash")]
public String NzbsrusHash
{
get;
set;
}
public List<Indexer> Indexers
{
get;
set;
}
#endregion
#region Download Settings
//Sync Frequency
//Download Propers?
//Retention
//SAB Host/IP
//SAB Port
//SAB APIKey
//SAB Username
//SAB Password
//SAB Category
//SAB Priority
[DataType(DataType.Text)]
[DisplayName("Sync Frequency")]
public int SyncFrequency
{
get;
set;
}
[DisplayName("Download Propers")]
public bool DownloadPropers
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("Retention")]
public int Retention
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Host")]
public String SabHost
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Port")]
public int SabPort
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd API Key")]
public String SabApiKey
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Username")]
public String SabUsername
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Password")]
public String SabPassword
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Category")]
public String SabCategory
{
get;
set;
}
[DataType(DataType.Text)]
[DisplayName("SABnzbd Priority")]
public SabnzbdPriorityType SabPriority
{
get;
set;
}
#endregion
//#region Indexer Settings
//[DataType(DataType.Text)]
//[DisplayName("NZBMatrix Username")]
//public String NzbMatrixUsername
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBMatrix API Key")]
//public String NzbMatrixApiKey
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBs.Org UID")]
//public String NzbsOrgUId
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBs.Org Hash")]
//public String NzbsOrgHash
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBsRus UID")]
//public String NzbsrusUId
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBsRus Hash")]
//public String NzbsrusHash
//{
// get;
// set;
//}
//public List<Indexer> Indexers
//{
// get;
// set;
//}
//#endregion
//#region Download Settings
////Sync Frequency
////Download Propers?
////Retention
////SAB Host/IP
////SAB Port
////SAB APIKey
////SAB Username
////SAB Password
////SAB Category
////SAB Priority
//[DataType(DataType.Text)]
//[DisplayName("Sync Frequency")]
//public int SyncFrequency
//{
// get;
// set;
//}
//[DisplayName("Download Propers")]
//public bool DownloadPropers
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("Retention")]
//public int Retention
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Host")]
//public String SabHost
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Port")]
//public int SabPort
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd API Key")]
//public String SabApiKey
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Username")]
//public String SabUsername
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Password")]
//public String SabPassword
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Category")]
//public String SabCategory
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Priority")]
//public SabnzbdPriorityType SabPriority
//{
// get;
// set;
//}
//#endregion
}
}

@ -85,6 +85,8 @@
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
<Compile Include="Models\AccountModels.cs" />
<Compile Include="Models\DownloadSettingsModel.cs" />
<Compile Include="Models\IndexerSettingsModel.cs" />
<Compile Include="Models\MappingModel.cs" />
<Compile Include="Models\EpisodeModel.cs" />
<Compile Include="Models\QualityModel.cs" />

@ -1,4 +1,4 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NzbDrone.Web.Models.SettingsModel>" %>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NzbDrone.Web.Models.DownloadSettingsModel>" %>
<script type="text/javascript">
$(document).ready(function () {
@ -23,6 +23,10 @@
}
</script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("SaveDownloads", "Settings", FormMethod.Post, new { id = "form", name = "form" }))
{%>
<%: Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") %>
@ -103,13 +107,11 @@
<div class="config-validation"><%= Html.ValidationMessageFor(m => m.SabCategory)%></div>
</div>
<%--<div class="editor-label">
<%= Html.DropDownListFor(m => m.SabPriority) %>
<div class="config-group">
<div class="config-title"><%= Html.LabelFor(m => m.SabPriority) %></div>
<div class="config-value"><%= Html.DropDownListFor(m => m.SabPriority, Model.PrioritySelectList) %></div>
<div class="config-validation"><%= Html.ValidationMessageFor(m => m.SabCategory)%></div>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(m => m.SabCategory)%>
<%= Html.ValidationMessageFor(m => m.SabCategory)%>
</div>--%>
</fieldset>
<p>

@ -1,4 +1,4 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NzbDrone.Web.Models.SettingsModel>" %>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NzbDrone.Web.Models.IndexerSettingsModel>" %>
<script type="text/javascript">
$(document).ready(function () {

@ -89,13 +89,15 @@
<li class="ui-state-default" id="<%= qualitiesList[i].ToString() %>">
<%=Html.RadioButtonFor(x => x.Cutoff, qualitiesList[i])%>
<%= Html.Label(qualitiesList[i].ToString()) %>
<%--<%= Html.RenderPartial("ProfileAllowedQualities", Model.Allowed[i]) %>--%>
</li>
<% } %>
</ul>
</div>
</div>
<%= Html.ValidationMessageFor(x => x.Cutoff) %>
<div class="hiddenProfileDetails">
<%= Html.TextBoxFor(x => x.ProfileId, new { @style = "display:none" })%>
<%= Html.CheckBoxFor(x => x.UserProfile, new { @style = "display:none" })%>

Loading…
Cancel
Save