1
0
mirror of https://github.com/2ec0b4/kaamelott-soundboard.git synced 2025-12-08 23:53:24 +00:00
Files
kaamelott-soundboard/js/app/views/sounds.js
2016-04-10 21:57:43 +02:00

62 lines
1.8 KiB
JavaScript

define(
'views/sounds',
[
'marionette',
'backbone.radio',
'underscore',
'collections/sounds',
'hbs!templates/sounds'
],
function (Marionette, Radio, _, SoundsCollection, SoundListTemplate) {
"use strict";
var SoundListView = Marionette.LayoutView.extend({
collection: new SoundsCollection(),
template: SoundListTemplate,
ui: {
soundItem: 'li a'
},
events: {
'click @ui.soundItem': 'playSound'
},
initialize: function() {
var that = this;
this.data = {};
this.channel = Radio.channel('Sounds');
this.channel.request('getSounds')
.then(function(sounds) {
that.collection = new SoundsCollection(sounds);
that.data.sounds = that.collection.toJSON();
that.render();
});
},
playSound: function(e) {
var index = $(e.currentTarget).attr('data-sound'),
sound = this.collection.at(index);
e.preventDefault();
this.stopCurrentPlay();
if( sound ) {
this.currentPlay = sound.play();
}
},
stopCurrentPlay: function() {
if( this.currentPlay && !this.currentPlay.paused ) {
this.currentPlay.pause();
}
},
serializeData: function () {
var viewData = {data: this.data};
return _.extend(viewData, Marionette.LayoutView.prototype.serializeData.apply(this, arguments));
}
});
return SoundListView;
});