2013-06-22 06:24:24 +00:00
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
define(
|
|
|
|
[
|
2013-06-29 00:35:21 +00:00
|
|
|
'app',
|
2013-06-24 23:41:59 +00:00
|
|
|
'marionette',
|
2013-07-04 03:04:26 +00:00
|
|
|
'Episode/Search/ButtonsView',
|
2013-06-29 00:35:21 +00:00
|
|
|
'Episode/Search/ManualLayout',
|
|
|
|
'Release/Collection',
|
2013-08-23 02:07:13 +00:00
|
|
|
'Series/SeriesCollection',
|
2013-09-11 06:33:47 +00:00
|
|
|
'Commands/CommandController',
|
|
|
|
'Shared/LoadingView'
|
|
|
|
], function (App, Marionette, ButtonsView, ManualSearchLayout, ReleaseCollection, SeriesCollection,CommandController, LoadingView) {
|
2013-05-15 01:17:24 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
return Marionette.Layout.extend({
|
2013-09-19 05:49:15 +00:00
|
|
|
template: 'Episode/Search/EpisodeSearchLayoutTemplate',
|
2013-05-15 01:17:24 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
regions: {
|
2013-06-29 00:35:21 +00:00
|
|
|
main: '#episode-search-region'
|
2013-06-07 00:17:57 +00:00
|
|
|
},
|
2013-06-10 02:16:48 +00:00
|
|
|
|
2013-06-29 00:35:21 +00:00
|
|
|
events: {
|
2013-07-04 03:04:26 +00: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 00:35:21 +00:00
|
|
|
},
|
2013-06-24 23:41:59 +00:00
|
|
|
|
|
|
|
onShow: function () {
|
2013-09-19 05:49:15 +00:00
|
|
|
if (this.startManualSearch) {
|
|
|
|
this._searchManual();
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
this._showMainView();
|
|
|
|
}
|
2013-06-29 00:35:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_searchAuto: function (e) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2013-09-11 06:33:47 +00:00
|
|
|
CommandController.Execute('episodeSearch', {
|
|
|
|
episodeId: this.model.get('id')
|
2013-06-29 00:35:21 +00:00
|
|
|
});
|
|
|
|
|
2013-07-24 01:15:58 +00:00
|
|
|
App.vent.trigger(App.Commands.CloseModalCommand);
|
2013-06-29 00:35:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_searchManual: function (e) {
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
2013-06-24 23:41:59 +00:00
|
|
|
}
|
2013-06-29 00:35:21 +00:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2013-08-22 04:04:03 +00:00
|
|
|
this.mainView = new LoadingView();
|
2013-07-04 03:04:26 +00:00
|
|
|
this._showMainView();
|
2013-06-29 00:35:21 +00:00
|
|
|
|
|
|
|
var releases = new ReleaseCollection();
|
|
|
|
var promise = releases.fetchEpisodeReleases(this.model.id);
|
|
|
|
|
|
|
|
promise.done(function () {
|
|
|
|
if (!self.isClosed) {
|
2013-07-04 03:04:26 +00:00
|
|
|
self.mainView = new ManualSearchLayout({collection: releases});
|
|
|
|
self._showMainView();
|
2013-06-29 00:35:21 +00:00
|
|
|
}
|
|
|
|
});
|
2013-07-04 03:04:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_showMainView: function () {
|
|
|
|
this.main.show(this.mainView);
|
|
|
|
},
|
|
|
|
|
|
|
|
_showButtons: function () {
|
|
|
|
this.mainView = new ButtonsView();
|
|
|
|
this._showMainView();
|
2013-06-07 00:17:57 +00:00
|
|
|
}
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|
2013-05-15 01:17:24 +00:00
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
});
|