Commit 91d09a28 authored by alexandre's avatar alexandre

fix score creation. Turns out the solution was to be found in Backbone

Relational.

<http://backbonerelational.org/#RelationalModel-find>

This was useful as well:

<https://medium.com/blog-marionettejs/a-basic-marionette-app-3e5c261146ea>
parent e52c1a77
......@@ -7,8 +7,10 @@ window.W = window.W || {};
'use strict';
W.ScoreApp = new Backbone.Marionette.Application({
region: 'body',
onStart: function(options) {
var router = new W.ScoreRouter();
var router = new W.ScoreRouter({application: this});
/** Starts the URL handling framework */
Backbone.history.start({
......
......@@ -6,10 +6,12 @@ window.W = window.W || {};
(function(undefined) {
'use strict';
W.ScoreController = {
W.ScoreController = Backbone.Marionette.Object.extend({
scoreList: function() {
var app = this.getOption('application');
// app.getRegion().empty();
var myListView = new W.ScoreListView();
myListView.render();
app.showView(myListView);
},
scoreCreate: function() {
var myBaseView = new W.BaseView();
......@@ -18,8 +20,10 @@ window.W = window.W || {};
scoreView: function(id) {
},
scoreEdit: function(id) {
var app = this.getOption('application');
// app.getRegion().empty();
var myBaseView = new W.BaseView({id: id});
myBaseView.render();
app.showView(myBaseView);
}
};
});
})();
......@@ -7,7 +7,7 @@ window.W = window.W || {};
'use strict';
W.ScoreRouter = Backbone.Marionette.AppRouter.extend({
controller: W.ScoreController,
// controller: W.ScoreController,
appRoutes: {
'': 'scoreList',
......@@ -15,5 +15,9 @@ window.W = window.W || {};
'(:id)/edit/': 'scoreEdit',
'(:id)/view/': 'scoreView',
},
initialize(options) {
this.controller = new W.ScoreController(options);
},
});
})();
......@@ -539,8 +539,6 @@ window.W = window.W || {};
W.BaseView = Backbone.Marionette.View.extend({
el: "body",
template: '#base-template',
regions: {
......@@ -559,7 +557,7 @@ window.W = window.W || {};
},
onRender: function() {
var scoreModel = new W.ScoreModel(this.options);
var scoreModel = W.ScoreModel.find(this.options) || new W.ScoreModel(this.options);
var sliderView = new W.SliderView({
model: scoreModel
});
......@@ -607,14 +605,39 @@ window.W = window.W || {};
var title = this.$el.find('[name="title"]').val();
var myModel = new W.ScoreModel();
myModel.save({title: title}, {success: function() {
Backbone.history.navigate('/' + myModel.id + '/edit/', {trigger: true});
}});
},
});
W.ScoreListView = Backbone.Marionette.View.extend({
template: '#score-list-template',
regions: {
list: '#list',
create: '#create'
},
onRender: function() {
var scoreCollection = new W.ScoreCollection();
var myListView = new W.ListView({collection: scoreCollection});
var myCreateView = new W.CreateView();
var that = this;
myListView.collection.fetch({
success: function() {
that.showChildView('list', myListView);
that.showChildView('create', myCreateView);
}
});
}
});
W.RootView = Backbone.Marionette.View.extend({
el: "body",
template: '#score-list-template',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment