From 4a55d08130f3baec9de7a8d18ecdb3a30ec99ecf Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 26 Feb 2012 00:36:47 -0800 Subject: [PATCH] Ajax Links are all handled by jQuery now, no more MvcAjax handlers. --- NzbDrone.Web/Controllers/EpisodeController.cs | 2 -- NzbDrone.Web/Helpers/LinkHelper.cs | 15 --------------- NzbDrone.Web/Scripts/NzbDrone/AutoBind.js | 17 +++++++++++++++++ NzbDrone.Web/Scripts/NzbDrone/grid.js | 8 ++++---- NzbDrone.Web/Views/History/Index.cshtml | 4 ++-- NzbDrone.Web/Views/Log/Index.cshtml | 2 +- NzbDrone.Web/Views/Missing/Index.cshtml | 6 +++--- NzbDrone.Web/Views/Series/Details.cshtml | 6 +++--- NzbDrone.Web/Views/Series/Episode.cshtml | 2 +- NzbDrone.Web/Views/Series/Index.cshtml | 2 +- NzbDrone.Web/Views/Series/Season.cshtml | 4 ++-- NzbDrone.Web/Views/Upcoming/Index.cshtml | 2 +- .../Views/Upcoming/UpcomingEpisode.cshtml | 2 +- NzbDrone.Web/Views/Update/Index.cshtml | 2 +- 14 files changed, 37 insertions(+), 37 deletions(-) diff --git a/NzbDrone.Web/Controllers/EpisodeController.cs b/NzbDrone.Web/Controllers/EpisodeController.cs index 11eb0c52e..c956f1aa7 100644 --- a/NzbDrone.Web/Controllers/EpisodeController.cs +++ b/NzbDrone.Web/Controllers/EpisodeController.cs @@ -14,14 +14,12 @@ namespace NzbDrone.Web.Controllers _jobProvider = jobProvider; } - [HttpPost] public JsonResult Search(int episodeId) { _jobProvider.QueueJob(typeof(EpisodeSearchJob), episodeId); return JsonNotificationResult.Info("Queued"); } - [HttpPost] public JsonResult SearchSeason(int seriesId, int seasonNumber) { _jobProvider.QueueJob(typeof(SeasonSearchJob), seriesId, seasonNumber); diff --git a/NzbDrone.Web/Helpers/LinkHelper.cs b/NzbDrone.Web/Helpers/LinkHelper.cs index af1438715..df6d83245 100644 --- a/NzbDrone.Web/Helpers/LinkHelper.cs +++ b/NzbDrone.Web/Helpers/LinkHelper.cs @@ -11,21 +11,6 @@ namespace NzbDrone.Web.Helpers { public static class LinkHelper { - public static MvcHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, object imgAttributes, string actionName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes) - { - return ImageActionLink(helper, imageUrl, imgAttributes, actionName, null, routeValues, ajaxOptions, htmlAttributes); - } - - public static MvcHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, object imgAttributes, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes) - { - var builder = new TagBuilder("img"); - builder.MergeAttribute("src", imageUrl); - var imgAttributesDictionary = new RouteValueDictionary(imgAttributes); - builder.MergeAttributes(imgAttributesDictionary); - var link = helper.ActionLink("[replaceme]", actionName, controllerName, routeValues, ajaxOptions, htmlAttributes).ToHtmlString(); - return new MvcHtmlString(link.Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing))); - } - public static MvcHtmlString ImageActionLink(this HtmlHelper helper, string imageUrl, object imgAttributes, string actionName, object routeValues, object htmlAttributes) { return ImageActionLink(helper, imageUrl, imgAttributes, actionName, null, routeValues, htmlAttributes); diff --git a/NzbDrone.Web/Scripts/NzbDrone/AutoBind.js b/NzbDrone.Web/Scripts/NzbDrone/AutoBind.js index 1e8026218..a8eb52972 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/AutoBind.js +++ b/NzbDrone.Web/Scripts/NzbDrone/AutoBind.js @@ -42,4 +42,21 @@ } }); }); +}); + +//Make .ajaxLink use jQuery Ajax for the request + +$(document).on('click', '.ajaxLink', function (event) { + event.preventDefault(); + var onSuccess = $(this).attr('onsuccess'); + $.ajax({ + url: this.href, + cache: false, + success: function () { + if (onSuccess) { + window[onSuccess](); + } + } + }); + return false; }); \ No newline at end of file diff --git a/NzbDrone.Web/Scripts/NzbDrone/grid.js b/NzbDrone.Web/Scripts/NzbDrone/grid.js index 481c5482a..7095a0f28 100644 --- a/NzbDrone.Web/Scripts/NzbDrone/grid.js +++ b/NzbDrone.Web/Scripts/NzbDrone/grid.js @@ -1,6 +1,6 @@ /* Click on row, show details */ -$('.seriesTable a, .dataTable a').live('click', function (event) { - if ($(this).attr('onclick')) +$(document).on('click', '.seriesTable a, .dataTable a', function (event) { + if ($(this).hasClass('ajaxLink') || $(this).attr('onclick')) return; event.preventDefault(); @@ -48,8 +48,8 @@ function fnFormatDetails(nTr) { //Create Image function createImageAjaxLink(url, image, alt, title, classes) { - var html = "" + - "\"""; + var html = '' + + '' + alt + ''; return html; } diff --git a/NzbDrone.Web/Views/History/Index.cshtml b/NzbDrone.Web/Views/History/Index.cshtml index 38b03d05b..73cbde43c 100644 --- a/NzbDrone.Web/Views/History/Index.cshtml +++ b/NzbDrone.Web/Views/History/Index.cshtml @@ -3,8 +3,8 @@ @{ViewBag.Title = "History";} @section ActionMenu{ } @section HeaderContent diff --git a/NzbDrone.Web/Views/Log/Index.cshtml b/NzbDrone.Web/Views/Log/Index.cshtml index 85f9097ab..0f0ec7d2a 100644 --- a/NzbDrone.Web/Views/Log/Index.cshtml +++ b/NzbDrone.Web/Views/Log/Index.cshtml @@ -3,7 +3,7 @@ @{ ViewBag.Title = "Logs";} @section ActionMenu{ } diff --git a/NzbDrone.Web/Views/Missing/Index.cshtml b/NzbDrone.Web/Views/Missing/Index.cshtml index f003520f5..d819df6b5 100644 --- a/NzbDrone.Web/Views/Missing/Index.cshtml +++ b/NzbDrone.Web/Views/Missing/Index.cshtml @@ -9,9 +9,9 @@ } @section ActionMenu{ }
diff --git a/NzbDrone.Web/Views/Series/Details.cshtml b/NzbDrone.Web/Views/Series/Details.cshtml index 39eaf8e1d..9f3d80af0 100644 --- a/NzbDrone.Web/Views/Series/Details.cshtml +++ b/NzbDrone.Web/Views/Series/Details.cshtml @@ -68,9 +68,9 @@ { } diff --git a/NzbDrone.Web/Views/Series/Episode.cshtml b/NzbDrone.Web/Views/Series/Episode.cshtml index e9b5c9e32..e2bffc20a 100644 --- a/NzbDrone.Web/Views/Series/Episode.cshtml +++ b/NzbDrone.Web/Views/Series/Episode.cshtml @@ -25,7 +25,7 @@ @*Commands Column*@ - @Ajax.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for episode", @class = "gridAction" }, "Search", "Episode", new { episodeId = Model.EpisodeId }, null, null) + @Html.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for episode", @class = "gridAction" }, "Search", "Episode", new { episodeId = Model.EpisodeId }, new { @class = "ajaxLink" }) @Model.Status diff --git a/NzbDrone.Web/Views/Series/Index.cshtml b/NzbDrone.Web/Views/Series/Index.cshtml index 9a21d2a32..6e1db83ab 100644 --- a/NzbDrone.Web/Views/Series/Index.cshtml +++ b/NzbDrone.Web/Views/Series/Index.cshtml @@ -75,7 +75,7 @@ @section ActionMenu{ } diff --git a/NzbDrone.Web/Views/Series/Season.cshtml b/NzbDrone.Web/Views/Series/Season.cshtml index 5764cffd8..a7db36a74 100644 --- a/NzbDrone.Web/Views/Series/Season.cshtml +++ b/NzbDrone.Web/Views/Series/Season.cshtml @@ -23,8 +23,8 @@ @*Commands Column*@ - @Ajax.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for all episodes in this season", @class = "gridAction" }, "SearchSeason", "Episode", new { SeriesId = Model.SeriesId, SeasonNumber = Model.SeasonNumber }, null, null) - @Ajax.ImageActionLink("../../Content/Images/Rename.png", new { Alt = "Rename", Title = "Rename all episodes in this season", @class = "gridAction" }, "RenameSeason", "Episode", new { SeriesId = Model.SeriesId, SeasonNumber = Model.SeasonNumber }, null, null) + @Html.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for all episodes in this season", @class = "gridAction" }, "SearchSeason", "Episode", new { SeriesId = Model.SeriesId, SeasonNumber = Model.SeasonNumber }, new { @class = "ajaxLink" }) + @Html.ImageActionLink("../../Content/Images/Rename.png", new { Alt = "Rename", Title = "Rename all episodes in this season", @class = "gridAction" }, "RenameSeason", "Episode", new { SeriesId = Model.SeriesId, SeasonNumber = Model.SeasonNumber }, new { @class = "ajaxLink" }) diff --git a/NzbDrone.Web/Views/Upcoming/Index.cshtml b/NzbDrone.Web/Views/Upcoming/Index.cshtml index 22e6134bd..663c87392 100644 --- a/NzbDrone.Web/Views/Upcoming/Index.cshtml +++ b/NzbDrone.Web/Views/Upcoming/Index.cshtml @@ -20,7 +20,7 @@ } @section ActionMenu{ }
diff --git a/NzbDrone.Web/Views/Upcoming/UpcomingEpisode.cshtml b/NzbDrone.Web/Views/Upcoming/UpcomingEpisode.cshtml index 8ab45ff19..cce7bfdfc 100644 --- a/NzbDrone.Web/Views/Upcoming/UpcomingEpisode.cshtml +++ b/NzbDrone.Web/Views/Upcoming/UpcomingEpisode.cshtml @@ -36,7 +36,7 @@ @*Commands Column*@ @Model.Status - @Ajax.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for episode", @class = "gridAction" }, "Search", "Episode", new { episodeId = Model.EpisodeId }, null, null) + @Html.ImageActionLink("../../Content/Images/Search.png", new { Alt = "Search", Title = "Search for episode", @class = "gridAction" }, "Search", "Episode", new { episodeId = Model.EpisodeId }, new { @class = "ajaxLink" }) diff --git a/NzbDrone.Web/Views/Update/Index.cshtml b/NzbDrone.Web/Views/Update/Index.cshtml index 20e6cea24..842ba0e89 100644 --- a/NzbDrone.Web/Views/Update/Index.cshtml +++ b/NzbDrone.Web/Views/Update/Index.cshtml @@ -9,7 +9,7 @@ else {

Available Update: @Model.UpdatePackage.Version - @Ajax.ActionLink("Update", "StartUpdate", "Update", null) + @Html.ActionLink("Update", "StartUpdate", "Update", null, new { @class = "ajaxLink" })

} @if (Model.LogFiles.Count != 0)