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/3113/head
markus101 14 years ago
parent 6690139616
commit 6e66a7a27f

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

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

@ -5,6 +5,7 @@ using System.Threading;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using NLog; using NLog;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Repository.Quality;
using NzbDrone.Web.Models; using NzbDrone.Web.Models;
@ -53,7 +54,7 @@ namespace NzbDrone.Web.Controllers
public ActionResult Indexers() public ActionResult Indexers()
{ {
ViewData["viewName"] = "Indexers"; ViewData["viewName"] = "Indexers";
return View("Index", new SettingsModel return View("Index", new IndexerSettingsModel
{ {
NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, false), NzbMatrixUsername = _configProvider.GetValue("NzbMatrixUsername", String.Empty, false),
NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false), NzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false),
@ -68,19 +69,9 @@ namespace NzbDrone.Web.Controllers
public ActionResult Downloads() public ActionResult Downloads()
{ {
ViewData["viewName"] = "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
var model = new DownloadSettingsModel
{
SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)), SyncFrequency = Convert.ToInt32(_configProvider.GetValue("SyncFrequency", "15", true)),
DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)), DownloadPropers = Convert.ToBoolean(_configProvider.GetValue("DownloadPropers", "false", true)),
Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)), Retention = Convert.ToInt32(_configProvider.GetValue("Retention", "500", true)),
@ -90,8 +81,10 @@ namespace NzbDrone.Web.Controllers
SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false), SabUsername = _configProvider.GetValue("SabUsername", String.Empty, false),
SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false), SabPassword = _configProvider.GetValue("SabPassword", String.Empty, false),
SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false), SabCategory = _configProvider.GetValue("SabCategory", String.Empty, false),
//SabPriority = _configProvider.GetValue("SabPriority", String.Empty, false) SabPriority = (SabnzbdPriorityType)Enum.Parse(typeof(SabnzbdPriorityType), _configProvider.GetValue("SabPriority", "Normal", true)),
}); };
return View("Index", model);
} }
public ActionResult Quality() public ActionResult Quality()
@ -150,10 +143,6 @@ namespace NzbDrone.Web.Controllers
try try
{ {
_configProvider.SeriesRoot = data.TvFolder; _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) catch (Exception)
{ {
@ -199,7 +188,7 @@ namespace NzbDrone.Web.Controllers
} }
[HttpPost] [HttpPost]
public ActionResult SaveIndexers(SettingsModel data) public ActionResult SaveIndexers(IndexerSettingsModel data)
{ {
try try
{ {
@ -245,7 +234,9 @@ namespace NzbDrone.Web.Controllers
} }
[HttpPost] [HttpPost]
public ActionResult SaveDownloads(SettingsModel data) public ActionResult SaveDownloads(DownloadSettingsModel data)
{
if (ModelState.IsValid)
{ {
try try
{ {
@ -275,9 +266,14 @@ namespace NzbDrone.Web.Controllers
if (data.SabCategory != null) if (data.SabCategory != null)
_configProvider.SetValue("SabCategory", data.SabCategory); _configProvider.SetValue("SabCategory", data.SabCategory);
//if (data.SabPriority != null) _configProvider.SetValue("SabPriority", data.SabPriority.ToString());
// _configProvider.SetValue("SabPriority", data.SabPriority.ToString());
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
return Content("Settings Saved.");
} }
catch (Exception e) catch (Exception e)
{ {
Logger.ErrorException(e.Message, e); Logger.ErrorException(e.Message, e);
@ -286,11 +282,11 @@ namespace NzbDrone.Web.Controllers
return Content("Error Saving Settings, please fix any errors"); return Content("Error Saving Settings, please fix any errors");
} }
}
if (Request.IsAjaxRequest()) //ViewData["viewName"] = "Downloads";
return Content("Settings Saved."); //return View("Index", data);
return Content("Error Saving Settings, please fix any errors");
return Content("Settings Saved.");
} }
[HttpPost] [HttpPost]
@ -314,7 +310,7 @@ namespace NzbDrone.Web.Controllers
profile.Allowed = new List<QualityTypes>(); profile.Allowed = new List<QualityTypes>();
foreach (var quality in profile.AllowedString.Split(',')) 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); profile.Allowed.Add(qType);
} }
@ -334,6 +330,7 @@ namespace NzbDrone.Web.Controllers
catch (Exception e) catch (Exception e)
{ {
Logger.ErrorException(e.Message, e); Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest()) if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors"); return Content("Error Saving Settings, please fix any errors");
@ -347,7 +344,7 @@ namespace NzbDrone.Web.Controllers
} }
[HttpPost] [HttpPost]
public ActionResult SortedList(List<object > items) public ActionResult SortedList(List<object> items)
{ {
return Content("Settings Saved."); 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;

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

@ -85,6 +85,8 @@
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" /> <Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
<Compile Include="Helpers\IsCurrentActionHelper.cs" /> <Compile Include="Helpers\IsCurrentActionHelper.cs" />
<Compile Include="Models\AccountModels.cs" /> <Compile Include="Models\AccountModels.cs" />
<Compile Include="Models\DownloadSettingsModel.cs" />
<Compile Include="Models\IndexerSettingsModel.cs" />
<Compile Include="Models\MappingModel.cs" /> <Compile Include="Models\MappingModel.cs" />
<Compile Include="Models\EpisodeModel.cs" /> <Compile Include="Models\EpisodeModel.cs" />
<Compile Include="Models\QualityModel.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"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {
@ -23,6 +23,10 @@
} }
</script> </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" })) <% 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.") %> <%: 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 class="config-validation"><%= Html.ValidationMessageFor(m => m.SabCategory)%></div>
</div> </div>
<%--<div class="editor-label"> <div class="config-group">
<%= Html.DropDownListFor(m => m.SabPriority) %> <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>
<div class="editor-field">
<%= Html.TextBoxFor(m => m.SabCategory)%>
<%= Html.ValidationMessageFor(m => m.SabCategory)%>
</div>--%>
</fieldset> </fieldset>
<p> <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"> <script type="text/javascript">
$(document).ready(function () { $(document).ready(function () {

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

Loading…
Cancel
Save