Skip to content

Commit

Permalink
Marionette v3 update
Browse files Browse the repository at this point in the history
Very basics upgrade to v3.  Doesn't really address style or architectural suggestions in v3 (ie: there's stil an App.Vent) but it is using the new lib
  • Loading branch information
paulfalgout committed Mar 17, 2018
1 parent cb44e3f commit 04f23ac
Show file tree
Hide file tree
Showing 26 changed files with 150 additions and 154 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@

// Third party
"Backbone": true,
"Marionette": true,
"Mousetrap": true,
"_": true,
"request": true,
Expand Down
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "butter",
"dependencies": {
"marionette": "~2.x.x",
"backbone": "1.3.3",
"marionette": "~3.x.x",
"bootstrap": "~3.3.7",
"video.js": "4.11.4",
"videojs-youtube": "1.2.10",
Expand All @@ -17,8 +18,6 @@
"underscore": ["**/!(underscore-min.js)"],
"mousetrap": ["tests", ".gitignore", "./*!mousetrap.min.js"],
"marionette": ["**/!(lib)"],
"backbone.babysitter": ["**/!(lib)"],
"backbone.wreqr": ["**/!(lib)"],
"bootstrap": ["**/!(dist)"]
},
"resolutions": {
Expand Down
21 changes: 11 additions & 10 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ if (nw.App.fullArgv.indexOf('--reset') !== -1) {


// Global App skeleton for backbone
var App = new Backbone.Marionette.Application();
var App = new Marionette.Application({
region: '.main-window-region'
});
_.extend(App, {
Controller: {},
View: {},
Expand All @@ -68,6 +70,9 @@ _.extend(App, {
Localization: {}
});

// Create old v2 style vent
App.vent = Backbone.Radio.channel('v2-vent');

// set database
App.db = Database;

Expand All @@ -81,10 +86,6 @@ fs.readFile('./.git.json', 'utf8', function (err, json) {
}
});

App.addRegions({
Window: '.main-window-region'
});

// Menu for mac
if (os.platform() === 'darwin') {
var nativeMenuBar = new nw.Menu({
Expand All @@ -100,7 +101,7 @@ if (os.platform() === 'darwin') {
//Keeps a list of stacked views
App.ViewStack = [];

App.addInitializer(function (options) {
App.onBeforeStart = function (options) {
// this is the 'do things with resolutions and size initializer
var zoom = 0;

Expand Down Expand Up @@ -147,7 +148,7 @@ App.addInitializer(function (options) {
win.zoomLevel = zoom;
win.resizeTo(width, height);
win.moveTo(x, y);
});
};

var initTemplates = function () {
// Load in external templates
Expand All @@ -170,16 +171,16 @@ var initApp = function () {
win.show();

try {
App.Window.show(mainWindow);
App.showView(mainWindow);
} catch (e) {
console.error('Couldn\'t start app: ', e, e.stack);
}
};

App.addInitializer(function (options) {
App.onStart = function (options) {
initTemplates()
.then(initApp);
});
};

var deleteFolder = function (path) {
rimraf(path, function () {});
Expand Down
16 changes: 8 additions & 8 deletions src/app/httpapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@
butterCallback(callback, 'Arguments missing');
}

App.Window.currentView.Content.currentView.ItemList.currentView.selectIndex(index);
App.getView().Content.currentView.ItemList.currentView.selectIndex(index);

butterCallback(callback);
});

server.expose('getselection', function (args, opt, callback) {
var movieView = App.Window.currentView.MovieDetail.currentView;
var movieView = App.getView().MovieDetail.currentView;
if (movieView === undefined || movieView.model === undefined) {
var index = $('.item.selected').index();
if (args.length > 0) {
Expand All @@ -165,7 +165,7 @@
index = 0;
}
}
var result = App.Window.currentView.Content.currentView.ItemList.currentView.collection.models[index];
var result = App.getView().Content.currentView.ItemList.currentView.collection.models[index];
if (result === undefined) {
butterCallback(callback, 'Index not found');
}
Expand Down Expand Up @@ -252,7 +252,7 @@
});

server.expose('getcurrentlist', function (args, opt, callback) {
var collection = App.Window.currentView.Content.currentView.ItemList.currentView.collection;
var collection = App.getView().Content.currentView.ItemList.currentView.collection;
var result = collection.models;
var page = 0;
if (args.length > 0) {
Expand All @@ -267,7 +267,7 @@
'type': result[0].get('type'),
'list': result,
'page': page,
'max_page': App.Window.currentView.Content.currentView.ItemList.currentView.collection.filter.page
'max_page': App.getView().Content.currentView.ItemList.currentView.collection.filter.page
});
} else {
collection.fetchMore();
Expand All @@ -280,11 +280,11 @@
'type': result[0].get('type'),
'list': result,
'page': page,
'max_page': App.Window.currentView.Content.currentView.ItemList.currentView.collection.filter.page
'max_page': App.getView().Content.currentView.ItemList.currentView.collection.filter.page
});
}
} else {
page = App.Window.currentView.Content.currentView.ItemList.currentView.collection.filter.page;
page = App.getView().Content.currentView.ItemList.currentView.collection.filter.page;
butterCallback(callback, false, {
'type': result[0].get('type'),
'list': result,
Expand Down Expand Up @@ -391,7 +391,7 @@
return;
}

var movieView = App.Window.currentView.MovieDetail.currentView;
var movieView = App.getView().MovieDetail.currentView;
if (movieView === undefined || movieView.model === undefined || movieView.model.type === 'movie') {
butterCallback(callback, 'View not open');
return;
Expand Down
3 changes: 1 addition & 2 deletions src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
<script src="vendor/jquery/dist/jquery.min.js"></script>
<script src="vendor/underscore/underscore-min.js"></script>
<script src="vendor/backbone/backbone-min.js"></script>
<script src="vendor/backbone.wreqr/lib/backbone.wreqr.min.js"></script>
<script src="vendor/backbone.babysitter/lib/backbone.babysitter.min.js"></script>
<script src="vendor/backbone.radio/build/backbone.radio.min.js"></script>
<script src="vendor/marionette/lib/backbone.marionette.min.js"></script>
<script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="vendor/mousetrap/mousetrap.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/device/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
var collection = new DeviceCollection(new Device());
collection.setDevice('local');

var ChooserView = Backbone.Marionette.ItemView.extend({
var ChooserView = Marionette.View.extend({
template: '#player-chooser-tpl',
events: {
'click .playerchoicemenu li a': 'selectPlayer'
Expand Down
6 changes: 3 additions & 3 deletions src/app/lib/views/about.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function (App) {
'use strict';

var About = Backbone.Marionette.ItemView.extend({
var About = Marionette.View.extend({
template: '#about-tpl',
className: 'about',

Expand All @@ -15,7 +15,7 @@
'click .title-issue': 'reportIssue'
},

onShow: function () {
onAttach: function () {
$('.filter-bar').hide();
$('#header').addClass('header-shadow');

Expand All @@ -27,7 +27,7 @@
$('#movie-detail').hide();
},

onDestroy: function () {
onBeforeDestroy: function () {
Mousetrap.unbind(['esc', 'backspace']);
$('.filter-bar').show();
$('#header').removeClass('header-shadow');
Expand Down
4 changes: 2 additions & 2 deletions src/app/lib/views/browser/filter_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';
var clipboard = nw.Clipboard.get();

App.View.FilterBar = Backbone.Marionette.ItemView.extend({
App.View.FilterBar = Marionette.View.extend({
className: 'filter-bar',
ui: {
searchForm: '.search form',
Expand Down Expand Up @@ -134,7 +134,7 @@

return menu;
},
onShow: function () {
onAttach: function () {

var activetab;

Expand Down
10 changes: 5 additions & 5 deletions src/app/lib/views/browser/generic_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* * Show movie detail
* * Start playing a movie
*/
var PCTBrowser = Backbone.Marionette.LayoutView.extend({
var PCTBrowser = Marionette.View.extend({
template: '#browser-tpl',
className: 'main-browser',
regions: {
Expand All @@ -34,7 +34,7 @@

},

onShow: function () {
onAttach: function () {
if (Settings.rememberFilters) {
this.filter.set(this.getSavedFilter());
}
Expand All @@ -43,9 +43,9 @@
model: this.filter
});

this.FilterBar.show(this.bar);
this.showChildView('FilterBar', this.bar);

this.ItemList.show(new App.View.List({
this.showChildView('ItemList', new App.View.List({
collection: this.collection
}));

Expand All @@ -68,7 +68,7 @@
App.vent.trigger('show:closeDetail');
this.collection.fetch();

this.ItemList.show(new App.View.List({
this.showChildView('ItemList', new App.View.List({
collection: this.collection
}));
},
Expand Down
6 changes: 3 additions & 3 deletions src/app/lib/views/browser/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var prevX = 0;
var prevY = 0;

var Item = Backbone.Marionette.ItemView.extend({
var Item = Marionette.View.extend({
template: '#item-tpl',

tagName: 'li',
Expand Down Expand Up @@ -77,7 +77,7 @@
}
},

onShow: function () {
onAttach: function () {
this.ui.coverImage.on('load', _.bind(this.showCover, this));
},

Expand All @@ -89,7 +89,7 @@

},

onDestroy: function () {
onBeforeDestroy: function () {
this.ui.coverImage.off('load');
},

Expand Down
13 changes: 9 additions & 4 deletions src/app/lib/views/browser/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}

var ErrorView = Backbone.Marionette.ItemView.extend({
var ErrorView = Marionette.View.extend({
template: '#movie-error-tpl',
ui: {
retryButton: '.retry-button',
Expand Down Expand Up @@ -73,7 +73,7 @@
return !this.collection.length && this.collection.state !== 'loading';
},

getEmptyView: function () {
emptyView: function () {
switch (App.currentview) {
case 'movies':
case 'shows':
Expand Down Expand Up @@ -244,7 +244,7 @@
});
},

onShow: function () {
onAttach: function () {
if (this.collection.state === 'loading') {
this.onLoading();
}
Expand All @@ -257,7 +257,12 @@

onLoaded: function () {
App.vent.trigger('list:loaded');
this.checkEmpty();

// Added for v2-style checkEmpty
if (this.isEmpty()) {
this._showEmptyView();
}

var self = this;
this.addloadmore();

Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/views/disclaimer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function (App) {
'use strict';

var DisclaimerModal = Backbone.Marionette.ItemView.extend({
var DisclaimerModal = Marionette.View.extend({
template: '#disclaimer-tpl',
className: 'disclaimer',

Expand Down
6 changes: 3 additions & 3 deletions src/app/lib/views/file_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var that,
formatMagnet;

var FileSelector = Backbone.Marionette.ItemView.extend({
var FileSelector = Marionette.View.extend({
template: '#file-selector-tpl',
className: 'file-selector',

Expand Down Expand Up @@ -36,7 +36,7 @@
this.bitsnoopRequest(this.model.get('torrent').infoHash);
},

onShow: function () {
onAttach: function () {
this.isTorrentStored();

Mousetrap.bind(['esc', 'backspace'], function (e) {
Expand Down Expand Up @@ -176,7 +176,7 @@
App.vent.trigger('system:closeFileSelector');
},

onDestroy: function () {
onBeforeDestroy: function () {
Settings.droppedTorrent = false;
Settings.droppedMagnet = false;
Settings.droppedStoredMagnet = false;
Expand Down
6 changes: 3 additions & 3 deletions src/app/lib/views/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';
var dyks;

var Help = Backbone.Marionette.ItemView.extend({
var Help = Marionette.View.extend({
template: '#help-tpl',
className: 'help',

Expand All @@ -27,7 +27,7 @@
];
},

onShow: function () {
onAttach: function () {
$('.search input').blur();
Mousetrap.bind('esc', function (e) {
App.vent.trigger('help:close');
Expand All @@ -40,7 +40,7 @@
App.vent.trigger('issue:new');
},

onDestroy: function () {},
onBeforeDestroy: function () {},

closeHelp: function () {
App.vent.trigger('help:close');
Expand Down
Loading

0 comments on commit 04f23ac

Please sign in to comment.