Commit df35787f authored by alexandre's avatar alexandre
Browse files

Working App + Router.

http://localhost:8000/playground/score/ creates a new score
http://localhost:8000/playground/score/#3 loads score with id 3
parent 84e90f12
......@@ -43,6 +43,12 @@ window.W = window.W || {};
W.ScoreModel = Backbone.RelationalModel.extend({
defaults: {
title: "Untitled",
stage_set: "Here comes the initial set",
mainline: {}
},
urlRoot: '/api/scores/',
url: function() {
......@@ -85,6 +91,7 @@ window.W = window.W || {};
}
});
W.LineModel = Backbone.RelationalModel.extend({
defaults: {
sublines: [],
......@@ -131,6 +138,7 @@ window.W = window.W || {};
}]
});
W.LineCollection = Backbone.Collection.extend({
model: W.LineModel
});
......@@ -404,11 +412,12 @@ window.W = window.W || {};
}
},
initialize: function(options) {
this.options = options;
},
onRender: function() {
var scoreModel = new W.ScoreModel({
// sets the ID according to the path
id: parseInt(window.location.pathname.split("/")[3])
});
var scoreModel = new W.ScoreModel(this.options);
var sliderView = new W.SliderView({
model: scoreModel
});
......@@ -427,6 +436,33 @@ window.W = window.W || {};
}
});
var myBaseView = new W.BaseView();
myBaseView.render();
W.ScoreController = {
editScore: function(id) {
var params = {}
if (id) {params.id = id}
var myBaseView = new W.BaseView(params);
myBaseView.render();
}
};
W.ScoreRouter = Backbone.Marionette.AppRouter.extend({
controller: W.ScoreController,
appRoutes: {
'(:id)': 'editScore',
},
});
W.ScoreApp = new Backbone.Marionette.Application({
onStart: function(options) {
var router = new W.ScoreRouter();
/** Starts the URL handling framework */
Backbone.history.start();
}
});
var scoreApp = W.ScoreApp.start();
})();
......@@ -5,5 +5,6 @@ from playground.views import ScoreDetailView, SandboxView
urlpatterns = [
url(r'^sandbox/$', SandboxView.as_view(), name='sandbox'),
url(r'^score/(?P<pk>\d+)/$', ScoreDetailView.as_view(), name='score-detail'),
url(r'^score/', ScoreDetailView.as_view(), name='score-detail'),
# url(r'^score/(?P<pk>\d+)/$', ScoreDetailView.as_view(), name='score-detail'),
]
......@@ -13,10 +13,10 @@ class ScoreViewSet(viewsets.ModelViewSet):
serializer_class = ScoreSerializer
class ScoreDetailView(DetailView):
class ScoreDetailView(TemplateView):
"""
"""
model = Score
template_name = "playground/score_detail.html"
class SandboxView(TemplateView):
......
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