From 08b7b8c3e15936f2a0626396fab2b0b3a956625d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 4 Jun 2011 22:23:50 -0700 Subject: [PATCH] SeasonEditor moved to Gird Editor. --- NzbDrone.Core/Providers/EpisodeProvider.cs | Bin 10741 -> 10740 bytes NzbDrone.Web/Controllers/SeriesController.cs | 21 ++----- .../Helpers/HtmlPrefixScopeExtensions.cs | 4 ++ NzbDrone.Web/Helpers/ValueExtension.cs | 27 +++++++++ NzbDrone.Web/Models/SeriesModel.cs | 3 + NzbDrone.Web/NzbDrone.Web.csproj | 1 + .../Series/EditorTemplates/SeriesModel.cshtml | 7 +++ NzbDrone.Web/Views/Series/Index.cshtml | 54 ++++++++++-------- NzbDrone.Web/Views/Series/SeasonEditor.cshtml | 46 ++------------- NzbDrone.Web/Views/Series/SingleSeason.cshtml | 10 +++- 10 files changed, 90 insertions(+), 83 deletions(-) create mode 100644 NzbDrone.Web/Helpers/ValueExtension.cs diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 816a323c1472f15f43f785b9c3ce5d28272ccce2..e6135751c182ac01edc8f51153a99fb52d2042b4 100644 GIT binary patch delta 19 bcmeww{3Uq9F>$6;y~%>oVw>-aiwOY$Sa=6m delta 20 ccmewo{55#PF>z+aRK3Xp(qfzMiHivV0A3;ocmMzZ diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 2441d0162..feb2a8936 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -90,7 +90,7 @@ namespace NzbDrone.Web.Controllers [AcceptVerbs(HttpVerbs.Post)] [GridAction] - public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored, bool seasonFolder, int qualityProfileId, List seasons) + public ActionResult _SaveAjaxSeriesEditing(int id, string path, bool monitored, bool seasonFolder, int qualityProfileId, List seasonEditor) { var oldSeries = _seriesProvider.GetSeries(id); oldSeries.Path = path; @@ -182,25 +182,15 @@ namespace NzbDrone.Web.Controllers return PartialView("SeriesSearchResults", model); } - [AcceptVerbs(HttpVerbs.Post)] - [GridAction] - public ActionResult _SaveAjaxEditing(string id) - { - return RedirectToAction("UnMapped"); - } - [HttpPost] - public ActionResult SaveSeasons(List seasons) + public JsonResult SaveSeason(int seriesId, int seasonNumber, bool monitored) { - foreach (var season in seasons) + if (_episodeProvider.IsIgnored(seriesId, seasonNumber) == monitored) { - if (_episodeProvider.IsIgnored(season.SeriesId, season.SeasonNumber) != !season.Monitored) - { - _episodeProvider.SetSeasonIgnore(season.SeriesId, season.SeasonNumber, !season.Monitored); - } + _episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, !monitored); } - return Content("Saved"); + return new JsonResult { Data = "ok" }; } public ActionResult Details(int seriesId) @@ -284,6 +274,7 @@ namespace NzbDrone.Web.Controllers QualityProfileName = s.QualityProfile.Name, SeasonFolder = s.SeasonFolder, Status = s.Status, + SeasonsCount = _episodeProvider.GetSeasons(s.SeriesId).Where(n => n != 0).Count() }); } diff --git a/NzbDrone.Web/Helpers/HtmlPrefixScopeExtensions.cs b/NzbDrone.Web/Helpers/HtmlPrefixScopeExtensions.cs index e985bc591..c816e1bba 100644 --- a/NzbDrone.Web/Helpers/HtmlPrefixScopeExtensions.cs +++ b/NzbDrone.Web/Helpers/HtmlPrefixScopeExtensions.cs @@ -19,6 +19,10 @@ namespace NzbDrone.Web.Helpers string.Format("", collectionName, itemIndex)); + html.ViewContext.Writer.WriteLine( + string.Format("", + collectionName, itemIndex)); + return BeginHtmlFieldPrefixScope(html, string.Format("{0}[{1}]", collectionName, itemIndex)); } diff --git a/NzbDrone.Web/Helpers/ValueExtension.cs b/NzbDrone.Web/Helpers/ValueExtension.cs new file mode 100644 index 000000000..e6330d24e --- /dev/null +++ b/NzbDrone.Web/Helpers/ValueExtension.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Linq.Expressions; +using System.Web; +using System.Web.Mvc; + +namespace NzbDrone.Web.Helpers +{ + public static class ValueExtension + { + public static object ValueFor(this HtmlHelper html, Expression> expression) + { + var memberEx = expression.Body as MemberExpression; + + if (memberEx == null) + throw new ArgumentException("Body not a member-expression."); + + string name = memberEx.Member.Name; + var model = html.ViewData.Model; + var value = model.GetType().GetProperty(name).GetValue(model, null); + + return value; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Web/Models/SeriesModel.cs b/NzbDrone.Web/Models/SeriesModel.cs index 2fce11b30..785ba0691 100644 --- a/NzbDrone.Web/Models/SeriesModel.cs +++ b/NzbDrone.Web/Models/SeriesModel.cs @@ -35,5 +35,8 @@ namespace NzbDrone.Web.Models [DisplayName("Monitored")] public bool Monitored { get; set; } + + [DisplayName("Season Editor")] + public List SeasonEditor { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 4a515dd1e..f894166cd 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -252,6 +252,7 @@ Global.asax + diff --git a/NzbDrone.Web/Views/Series/EditorTemplates/SeriesModel.cshtml b/NzbDrone.Web/Views/Series/EditorTemplates/SeriesModel.cshtml index a0857b1bc..e5259446c 100644 --- a/NzbDrone.Web/Views/Series/EditorTemplates/SeriesModel.cshtml +++ b/NzbDrone.Web/Views/Series/EditorTemplates/SeriesModel.cshtml @@ -8,6 +8,8 @@
+ @Html.HiddenFor(m => m.SeriesId) +
@Html.LabelFor(m => m.Path)
@Html.TextBoxFor(m => m.Path, new { style = "width: 300" })
@@ -27,4 +29,9 @@ @Html.LabelFor(m => m.QualityProfileId) @Html.DropDownListFor(model => model.QualityProfileId, (SelectList)ViewData["SelectList"], new { style = "margin-left:40px" })
+ +
+
@Html.LabelFor(m => m.SeasonEditor)
+
+
\ No newline at end of file diff --git a/NzbDrone.Web/Views/Series/Index.cshtml b/NzbDrone.Web/Views/Series/Index.cshtml index cea5c4652..3493bab3e 100644 --- a/NzbDrone.Web/Views/Series/Index.cshtml +++ b/NzbDrone.Web/Views/Series/Index.cshtml @@ -109,8 +109,7 @@ .ClientTemplate("<#= Title #>"); - columns.Bound(o => o.SeasonsCount).Title("Seasons") - .ClientTemplate(", \'<#= Title #>\'); return false;\"><#= SeasonsCount #>"); + columns.Bound(o => o.SeasonsCount).Title("Seasons"); columns.Bound(o => o.QualityProfileName).Title("Quality"); columns.Bound(o => o.Status); columns.Bound(o => o.AirsDayOfWeek); @@ -133,6 +132,7 @@ .Sortable(sort => sort.OrderBy(order => order.Add(o => o.Title).Ascending()).Enabled(true)) .DetailView(detailView => detailView.ClientTemplate("
<#= Overview #>
")) .ClientEvents(clientEvents => { clientEvents.OnEdit("grid_edit"); + clientEvents.OnSave("grid_save"); clientEvents.OnDataBinding("grid_bind"); clientEvents.OnDataBound("grid_bound"); clientEvents.OnRowDataBound("grid_rowBound"); @@ -150,6 +150,33 @@ .closest(".t-window") .data("tWindow") .center(); + + var seriesId = args.dataItem.SeriesId; + var url = '@Url.Action("SeasonEditor", "Series")'; + $('#season-editor').load(url, { seriesId: seriesId }); + } + + function grid_save(e) { + var seasonEditor = e.form.SeasonEditor_collection; + var saveSeasonEditUrl = '@Url.Action("SaveSeason", "Series")'; + + jQuery.each(seasonEditor, function() { + var guid = $(this).val(); + var prefix = '#SeasonEditor_' + guid + '__'; + var seriesId = $(prefix + 'SeriesId').val(); + var seasonNumber = $(prefix + 'SeasonNumber').val(); + var monitored = $(prefix + 'Monitored').attr('checked'); + + $.ajax({ + type: "POST", + url: saveSeasonEditUrl, + data: jQuery.param({ seriesId: seriesId, seasonNumber: seasonNumber, monitored: monitored }), + error: function(req, status, error) { + alert("Sorry! We could save season changes at this time. " + error); + }, + success: function(data, textStatus, jqXHR) { } + }); + }); } function grid_rowBound(e) { @@ -188,27 +215,4 @@ } }); } - - - function openSeasonEditor(seriesId, seriesName) { - windowElement = null; - windowElement = $.telerik.window.create({ - title: "Season Editor: " + seriesName + "", - contentUrl: '@Url.Action("SeasonEditor", "Series")' + '/?seriesId=' + seriesId, - width: 360, - height: 400, - modal: true, - resizable: false, - draggable: true, - scrollable: true - }); - - windowElement.data('tWindow').center(); - } - - function closeSeasonEditor() { - $('#form').remove(); - var window = windowElement.data("tWindow"); - window.close(); - } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Series/SeasonEditor.cshtml b/NzbDrone.Web/Views/Series/SeasonEditor.cshtml index bddcef32b..da8ed7027 100644 --- a/NzbDrone.Web/Views/Series/SeasonEditor.cshtml +++ b/NzbDrone.Web/Views/Series/SeasonEditor.cshtml @@ -5,46 +5,12 @@ Layout = null; } - - -@using (Html.BeginForm("SaveSeasons", "Series", FormMethod.Post, new { id = "form" })) -{ -
- @foreach (var season in Model) - { - Html.RenderAction("GetSingleSeasonView", "Series", season); - } -
- -
- - -
-} -
+ + diff --git a/NzbDrone.Web/Views/Series/SingleSeason.cshtml b/NzbDrone.Web/Views/Series/SingleSeason.cshtml index 707ae438b..282a2bd2f 100644 --- a/NzbDrone.Web/Views/Series/SingleSeason.cshtml +++ b/NzbDrone.Web/Views/Series/SingleSeason.cshtml @@ -2,14 +2,18 @@ @using NzbDrone.Web.Models; @model SeasonEditModel -@using (Html.BeginCollectionItem("seasons")) +@using (Html.BeginCollectionItem("SeasonEditor")) { -
+ var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_'); + +
+ @Html.DisplayFor(m => m.SeasonString) @Html.CheckBoxFor(m => m.Monitored, new { @class = "chkbox" }) + @Html.HiddenFor(m => m.SeriesId) @Html.HiddenFor(m => m.SeasonNumber) - @Html.HiddenFor(m => m.SeasonNumber) + @Html.Hidden(idClean, new { @class = "cleanId", })
}