AutoComplete is now using jQuery UI AutoComplete.

Removed jquery.liveQuery.
pull/2/head
Mark McDowall 13 years ago
parent 59d4ae6219
commit d330c65165

@ -4,7 +4,6 @@ using System.IO;
using System.Linq;
using System.Web.Mvc;
using NLog;
using NzbDrone.Core.Helpers;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
@ -170,12 +169,16 @@ namespace NzbDrone.Web.Controllers
}
[HttpGet]
public JsonResult LookupSeries(string q)
public JsonResult LookupSeries(string term)
{
var dataVal = _tvDbProvider.SearchSeries(q);
return Json(dataVal.Select(c => new KeyValuePair<int, string>(c.Id, c.SeriesName)), JsonRequestBehavior.AllowGet);
var tvDbResults = _tvDbProvider.SearchSeries(term).Select(r => new TvDbSearchResultModel
{
Id = r.Id,
Title = r.SeriesName,
FirstAired = r.FirstAired.ToShortDateString()
}).ToList();
return Json(tvDbResults, JsonRequestBehavior.AllowGet);
}
public ActionResult RootList()

@ -29,26 +29,26 @@ namespace NzbDrone.Web.Controllers
}
[HttpGet]
public JsonResult GetDirectories(string q)
public JsonResult GetDirectories(string term)
{
string[] dirs = null;
try
{
//Windows (Including UNC)
var windowsSep = q.LastIndexOf('\\');
var windowsSep = term.LastIndexOf('\\');
if (windowsSep > -1)
{
dirs = _diskProvider.GetDirectories(q.Substring(0, windowsSep + 1));
dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1));
}
//Unix
var index = q.LastIndexOf('/');
var index = term.LastIndexOf('/');
if (index > -1)
{
dirs = _diskProvider.GetDirectories(q.Substring(0, index + 1));
dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1));
}
}
catch

@ -45,9 +45,13 @@ namespace NzbDrone.Web.Controllers
return View();
}
public ActionResult TestPartial()
public JsonResult TestResults(string q)
{
return View();
var results = new List<TvDbSearchResultModel>();
results.Add(new TvDbSearchResultModel { Id = 1, Title = "30 Rock", FirstAired = DateTime.Today.ToShortDateString() });
results.Add(new TvDbSearchResultModel { Id = 2, Title = "The Office", FirstAired = DateTime.Today.AddDays(-1).ToShortDateString() });
return Json(results, JsonRequestBehavior.AllowGet );
}
public ActionResult Index()

