2013-06-22 09:24:24 +03:00
|
|
|
'use strict';
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
2013-06-29 03:35:21 +03:00
|
|
|
'app',
|
2013-06-25 02:41:59 +03:00
|
|
|
'marionette',
|
2013-06-29 03:35:21 +03:00
|
|
|
'Episode/Search/ManualLayout',
|
|
|
|
'Release/Collection',
|
|
|
|
'Shared/SpinnerView',
|
|
|
|
'Shared/Messenger',
|
|
|
|
'Commands/CommandController'
|
|
|
|
], function (App, Marionette, ManualSearchLayout, ReleaseCollection, SpinnerView, Messenger, CommandController) {
|
2013-05-15 04:17:24 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
return Marionette.Layout.extend({
|
|
|
|
template: 'Episode/Search/LayoutTemplate',
|
2013-05-15 04:17:24 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
regions: {
|
2013-06-29 03:35:21 +03:00
|
|
|
main: '#episode-search-region'
|
2013-06-07 03:17:57 +03:00
|
|
|
},
|
2013-06-10 05:16:48 +03:00
|
|
|
|
2013-06-29 03:35:21 +03:00
|
|
|
events: {
|
|
|
|
'click .x-search-auto': '_searchAuto',
|
|
|
|
'click .x-search-manual': '_searchManual'
|
|
|
|
},
|
2013-06-25 02:41:59 +03:00
|
|
|
|
|
|
|
onShow: function () {
|
2013-06-29 03:35:21 +03:00
|
|
|
this._releaseSearchActivated = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
_searchAuto: function (e) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandController.Execute('episodeSearch', { episodeId: this.model.get('id') });
|
|
|
|
|
|
|
|
var seriesTitle = this.model.get('series').get('title');
|
|
|
|
var season = this.model.get('seasonNumber');
|
|
|
|
var episode = this.model.get('episodeNumber');
|
|
|
|
var message = seriesTitle + ' - S' + season.pad(2) + 'E' + episode.pad(2);
|
|
|
|
|
|
|
|
Messenger.show({
|
|
|
|
message: 'Search started for: ' + message
|
|
|
|
});
|
|
|
|
|
|
|
|
App.modalRegion.closeModal();
|
|
|
|
},
|
|
|
|
|
|
|
|
_searchManual: function (e) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
2013-06-25 02:41:59 +03:00
|
|
|
}
|
2013-06-29 03:35:21 +03:00
|
|
|
|
|
|
|
if (this._releaseSearchActivated) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.main.show(new SpinnerView());
|
|
|
|
|
|
|
|
var releases = new ReleaseCollection();
|
|
|
|
var promise = releases.fetchEpisodeReleases(this.model.id);
|
|
|
|
|
|
|
|
promise.done(function () {
|
|
|
|
if (!self.isClosed) {
|
|
|
|
self.main.show(new ManualSearchLayout({collection: releases}));
|
|
|
|
}
|
|
|
|
});
|
2013-06-07 03:17:57 +03:00
|
|
|
}
|
2013-06-25 02:41:59 +03:00
|
|
|
});
|
2013-05-15 04:17:24 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
});
|