From fda6b1fa36bf1e06f4dfa08d051253cbd6c80900 Mon Sep 17 00:00:00 2001 From: Antoine Date: Tue, 12 Apr 2016 22:42:50 +0200 Subject: [PATCH] Finalise le filtre des sons --- js/app/collections/sounds.js | 2 +- js/app/views/sounds.js | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/js/app/collections/sounds.js b/js/app/collections/sounds.js index fbf6ff0..f086779 100644 --- a/js/app/collections/sounds.js +++ b/js/app/collections/sounds.js @@ -16,7 +16,7 @@ define( return this; } - var pattern = new RegExp('^'+search, 'gi'); + var pattern = new RegExp(search, 'gi'); return new Sounds(this.filter(function(data) { return pattern.test(data.get('title')); })); diff --git a/js/app/views/sounds.js b/js/app/views/sounds.js index c1f3a76..1161283 100644 --- a/js/app/views/sounds.js +++ b/js/app/views/sounds.js @@ -20,22 +20,24 @@ define( initialize: function() { var that = this; - this.data = {}; + this.data = { + collection: this.collection + }; this.channel = Radio.channel('Sounds'); - this.channel.request('getSounds') - .then(function(sounds) { - that.collection = new SoundsCollection(sounds); - that.data.sounds = that.collection.toJSON(); + this.channel.request('getSounds').then(this.initCollection.bind(this)); + this.channel.on('sounds:filter', this.filterCollection.bind(this)); + }, + initCollection: function(sounds) { + this.data.collection = new SoundsCollection(sounds); + this.collection = this.data.collection; - that.render(); - }); + this.render(); + }, + filterCollection: function(search) { + this.collection = this.data.collection.filterByTitle(search); - this.channel.on('sounds:filter', function(search) { - that.data.sounds = that.collection.filterByTitle(search).toJSON(); - - that.render(); - }); + this.render(); }, stopPlayingSound: function() { var playingSound = this.collection.findWhere({playing: true}); @@ -43,11 +45,6 @@ define( if( playingSound ) { playingSound.stop(); } - }, - serializeData: function () { - var viewData = {data: this.data}; - - return _.extend(viewData, Marionette.CollectionView.prototype.serializeData.apply(this, arguments)); } });