making modals event driven,

pull/6/head
Keivan Beigi 12 years ago
parent 121f3b973d
commit 62cea8de5e

@ -49,7 +49,8 @@ define(
}, },
_folderSelected: function (options) { _folderSelected: function (options) {
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
this.workspace.show(new ExistingSeriesCollectionView({model: options.model})); this.workspace.show(new ExistingSeriesCollectionView({model: options.model}));
}, },

@ -98,7 +98,7 @@ define(
}, },
_setRootFolder: function (options) { _setRootFolder: function (options) {
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
this.ui.rootFolder.val(options.model.id); this.ui.rootFolder.val(options.model.id);
}, },

@ -1,4 +1,4 @@
'use strict'; 'use strict';
define( define(
[ [
@ -6,7 +6,6 @@ define(
'marionette', 'marionette',
'moment', 'moment',
'Calendar/Collection', 'Calendar/Collection',
'Episode/Layout',
'fullcalendar' 'fullcalendar'
], function (App, Marionette, Moment, CalendarCollection, EpisodeLayout) { ], function (App, Marionette, Moment, CalendarCollection, EpisodeLayout) {
@ -37,7 +36,7 @@ define(
$(element).addClass(event.statusLevel); $(element).addClass(event.statusLevel);
$(element).children('.fc-event-inner').addClass(event.statusLevel); $(element).children('.fc-event-inner').addClass(event.statusLevel);
}, },
eventClick : function (event) { eventClick : function (event) {
var view = new EpisodeLayout({ model: event.model }); var view = new EpisodeLayout({ model: event.model });
App.modalRegion.show(view); App.modalRegion.show(view);
} }

@ -1,4 +0,0 @@
'use strict';
define({
ApiRoot : '/api'
});

@ -49,7 +49,7 @@ define(
message: 'Search started for: ' + message message: 'Search started for: ' + message
}); });
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
}, },
_searchManual: function (e) { _searchManual: function (e) {

@ -1,9 +1,9 @@
'use strict'; 'use strict';
define( define(
[ [
'History/Model', 'History/Model',
'backbone.pageable' 'backbone.pageable'
], function ( HistoryModel, PageableCollection) { ], function (HistoryModel, PageableCollection) {
return PageableCollection.extend({ return PageableCollection.extend({
url : window.ApiRoot + '/history', url : window.ApiRoot + '/history',
model: HistoryModel, model: HistoryModel,

@ -25,7 +25,7 @@ define(
wait: true wait: true
}).done(function () { }).done(function () {
App.vent.trigger(App.Events.SeriesDeleted, { series: self.model }); App.vent.trigger(App.Events.SeriesDeleted, { series: self.model });
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
}); });
} }
}); });

@ -6,11 +6,10 @@ define(
'Series/EpisodeCollection', 'Series/EpisodeCollection',
'Series/SeasonCollection', 'Series/SeasonCollection',
'Series/Details/SeasonCollectionView', 'Series/Details/SeasonCollectionView',
'Series/Edit/EditSeriesView',
'Shared/LoadingView', 'Shared/LoadingView',
'Shared/Actioneer', 'Shared/Actioneer',
'backstrech' 'backstrech'
], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, EditSeriesView, LoadingView, Actioneer) { ], function (App, Marionette, EpisodeCollection, SeasonCollection, SeasonCollectionView, LoadingView, Actioneer) {
return Marionette.Layout.extend({ return Marionette.Layout.extend({
itemViewContainer: '.x-series-seasons', itemViewContainer: '.x-series-seasons',
@ -78,7 +77,7 @@ define(
_getFanArt: function () { _getFanArt: function () {
var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'}); var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'});
if(fanArt && fanArt[0]){ if (fanArt && fanArt[0]) {
return fanArt[0].url; return fanArt[0].url;
} }
@ -117,18 +116,17 @@ define(
}, },
_editSeries: function () { _editSeries: function () {
var view = new EditSeriesView({ model: this.model }); App.vent.trigger(App.Commands.EditSeriesCommand, {model: this.model});
App.modalRegion.show(view);
}, },
_refreshSeries: function () { _refreshSeries: function () {
Actioneer.ExecuteCommand({ Actioneer.ExecuteCommand({
command : 'refreshSeries', command : 'refreshSeries',
properties : { properties: {
seriesId : this.model.get('id') seriesId: this.model.get('id')
}, },
element : this.ui.refresh, element : this.ui.refresh,
leaveIcon : true leaveIcon : true
}); });
}, },
@ -143,7 +141,7 @@ define(
Actioneer.ExecuteCommand({ Actioneer.ExecuteCommand({
command : 'renameSeries', command : 'renameSeries',
properties : { properties : {
seriesId : this.model.get('id') seriesId: this.model.get('id')
}, },
element : this.ui.rename, element : this.ui.rename,
failMessage: 'Series search failed' failMessage: 'Series search failed'
@ -154,7 +152,7 @@ define(
Actioneer.ExecuteCommand({ Actioneer.ExecuteCommand({
command : 'seriesSearch', command : 'seriesSearch',
properties : { properties : {
seriesId : this.model.get('id') seriesId: this.model.get('id')
}, },
element : this.ui.search, element : this.ui.search,
failMessage : 'Series search failed', failMessage : 'Series search failed',

@ -1,7 +1,7 @@
'use strict'; 'use strict';
define( define(
[ [
'App', 'app',
'marionette', 'marionette',
'Series/Delete/DeleteSeriesView', 'Series/Delete/DeleteSeriesView',
'Quality/QualityProfileCollection', 'Quality/QualityProfileCollection',
@ -18,8 +18,8 @@ define(
}, },
events: { events: {
'click .x-save' : 'saveSeries', 'click .x-save' : '_saveSeries',
'click .x-remove': 'removeSeries' 'click .x-remove': '_removeSeries'
}, },
@ -28,22 +28,23 @@ define(
}, },
saveSeries: function () { _saveSeries: function () {
var self = this;
var qualityProfileId = this.ui.qualityProfile.val(); var qualityProfileId = this.ui.qualityProfile.val();
this.model.set({ qualityProfileId: qualityProfileId}); this.model.set({ qualityProfileId: qualityProfileId});
this.model.save(); this.model.save().done(function () {
this.trigger('saved'); self.trigger('saved');
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
});
}, },
onRender: function () { onRender: function () {
this.ui.path.autoComplete('/directories'); this.ui.path.autoComplete('/directories');
}, },
removeSeries: function () { _removeSeries: function () {
var view = new DeleteSeriesView({ model: this.model }); var view = new DeleteSeriesView({ model: this.model });
App.modalRegion.show(view); App.modalRegion.show(view);
} }

@ -11,7 +11,7 @@ define(['app', 'marionette'], function (App, Marionette) {
this.model.destroy({ this.model.destroy({
wait : true, wait : true,
success: function () { success: function () {
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
} }
}); });
} }

@ -1,4 +1,4 @@
'use strict'; 'use strict';
define( define(
[ [
@ -11,7 +11,7 @@ define(
template: 'Settings/Indexers/EditTemplate', template: 'Settings/Indexers/EditTemplate',
events: { events: {
'click .x-save': '_save', 'click .x-save' : '_save',
'click .x-save-and-add': '_saveAndAdd' 'click .x-save-and-add': '_saveAndAdd'
}, },
@ -26,7 +26,7 @@ define(
if (promise) { if (promise) {
promise.done(function () { promise.done(function () {
self.indexerCollection.add(self.model, { merge: true }); self.indexerCollection.add(self.model, { merge: true });
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
}); });
} }
}, },
@ -40,13 +40,13 @@ define(
self.indexerCollection.add(self.model, { merge: true }); self.indexerCollection.add(self.model, { merge: true });
self.model.set({ self.model.set({
id: undefined, id : undefined,
name: '', name : '',
enable: false enable: false
}); });
_.each(self.model.get('fields'), function (value, key, list) { _.each(self.model.get('fields'), function (value, key, list) {
self.model.set('fields.' + key +'.value', ''); self.model.set('fields.' + key + '.value', '');
}); });
}); });
} }

@ -11,7 +11,7 @@ define(['app', 'marionette'], function (App, Marionette) {
this.model.destroy({ this.model.destroy({
wait : true, wait : true,
success: function () { success: function () {
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
} }
}); });
} }

@ -39,7 +39,7 @@ define([
if (promise) { if (promise) {
promise.done(function () { promise.done(function () {
self.notificationCollection.add(self.model, { merge: true }); self.notificationCollection.add(self.model, { merge: true });
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
}); });
} }
}, },

@ -17,7 +17,7 @@ define(
this.model.destroy({ this.model.destroy({
wait: true wait: true
}).done(function () { }).done(function () {
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
}); });
} }
}); });

@ -63,7 +63,7 @@ define(['app', 'marionette', 'Mixins/AsModelBoundView'], function (App, Marionet
if (promise) { if (promise) {
promise.done(function () { promise.done(function () {
self.profileCollection.add(self.model, { merge: true }); self.profileCollection.add(self.model, { merge: true });
App.modalRegion.closeModal(); App.vent.trigger(App.Commands.CloseModalCommand);
}); });
} }
} }

@ -0,0 +1,42 @@
'use strict';
define(
[
'app',
'marionette',
'Series/Edit/EditSeriesView',
'Series/Delete/DeleteSeriesView',
'Episode/Layout'
], function (App, Marionette, EditSeriesView, DeleteSeriesView, EpisodeLayout) {
var router = Marionette.AppRouter.extend({
initialize: function () {
App.vent.on(App.Commands.CloseModalCommand, this._closeModal, this);
App.vent.on(App.Commands.EditSeriesCommand, this._editSeries, this);
App.vent.on(App.Commands.DeleteSeriesCommand, this._deleteSeries, this);
App.vent.on(App.Commands.ShowEpisodeDetails, this._showEpisode, this);
},
_closeModal: function () {
App.vent.trigger(App.Commands.CloseModalCommand);
},
_editSeries: function (options) {
var view = new EditSeriesView({ model: options.model });
App.modalRegion.show(view);
},
_deleteSeries: function (options) {
var view = new DeleteSeriesView({ model: options.model });
App.modalRegion.show(view);
},
_showEpisode: function (options) {
var view = new EpisodeLayout({ model: options.model });
App.modalRegion.show(view);
}
});
return new router();
});

@ -39,11 +39,17 @@ define(
}); });
app.addInitializer(function () { require(
app.addRegions({ [
modalRegion : region 'Shared/Modal/Controller'
], function () {
app.addInitializer(function () {
app.addRegions({
modalRegion: region
});
});
}); });
});
return region; return region;
}); });

@ -170,12 +170,16 @@ define(
var app = new Marionette.Application(); var app = new Marionette.Application();
app.Events = { app.Events = {
SeriesAdded: 'series:added', SeriesAdded : 'series:added',
SeriesDeleted: 'series:deleted' SeriesDeleted: 'series:deleted'
}; };
app.Commands = { app.Commands = {
SaveSettings: 'saveSettings' EditSeriesCommand : 'EditSeriesCommand',
DeleteSeriesCommand: 'DeleteSeriesCommand',
CloseModalCommand : 'CloseModalCommand',
ShowEpisodeDetails : 'ShowEpisodeDetails',
SaveSettings : 'saveSettings'
}; };
app.addInitializer(function () { app.addInitializer(function () {
@ -183,8 +187,8 @@ define(
}); });
app.addRegions({ app.addRegions({
mainRegion : '#main-region', mainRegion : '#main-region',
footerRegion : '#footer-region' footerRegion: '#footer-region'
}); });
app.start(); app.start();

Loading…
Cancel
Save