Files
dss/static/js/app/views/mix/mixItemView.js
2013-12-20 19:36:51 +00:00

169 lines
6.1 KiB
JavaScript
Executable File

// Generated by CoffeeScript 1.4.0
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
define(['moment', 'app', 'vent', 'marionette', 'utils', 'text!/tpl/MixListItemView'], function(moment, App, vent, Marionette, utils, Template) {
var MixItemView;
MixItemView = (function(_super) {
__extends(MixItemView, _super);
function MixItemView() {
this.doStart = __bind(this.doStart, this);
this.renderGenres = __bind(this.renderGenres, this);
this.onRender = __bind(this.onRender, this);
this.initialize = __bind(this.initialize, this);
return MixItemView.__super__.constructor.apply(this, arguments);
}
MixItemView.prototype.template = _.template(Template);
MixItemView.prototype.tagName = MixItemView.tagName || "li";
MixItemView.prototype.className = MixItemView.className || "";
MixItemView.prototype.events = {
"click .play-button-small-start": "doStart",
"click .play-button-small-resume": "doResume",
"click .play-button-small-pause": "doPause",
"click .mix-link": "mixLink",
"click .delete-button a": "mixDelete",
"click .like-button a": "mixLike",
"click .favourite-button a": "mixFavourite",
"click .share-button": "mixShare",
"click .download-button a": "mixDownload",
"click .login-download-button a": "login"
};
MixItemView.prototype.ui = {
playButton: ".play-button-small"
};
MixItemView.prototype.initialize = function() {
this.listenTo(this.model, 'change:favourited', this.render);
this.listenTo(this.model, 'change:liked', this.render);
this.listenTo(this.model, 'nested-change', this.render);
this.listenTo(vent, 'mix:play', this.mixPlay);
this.listenTo(vent, 'mix:pause', this.mixPause);
return true;
};
MixItemView.prototype.onRender = function() {
var id;
id = this.model.get('id');
if (this.model.get('duration')) {
$('#player-duration-' + id, this.el).text(this.model.secondsToHms('duration'));
}
this.renderGenres();
};
MixItemView.prototype.onShow = function() {
if (com.podnoms.player.isPlayingId(this.model.id)) {
com.podnoms.settings.setupPlayerWrapper(this.model.get('id'), com.podnoms.player.getStreamUrl(), this.el);
this.mixPlay(this.model);
}
return true;
};
MixItemView.prototype.renderGenres = function() {
var el;
el = this.el;
$.each(this.model.get("genres"), function(data) {
$("#genre-list", el).append('<a href="/mixes/' + this.slug + '" class="label label-info arrowed-right arrowed-in">' + this.description + '</a>');
return true;
});
return true;
};
MixItemView.prototype.doStart = function() {
console.log("MixItemView: mixStart");
this.ui.playButton.toggleClass('play-button-small-start', false).toggleClass('play-button-small-resume', false).toggleClass('play-button-small-pause', true);
vent.trigger('mix:init', this.model);
};
MixItemView.prototype.doPause = function() {
console.log("MixItemView: mixPause");
vent.trigger("mix:pause", this.model);
return true;
};
MixItemView.prototype.doResume = function() {
console.log("MixItemView: mixResume");
vent.trigger("mix:play", this.model);
return true;
};
MixItemView.prototype.mixPlay = function(model) {
if (this.model.get('id') === model.get('id')) {
this.ui.playButton.toggleClass('play-button-small-start', false).toggleClass('play-button-small-resume', false).toggleClass('play-button-small-pause', true);
}
};
MixItemView.prototype.mixPause = function(model) {
if (this.model.get('id') === model.get('id')) {
this.ui.playButton.toggleClass('play-button-small-start', false).toggleClass('play-button-small-resume', true).toggleClass('play-button-small-pause', false);
}
};
MixItemView.prototype.mixStop = function(model) {
if (this.model.get('id') === model.get('id')) {
this.ui.playButton.toggleClass('play-button-small-start', true).toggleClass('play-button-small-resume', false).toggleClass('play-button-small-pause', false);
}
};
MixItemView.prototype.mixFavourite = function() {
var app;
console.log("MixItemView: favouriteMix");
app = require('app');
vent.trigger("mix:favourite", this.model);
return true;
};
MixItemView.prototype.mixDelete = function() {
var _this = this;
console.log("MixItemView: mixDelete");
return utils.messageBox("/dlg/DeleteMixConfirm", function() {
return _this.model.destroy();
});
};
MixItemView.prototype.mixLike = function() {
console.log("MixItemView: likeMix");
vent.trigger("mix:like", this.model);
return true;
};
MixItemView.prototype.mixShare = function(e) {
var mode;
console.log("MixItemView: shareMix");
mode = $(e.currentTarget).data("mode");
console.log("MixItemView: " + mode);
vent.trigger("mix:share", mode, this.model);
return true;
};
MixItemView.prototype.mixDownload = function() {
console.log("MixItemView: mixDownload");
utils.downloadURL("/audio/download/" + this.model.get('id'));
return true;
};
MixItemView.prototype.login = function() {
console.log("MixItemView: login");
vent.trigger('app:login');
return true;
};
return MixItemView;
})(Marionette.ItemView);
return MixItemView;
});
}).call(this);