@ -1,7 +0,0 @@
namespace NzbDrone.Web.Models
{
public class TestModel
{
public int Number { get; set; }
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NzbDrone.Web.Models
{
public class TvDbSearchResultModel
{
public int Id { get; set; }
public string Title { get; set; }
public string FirstAired { get; set; }
}
}

@ -509,7 +509,7 @@
<Compile Include="Models\SeriesModel.cs" />
<Compile Include="Models\SeriesSearchResultModel.cs" />
<Compile Include="Models\SettingsModels.cs" />
<Compile Include="Models\TestModel.cs" />
<Compile Include="Models\TvDbSearchResultModel.cs" />
<Compile Include="Models\UpcomingEpisodeModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -764,7 +764,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="Views\Settings\Test.cshtml" />
<Content Include="Views\Settings\TestPartial.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Misnamed\Index.cshtml" />

@ -3,46 +3,51 @@
cache: false
});
$('.folderLookup').livequery(function () {
bindFolderAutoComplete(".folderLookup");
});
$('.seriesLookup').livequery(function () {
bindSeriesAutoComplete(".seriesLookup");
});
bindFolderAutoComplete(".folderLookup");
bindSeriesAutoComplete(".seriesLookup");
});
function bindFolderAutoComplete(selector) {
$(selector).each(function (index, element) {
YUI().use("autocomplete", "autocomplete-highlighters", 'autocomplete-filters', function (Y) {
Y.one('body').addClass('yui3-skin-sam');
Y.one(element).plug(Y.Plugin.AutoComplete, {
resultHighlighter: 'startsWith',
resultFilters: 'phraseMatch',
source: '/Directory/GetDirectories/?q={query}'
});
$(element).autocomplete({
//source: "/Directory/GetDirectories",
source: function (request, response) {
$.ajax({
url: "/Directory/GetDirectories",
dataType: "json",
data: {
term: request.term
},
success: function (data) {
var re = $.ui.autocomplete.escapeRegex(request.term);
var matcher = new RegExp("^" + re, "i");
response($.grep(data, function (item) { return matcher.test(item); }));
}
});
},
minLength: 3
});
});
}
function bindSeriesAutoComplete(selector) {
$(selector).each(function (index, element) {
YUI().use("autocomplete", "autocomplete-highlighters", 'autocomplete-filters', function (Y) {
Y.one('body').addClass('yui3-skin-sam');
Y.one(element).plug(Y.Plugin.AutoComplete, {
resultHighlighter: 'startsWith',
resultFilters: 'phraseMatch',
resultTextLocator: 'Value',
minQueryLength: 3,
queryDelay: 500,
source: '/AddSeries/LookupSeries/?q={query}'
});
});
$(element).autocomplete({
source: "/AddSeries/LookupSeries",
minLength: 3,
delay: 500,
select: function (event, ui) {
$(this).val(ui.item.Title);
return false;
}
})
.data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><strong>" + item.Title + "</strong><br>" + item.FirstAired + "</a>")
.appendTo(ul);
};
});
}

@ -1,250 +0,0 @@
/*! Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 1.0.3
* Requires jQuery 1.1.3+
* Docs: http://docs.jquery.com/Plugins/livequery
*/
(function($) {
$.extend($.fn, {
livequery: function(type, fn, fn2) {
var self = this, q;
// Handle different call patterns
if ($.isFunction(type))
fn2 = fn, fn = type, type = undefined;
// See if Live Query already exists
$.each( $.livequery.queries, function(i, query) {
if ( self.selector == query.selector && self.context == query.context &&
type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
// Found the query, exit the each loop
return (q = query) && false;
});
// Create new Live Query if it wasn't found
q = q || new $.livequery(this.selector, this.context, type, fn, fn2);
// Make sure it is running
q.stopped = false;
// Run it immediately for the first time
q.run();
// Contnue the chain
return this;
},
expire: function(type, fn, fn2) {
var self = this;
// Handle different call patterns
if ($.isFunction(type))
fn2 = fn, fn = type, type = undefined;
// Find the Live Query based on arguments and stop it
$.each( $.livequery.queries, function(i, query) {
if ( self.selector == query.selector && self.context == query.context &&
(!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
$.livequery.stop(query.id);
});
// Continue the chain
return this;
}
});
$.livequery = function(selector, context, type, fn, fn2) {
this.selector = selector;
this.context = context || document;
this.type = type;
this.fn = fn;
this.fn2 = fn2;
this.elements = [];
this.stopped = false;
// The id is the index of the Live Query in $.livequery.queries
this.id = $.livequery.queries.push(this)-1;
// Mark the functions for matching later on
fn.$lqguid = fn.$lqguid || $.livequery.guid++;
if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++;
// Return the Live Query
return this;
};
$.livequery.prototype = {
stop: function() {
var query = this;
if ( this.type )
// Unbind all bound events
this.elements.unbind(this.type, this.fn);
else if (this.fn2)
// Call the second function for all matched elements
this.elements.each(function(i, el) {
query.fn2.apply(el);
});
// Clear out matched elements
this.elements = [];
// Stop the Live Query from running until restarted
this.stopped = true;
},
run: function() {
// Short-circuit if stopped
if ( this.stopped ) return;
var query = this;
var oEls = this.elements,
els = $(this.selector, this.context),
nEls = els.not(oEls);
// Set elements to the latest set of matched elements
this.elements = els;
if (this.type) {
// Bind events to newly matched elements
nEls.bind(this.type, this.fn);
// Unbind events to elements no longer matched
if (oEls.length > 0)
$.each(oEls, function(i, el) {
if ( $.inArray(el, els) < 0 )
$.event.remove(el, query.type, query.fn);
});
}
else {
// Call the first function for newly matched elements
nEls.each(function() {
query.fn.apply(this);
});
// Call the second function for elements no longer matched
if ( this.fn2 && oEls.length > 0 )
$.each(oEls, function(i, el) {
if ( $.inArray(el, els) < 0 )
query.fn2.apply(el);
});
}
}
};
$.extend($.livequery, {
guid: 0,
queries: [],
queue: [],
running: false,
timeout: null,
checkQueue: function() {
if ( $.livequery.running && $.livequery.queue.length ) {
var length = $.livequery.queue.length;
// Run each Live Query currently in the queue
while ( length-- )
$.livequery.queries[ $.livequery.queue.shift() ].run();
}
},
pause: function() {
// Don't run anymore Live Queries until restarted
$.livequery.running = false;
},
play: function() {
// Restart Live Queries
$.livequery.running = true;
// Request a run of the Live Queries
$.livequery.run();
},
registerPlugin: function() {
$.each( arguments, function(i,n) {
// Short-circuit if the method doesn't exist
if (!$.fn[n]) return;
// Save a reference to the original method
var old = $.fn[n];
// Create a new method
$.fn[n] = function() {
// Call the original method
var r = old.apply(this, arguments);
// Request a run of the Live Queries
$.livequery.run();
// Return the original methods result
return r;
}
});
},
run: function(id) {
if (id != undefined) {
// Put the particular Live Query in the queue if it doesn't already exist
if ( $.inArray(id, $.livequery.queue) < 0 )
$.livequery.queue.push( id );
}
else
// Put each Live Query in the queue if it doesn't already exist
$.each( $.livequery.queries, function(id) {
if ( $.inArray(id, $.livequery.queue) < 0 )
$.livequery.queue.push( id );
});
// Clear timeout if it already exists
if ($.livequery.timeout) clearTimeout($.livequery.timeout);
// Create a timeout to check the queue and actually run the Live Queries
$.livequery.timeout = setTimeout($.livequery.checkQueue, 20);
},
stop: function(id) {
if (id != undefined)
// Stop are particular Live Query
$.livequery.queries[ id ].stop();
else
// Stop all Live Queries
$.each( $.livequery.queries, function(id) {
$.livequery.queries[ id ].stop();
});
}
});
// Register core DOM manipulation methods
$.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove');
// Run Live Queries when the Document is ready
$(function() { $.livequery.play(); });
// Save a reference to the original init method
var init = $.prototype.init;
// Create a new init method that exposes two new properties: selector and context
$.prototype.init = function(a,c) {
// Call the original init and save the result
var r = init.apply(this, arguments);
// Copy over properties if they exist already
if (a && a.selector)
r.context = a.context, r.selector = a.selector;
// Set properties
if ( typeof a == 'string' )
r.context = c || document, r.selector = a;
// Return the result
return r;
};
// Give the init function the jQuery prototype for later instantiation (needed after Rev 4091)
$.prototype.init.prototype = $.prototype;
})(jQuery);

File diff suppressed because one or more lines are too long

@ -107,7 +107,4 @@ function reloadAddNew() {
jQuery(document).ready(function () {
//RootDir
$('#rootDirInput').watermark('Enter your new root folder path...');
//AddNew
$('#newSeriesLookup').watermark('Title of the series you want to add...');
});

@ -12,3 +12,10 @@
Add</button>
</div>
<br />
<script type="text/javascript">
jQuery(document).ready(function () {
//AddNew
$('#newSeriesLookup').watermark('Title of the series you want to add...');
});
</script>

@ -1,38 +1,33 @@
@Html.DropDownList("SabTvCategory", new SelectList(new List<string> { "TV" }))
<style>
.ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script>
var sabCategoryUrl = '../Command/GetSabnzbdCategories';
$(function () {
$("#birds").autocomplete({
source: "/Settings/TestResults",
minLength: 3,
delay: 500,
select: function (event, ui) {
$(this).val(ui.item.Title);
return false;
}
})
.data("autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a><strong>" + item.Title + "</strong><br>" + item.FirstAired + "</a>")
.appendTo(ul);
};
});
</script>
$('#SabTvCategory').focus(function () {
$.ajax({
type: "POST",
url: sabCategoryUrl,
data: jQuery.param({ host: '192.168.5.55', port: 2222, apiKey: '5c770e3197e4fe763423ee7c392c25d1', username: 'admin', password: 'pass' }),
error: function (req, status, error) {
$.each($('#SabTvCategory option'), function () {
$(this).remove();
});
$('#SabTvCategory').append($('<option />').val('tv').text('Please check your SABnzbd Settings'));
},
success: function (data, textStatus, jqXHR) {
//Get the current value
var currentlySelected = $('#SabTvCategory').val();
//Remove all existing options
$.each($('#SabTvCategory option'), function () {
$(this).remove();
});
<div class="demo">
//Add the new ones
$.each(data.categories, function () {
$('#SabTvCategory').append($('<option />').val(this.toString()).text(this.toString()));
});
<div class="ui-widget">
<label for="birds">Birds: </label>
<input id="birds" />
</div>
//Attempt to reset to the preiously selected value (change to lower-case)
$("#SabTvCategory").val(currentlySelected.toLowerCase());
}
});
});
</script>
</div><!-- End demo -->

@ -1,24 +0,0 @@
@{
Layout = null;
}
@using (Html.BeginForm("SaveDownloads", "Settings", FormMethod.Post, new { id = "feedback-form" }))
{
<p class="note">This is just an example, sent data will <strong>not</strong> be saved.</p>
<label for="name">Name:</label>
@Html.TextBox("name")
<label for="email">E-mail:</label>
@Html.TextBox("email")
<label for="comment-value">Comments:</label>
@(Html.Telerik().Editor()
.Name("comment")
.Tools(tools => tools
.Clear()
.Bold().Italic().Separator()
.InsertOrderedList().InsertUnorderedList().Separator()
.Indent().Outdent()
))
<button type="submit" class="t-button t-state-default">Save</button>
<button type="button" class="t-button t-state-default" onclick="closeWindow()">Close</button>
}

@ -18,7 +18,6 @@
<script type="text/javascript" src="/Scripts/Plugins/jquery-1.6.3.min.js"></script>
<script type="text/javascript" src="/Scripts/Plugins/jquery-ui-1.8.16.min.js"></script>
<script type="text/javascript" src="/Scripts/Plugins/yui-min.js"></script>
<script type="text/javascript" src="/Scripts/Plugins/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/Scripts/Plugins/MicrosoftMvcAjax.js"></script>
<script type="text/javascript" src="/Scripts/Plugins/jquery.gritter.js"></script>
@ -29,6 +28,7 @@
<script type="text/javascript" src="/Scripts/Plugins/doTimeout.js"></script>
<script type="text/javascript" src="/Scripts/episodeSearch.js"></script>
<script type="text/javascript" src="/Scripts/autocomplete.js"></script>
@MvcMiniProfiler.MiniProfiler.RenderIncludes()
@RenderSection("HeaderContent", required: false)
</head>

Loading…
Cancel
Save