Added auto completion on General Settings for RootDir settings using jQuery UI.

pull/4/head
Mark McDowall 14 years ago
parent 30d7fecff5
commit 46e7c6f495

@ -15,3 +15,39 @@
{ {
margin-top: 2px; margin-top: 2px;
} }
.ui-autocomplete { position: absolute; cursor: default; }
/* workarounds */
* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */
.ui-menu {
list-style:none;
padding: 2px;
margin: 0;
display:block;
float: left;
}
.ui-menu .ui-menu {
margin-top: -3px;
}
.ui-menu .ui-menu-item {
margin:0;
padding: 0;
zoom: 1;
float: left;
clear: left;
width: 100%;
}
.ui-menu .ui-menu-item a {
text-decoration:none;
display:block;
padding:.2em .4em;
line-height:1.5;
zoom:1;
}
.ui-menu .ui-menu-item a.ui-state-hover,
.ui-menu .ui-menu-item a.ui-state-active {
font-weight: normal;
margin: -1px;
}

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using NLog; using NLog;
@ -27,10 +28,12 @@ namespace NzbDrone.Web.Controllers
private readonly RootDirProvider _rootDirProvider; private readonly RootDirProvider _rootDirProvider;
private readonly AutoConfigureProvider _autoConfigureProvider; private readonly AutoConfigureProvider _autoConfigureProvider;
private readonly NotificationProvider _notificationProvider; private readonly NotificationProvider _notificationProvider;
private readonly DiskProvider _diskProvider;
public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider, public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider,
QualityProvider qualityProvider, RootDirProvider rootDirProvider, QualityProvider qualityProvider, RootDirProvider rootDirProvider,
AutoConfigureProvider autoConfigureProvider, NotificationProvider notificationProvider) AutoConfigureProvider autoConfigureProvider, NotificationProvider notificationProvider,
DiskProvider diskProvider)
{ {
_configProvider = configProvider; _configProvider = configProvider;
_indexerProvider = indexerProvider; _indexerProvider = indexerProvider;
@ -38,6 +41,7 @@ namespace NzbDrone.Web.Controllers
_rootDirProvider = rootDirProvider; _rootDirProvider = rootDirProvider;
_autoConfigureProvider = autoConfigureProvider; _autoConfigureProvider = autoConfigureProvider;
_notificationProvider = notificationProvider; _notificationProvider = notificationProvider;
_diskProvider = diskProvider;
} }
public ActionResult Index(string viewName) public ActionResult Index(string viewName)
@ -313,6 +317,52 @@ namespace NzbDrone.Web.Controllers
} }
} }
public ActionResult AutoCompletePath(string path)
{
var windowsSep = path.LastIndexOf('\\');
if (windowsSep > -1)
{
var start = path.Substring(windowsSep + 1);
var dirs = _diskProvider.GetDirectories(path.Substring(0, windowsSep + 1)).Where(d => new DirectoryInfo(d).Name.ToLower().StartsWith(start.ToLower()));
return Content(String.Join("\n", dirs));
}
var index = path.LastIndexOf('/');
if (index > -1)
{
var start = path.Substring(index + 1);
var dirs = _diskProvider.GetDirectories(path.Substring(0, index + 1)).Where(d => new DirectoryInfo(d).Name.ToLower().StartsWith(start.ToLower()));
return Content(String.Join("\n", dirs));
}
return Content("");
}
public JsonResult JsonAutoCompletePath(string term)
{
var windowsSep = term.LastIndexOf('\\');
if (windowsSep > -1)
{
var start = term.Substring(windowsSep + 1);
var dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1)).Where(d => new DirectoryInfo(d).Name.ToLower().StartsWith(start.ToLower())).Take(10);
return Json(dirs.ToArray(), JsonRequestBehavior.AllowGet);
}
var index = term.LastIndexOf('/');
if (index > -1)
{
var start = term.Substring(index + 1);
var dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1)).Where(d => new DirectoryInfo(d).Name.ToLower().StartsWith(start.ToLower())).Take(10);
return Json(dirs.ToArray(), JsonRequestBehavior.AllowGet);
}
return Json(new JsonResult(), JsonRequestBehavior.AllowGet);
}
[HttpPost] [HttpPost]
public ActionResult SaveGeneral(SettingsModel data) public ActionResult SaveGeneral(SettingsModel data)
{ {

@ -573,6 +573,7 @@
<Content Include="Content\Images\Indexers\NzbsOrg.png" /> <Content Include="Content\Images\Indexers\NzbsOrg.png" />
<Content Include="Content\Images\Indexers\NzbsRus.png" /> <Content Include="Content\Images\Indexers\NzbsRus.png" />
<Content Include="Content\Images\Indexers\Unknown.png" /> <Content Include="Content\Images\Indexers\Unknown.png" />
<Content Include="Content\Images\indicator.gif" />
<Content Include="Content\Images\Plus.png" /> <Content Include="Content\Images\Plus.png" />
<Content Include="Content\Images\spin.gif" /> <Content Include="Content\Images\spin.gif" />
<Content Include="Content\Images\ui-bg_diagonals-small_0_aaaaaa_40x40.png" /> <Content Include="Content\Images\ui-bg_diagonals-small_0_aaaaaa_40x40.png" />
@ -596,6 +597,7 @@
<Content Include="Content\jquery-ui-1.8.8.custom.css" /> <Content Include="Content\jquery-ui-1.8.8.custom.css" />
<Content Include="Content\jquery-ui.css" /> <Content Include="Content\jquery-ui.css" />
<Content Include="Content\jquery-ui.custom.css" /> <Content Include="Content\jquery-ui.custom.css" />
<Content Include="Content\jquery.autocomplete.css" />
<Content Include="Content\jquery.jgrowl.css" /> <Content Include="Content\jquery.jgrowl.css" />
<Content Include="Content\notibar.css" /> <Content Include="Content\notibar.css" />
<Content Include="Content\style.css" /> <Content Include="Content\style.css" />
@ -637,6 +639,7 @@
<Content Include="Scripts\jquery-1.5.2.min.js" /> <Content Include="Scripts\jquery-1.5.2.min.js" />
<Content Include="Scripts\jquery-ui-1.8.8.min.js" /> <Content Include="Scripts\jquery-ui-1.8.8.min.js" />
<Content Include="Scripts\jquery-ui-1.8.5.custom.min.js" /> <Content Include="Scripts\jquery-ui-1.8.5.custom.min.js" />
<Content Include="Scripts\jquery.autocomplete.js" />
<Content Include="Scripts\jquery.form.js" /> <Content Include="Scripts\jquery.form.js" />
<Content Include="Scripts\jquery.jgrowl.js" /> <Content Include="Scripts\jquery.jgrowl.js" />
<Content Include="Scripts\jquery-tgc-countdown-1.0.js" /> <Content Include="Scripts\jquery-tgc-countdown-1.0.js" />

@ -11,6 +11,13 @@
}; };
$('#form').ajaxForm(options); $('#form').ajaxForm(options);
$('#save_button').attr('disabled', ''); $('#save_button').attr('disabled', '');
$(".root_dir_text").autocomplete({ url: '@Url.Action("AutoCompletePath", "Settings")', paramName: 'path', minChars: 3, delay: 300, maxCacheLength: 1 });
$(".root_dir_text").autocomplete({
source: '@Url.Action("JsonAutoCompletePath", "Settings")',
minLength: 3
});
}); });
function showRequest(formData, jqForm, options) { function showRequest(formData, jqForm, options) {

@ -19,7 +19,7 @@
<div class="rootDirSection" id="div_@(ViewData["RootDirId"])"> <div class="rootDirSection" id="div_@(ViewData["RootDirId"])">
<fieldset> <fieldset>
<div> <div class="ui-widget">
@Html.TextBoxFor(m => m.Path, new { @class = "root_dir_text" }) @Html.TextBoxFor(m => m.Path, new { @class = "root_dir_text" })
<a href="#" class="deleteRow" onclick="deleteRootDir('@ViewData["RootDirId"]')"> <a href="#" class="deleteRow" onclick="deleteRootDir('@ViewData["RootDirId"]')">
<img src="../../Content/Images/X.png" alt="Delete" /></a> <img src="../../Content/Images/X.png" alt="Delete" /></a>

Loading…
Cancel
Save