added add series search model/collections

This commit is contained in:
Keivan Beigi 2013-01-22 16:29:58 -08:00 committed by kay.one
parent d110cf2633
commit c247406d67
5 changed files with 56 additions and 8 deletions

View File

@ -187,6 +187,7 @@
<Compile Include="App_Start\MiniProfiler.cs" />
<Content Include="_backboneApp\AddSeries\AddNewSeries\AddNewSeriesTemplate.html" />
<Content Include="_backboneApp\AddSeries\AddNewSeries\AddNewSeriesView.js" />
<Content Include="_backboneApp\AddSeries\AddNewSeries\SearchResultTemplate.html" />
<Content Include="_backboneApp\AddSeries\SeriesSearchModel.js" />
<Content Include="_backboneApp\Content\Intelisense\bootstrap.css" />
<Content Include="_backboneApp\JsLibraries\backbone.marionette.extend.js" />

View File

@ -3,4 +3,6 @@
<i class="add-on icon-search"></i>
<input type="text" class="span10" placeholder="Start typing the name of series you want to add ...">
</div>
<div id="search-result">
</div>
</div>

View File

@ -1,27 +1,68 @@
/// <reference path="../../app.js" />
/// <reference path="../SeriesSearchModel.js" />
NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.ItemView.extend({
NzbDrone.AddSeries.SearchItemView = Backbone.Marionette.ItemView.extend({
tagName: 'li',
template: "AddSeries/AddNewSeries/SearchResultTemplate",
itemView: NzbDrone.AddSeries.SearchResultModel,
initialize: function () {
this.collection = new NzbDrone.AddSeries.SearchResultCollection();
this.bindTo(this.collection, 'reset', this.render);
},
});
NzbDrone.AddSeries.SearchResultView = Backbone.Marionette.CollectionView.extend({
tagName: 'ul',
className: 'result',
itemView: NzbDrone.AddSeries.SearchResultModel,
collection : new NzbDrone.AddSeries.SearchResultCollection(),
initialize: function () {
//this.collection = new NzbDrone.AddSeries.SearchResultCollection();
this.listenTo(this.collection, 'reset', this.render);
},
});
NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({
template: "AddSeries/AddNewSeries/AddNewSeriesTemplate",
ui: {
seriesSearch: '.search input'
},
onRender: function() {
regions: {
searchResult: "#search-result",
},
collection: new NzbDrone.AddSeries.SearchResultCollection(),
onRender: function () {
console.log('binding auto complete');
var self = this;
this.ui.seriesSearch
.data('timeout', null)
.keyup(function() {
.keyup(function () {
clearTimeout(self.$el.data('timeout'));
self.$el.data('timeout', setTimeout(self.search, 500, self));
});
this.searchResult.show(new NzbDrone.AddSeries.SearchResultView());
},
search: function (context) {
search: function(context) {
console.log(context.ui.seriesSearch.val());
var term = context.ui.seriesSearch.val();
console.log(term);
context.collection.fetch({ data: $.param({ term: term }) });
},
});

View File

@ -0,0 +1,3 @@
<div>
<h3>result</h3>
</div>

View File

@ -1,10 +1,11 @@
/// <reference path="../app.js" />
NzbDrone.AddSeries.SeriesSearchResultModel = Backbone.Model.extend({
NzbDrone.AddSeries.SearchResultModel = Backbone.Model.extend({
});
NzbDrone.AddSeries.SeriesSearchResultCollection = Backbone.Collection.extend({
NzbDrone.AddSeries.SearchResultCollection = Backbone.Collection.extend({
model: NzbDrone.AddSeries.SearchResultModel,
url: "http://localhost/api/v1/series/lookup"
});