2013-06-22 08:24:24 +02:00
|
|
|
'use strict';
|
2013-06-25 01:41:59 +02:00
|
|
|
define(
|
|
|
|
[
|
2013-06-29 02:35:21 +02:00
|
|
|
'app',
|
2013-06-25 01:41:59 +02:00
|
|
|
'marionette',
|
2013-07-04 05:04:26 +02:00
|
|
|
'Episode/Search/ButtonsView',
|
2013-06-29 02:35:21 +02:00
|
|
|
'Episode/Search/ManualLayout',
|
|
|
|
'Release/Collection',
|
2013-08-23 04:07:13 +02:00
|
|
|
'Series/SeriesCollection',
|
2013-08-22 06:04:03 +02:00
|
|
|
'Shared/LoadingView',
|
2013-06-29 02:35:21 +02:00
|
|
|
'Shared/Messenger',
|
2013-07-17 08:41:40 +02:00
|
|
|
'Commands/CommandController',
|
|
|
|
'Shared/FormatHelpers'
|
2013-08-23 04:07:13 +02:00
|
|
|
], function (App, Marionette, ButtonsView, ManualSearchLayout, ReleaseCollection, SeriesCollection, LoadingView, Messenger, CommandController, FormatHelpers) {
|
2013-05-15 03:17:24 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
return Marionette.Layout.extend({
|
|
|
|
template: 'Episode/Search/LayoutTemplate',
|
2013-05-15 03:17:24 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
regions: {
|
2013-06-29 02:35:21 +02:00
|
|
|
main: '#episode-search-region'
|
2013-06-07 02:17:57 +02:00
|
|
|
},
|
2013-06-10 04:16:48 +02:00
|
|
|
|
2013-06-29 02:35:21 +02:00
|
|
|
events: {
|
2013-07-04 05:04:26 +02:00
|
|
|
'click .x-search-auto' : '_searchAuto',
|
|
|
|
'click .x-search-manual': '_searchManual',
|
|
|
|
'click .x-search-back' : '_showButtons'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
this.mainView = new ButtonsView();
|
2013-06-29 02:35:21 +02:00
|
|
|
},
|
2013-06-25 01:41:59 +02:00
|
|
|
|
|
|
|
onShow: function () {
|
2013-07-04 05:04:26 +02:00
|
|
|
this._showMainView();
|
2013-06-29 02:35:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_searchAuto: function (e) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandController.Execute('episodeSearch', { episodeId: this.model.get('id') });
|
|
|
|
|
2013-08-23 04:07:13 +02:00
|
|
|
var series = SeriesCollection.get(this.model.get('seriesId'));
|
|
|
|
var seriesTitle = series.get('title');
|
2013-06-29 02:35:21 +02:00
|
|
|
var season = this.model.get('seasonNumber');
|
|
|
|
var episode = this.model.get('episodeNumber');
|
2013-07-17 08:41:40 +02:00
|
|
|
var message = seriesTitle + ' - ' + season + 'x' + FormatHelpers.pad(episode, 2);
|
2013-06-29 02:35:21 +02:00
|
|
|
|
|
|
|
Messenger.show({
|
|
|
|
message: 'Search started for: ' + message
|
|
|
|
});
|
|
|
|
|
2013-07-24 03:15:58 +02:00
|
|
|
App.vent.trigger(App.Commands.CloseModalCommand);
|
2013-06-29 02:35:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_searchManual: function (e) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
2013-06-25 01:41:59 +02:00
|
|
|
}
|
2013-06-29 02:35:21 +02:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2013-08-22 06:04:03 +02:00
|
|
|
this.mainView = new LoadingView();
|
2013-07-04 05:04:26 +02:00
|
|
|
this._showMainView();
|
2013-06-29 02:35:21 +02:00
|
|
|
|
|
|
|
var releases = new ReleaseCollection();
|
|
|
|
var promise = releases.fetchEpisodeReleases(this.model.id);
|
|
|
|
|
|
|
|
promise.done(function () {
|
|
|
|
if (!self.isClosed) {
|
2013-07-04 05:04:26 +02:00
|
|
|
self.mainView = new ManualSearchLayout({collection: releases});
|
|
|
|
self._showMainView();
|
2013-06-29 02:35:21 +02:00
|
|
|
}
|
|
|
|
});
|
2013-07-04 05:04:26 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
_showMainView: function () {
|
|
|
|
this.main.show(this.mainView);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showButtons: function () {
|
|
|
|
this.mainView = new ButtonsView();
|
|
|
|
this._showMainView();
|
2013-06-07 02:17:57 +02:00
|
|
|
}
|
2013-06-25 01:41:59 +02:00
|
|
|
});
|
2013-05-15 03:17:24 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
});
|