Commit cb113190 authored by alexandre's avatar alexandre

List + create views

parent b4366a7c
......@@ -8,9 +8,8 @@ window.W = window.W || {};
W.ScoreController = {
scoreList: function() {
var scoreCollection = new W.ScoreCollection();
var myListView = new W.ListView({collection: scoreCollection});
myListView.collection.fetch();
var myListView = new W.ScoreListView();
myListView.render();
},
scoreCreate: function() {
var myBaseView = new W.BaseView();
......
......@@ -556,7 +556,6 @@ window.W = window.W || {};
W.ListView = Backbone.Marionette.CollectionView.extend({
el: "body",
tagName: 'ol',
collection: W.ScoreCollection,
childView: W.ListItemView,
......@@ -565,4 +564,49 @@ window.W = window.W || {};
this.listenTo(this.collection, 'sync', this.render);
},
});
W.CreateView = Backbone.Marionette.View.extend({
template: '#create-template',
triggers: {
'submit .create-form': 'create'
},
onCreate: function(event) {
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({
el: "body",
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);
}
});
}
});
})();
......@@ -11,6 +11,18 @@
<link rel="stylesheet" href="http://meyerweb.com/eric/tools/css/reset/reset.css">
<link rel="stylesheet" href="{% static 'playground/css/styles.css' %}">
<script id="score-list-template" type="text/template">
<div id="list"></div>
<div id="create"></div>
</script>
<script id="create-template" type="text/template">
<form class="create-form" action="" method="post">
<input type="text" name="title" placeholder="title" required>
<input type="submit" name="submit" value="create">
</form>
</script>
<script id="list-item-template" type="text/template">
<a href="<%= id %>/edit/"><%= title %></a>
</script>
......
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