Skip to content

Commit

Permalink
Disable publish when no track. Move sound mgr out of model.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandahl committed May 12, 2012
1 parent d94da0b commit 0747248
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 50 deletions.
48 changes: 0 additions & 48 deletions public/js/models/track.js
@@ -1,52 +1,4 @@

var Track = Backbone.Model.extend({

getSoundMgr: function($el, cb, onprogress) {
var snd = this.get('snd');

if (snd) {
cb(snd);
return;
}

var self = this;

$el.attr('data-state', 'loading');

$.getJSON('/play/' + this.get('id'), function(data) {

snd = soundManager.createSound({
id: self.get('id'),
url: data.url,
whileloading: onprogress || function(){},
onfinish: function() {
App.setSnd(null);
$el.attr('data-state', 'paused');
},
onpause: function() {
App.setSnd(null);
$el.attr('data-state', 'paused');
},
onplay: function() {
App.setSnd(snd);
$el.attr('data-state', 'playing');
},
onresume: function() {
App.setSnd(snd);
$el.attr('data-state', 'playing');
},
onstop: function() {
App.setSnd(null);
$el.attr('data-state', 'paused');
}
});

self.set('snd', snd, {silent: true});

cb(snd);
});

// SndMgr.ready( SndMgr.createSound(… ( this.set('snd', snd); cb(snd) )) )
}

});
6 changes: 6 additions & 0 deletions public/js/views/editor.js
Expand Up @@ -23,6 +23,8 @@ var Editor = Backbone.View.extend({

this.$list = this.$el.find('.playlist');

this.$publish = this.$el.find('.publish');

},

render: function() {
Expand All @@ -40,6 +42,10 @@ var Editor = Backbone.View.extend({

});

if (this.collection.length)
this.$publish.removeClass('disabled');
else
this.$publish.addClass('disabled');

},

Expand Down
54 changes: 52 additions & 2 deletions public/js/views/trackentry.js
Expand Up @@ -19,6 +19,7 @@ var TrackEntry = Backbone.View.extend({
'<div class="pull-left"><strong><%= title %></strong><%= artist %></div><div style="clear: both"></div><small class="duration"><%= duration %></small>'), // load jQuery template

initialize: function() {
this.snd = null;
},

render: function(search) {
Expand All @@ -32,7 +33,7 @@ var TrackEntry = Backbone.View.extend({
evt.stopImmediatePropagation();

// Loading state?
this.model.getSoundMgr(this.$el, function(snd) {
this.getSoundMgr(function(snd) {

snd.play();

Expand All @@ -44,7 +45,7 @@ var TrackEntry = Backbone.View.extend({

evt.stopImmediatePropagation();

this.model.getSoundMgr(this.$el, function(snd) {
this.getSoundMgr(function(snd) {

snd.pause();

Expand All @@ -64,6 +65,55 @@ var TrackEntry = Backbone.View.extend({

App.editorView.collection.add(this.model);
App.searchView.reset();
},

getSoundMgr: function(cb, onprogress) {
var snd = this.snd;

if (snd) {
cb(snd);
return;
}

var self = this;

$el = this.$el;
$el.attr('data-state', 'loading');

var id = this.model.get('id');

$.getJSON('/play/' + id, function(data) {

snd = soundManager.createSound({
id: id,
url: data.url,
whileloading: onprogress || function(){},
onfinish: function() {
App.setSnd(null);
$el.attr('data-state', 'paused');
},
onpause: function() {
App.setSnd(null);
$el.attr('data-state', 'paused');
},
onplay: function() {
App.setSnd(snd);
$el.attr('data-state', 'playing');
},
onresume: function() {
App.setSnd(snd);
$el.attr('data-state', 'playing');
},
onstop: function() {
App.setSnd(null);
$el.attr('data-state', 'paused');
}
});

self.snd = snd;

cb(snd);
});
}

});

0 comments on commit 0747248

Please sign in to comment.