Commit 9935f780 authored by alexandre's avatar alexandre
Browse files

Oups, missing quite some files in my previous commit

parent 3474c232
......@@ -1304,6 +1304,24 @@ window.W = window.W || {};
});
W.SearchView = Backbone.Marionette.View.extend({
template: '#search-template',
triggers: {
'click .search': 'search',
},
onSearch: function(event) {
this.collection.queryParams.search = this.$el.find('.search-input').val();
this.collection.fetch();
},
// initialize: function (options) {
// this.listenTo(this.collection, 'sync', this.render);
// },
});
W.PaginationView = Backbone.Marionette.View.extend({
template: '#pagination-template',
......@@ -1366,6 +1384,7 @@ window.W = window.W || {};
template: '#score-list-template',
regions: {
search: '#search',
list: '#list',
pagination : '#pagination',
create: '#create'
......@@ -1375,7 +1394,6 @@ window.W = window.W || {};
document.title = 'Notation W';
var scoreCollection = new W.ScoreCollection([], {
// All the `state` and `queryParams` key value pairs are merged with
// the defaults too.
state: {
......@@ -1384,13 +1402,21 @@ window.W = window.W || {};
currentPage: 1,
sortKey: "created_at",
order: -1
}
},
// queryParams: {
// search: "Ménagerie"
// }
});
var myListView = new W.ListView({
collection: scoreCollection
});
var mySearchView = new W.SearchView({
collection: scoreCollection
});
var myPaginationView = new W.PaginationView({
collection: scoreCollection
});
......@@ -1401,6 +1427,7 @@ window.W = window.W || {};
myListView.collection.fetch({
success: function () {
that.showChildView('search', mySearchView);
that.showChildView('list', myListView);
that.showChildView('pagination', myPaginationView);
that.showChildView('create', myCreateView);
......
......@@ -15,6 +15,10 @@
{% include "playground/underscore/score-list.mtpl" %}
</script>
<script id="search-template" type="text/template">
{% include "playground/underscore/search.mtpl" %}
</script>
<script id="pagination-template" type="text/template">
{% include "playground/underscore/pagination.mtpl" %}
</script>
......
<div id="search"></div>
<div id="list"></div>
<div id="pagination"></div>
<div id="create"></div>
......@@ -2,7 +2,7 @@ from django.views.generic.base import TemplateView
from rest_framework import viewsets
from rest_framework.pagination import PageNumberPagination
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.filters import OrderingFilter
from rest_framework.filters import OrderingFilter, SearchFilter
# from django_filters.rest_framework import DjangoFilterBackend
from .models import Attachment, Score
from .serializers import AttachmentSerializer, ScoreSerializer
......@@ -31,7 +31,8 @@ class ScoreViewSet(viewsets.ModelViewSet):
queryset = Score.objects.all()
serializer_class = ScoreSerializer
pagination_class = ScoreViewSetPagination
filter_backends = (OrderingFilter,)
filter_backends = (OrderingFilter, SearchFilter)
search_fields = ('title',)
class ScoreView(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