Files
dss/static/js/app/views/mix/mixDetailView.js
2013-12-16 22:31:35 +00:00

96 lines
3.3 KiB
JavaScript

// 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(['marionette', 'utils', 'models/mix/mixItem', 'models/comment/commentItem', 'models/comment/commentCollection', 'views/comment/commentListView', 'views/mix/mixItemView', 'text!/tpl/MixDetailView', 'vent'], function(Marionette, utils, MixItem, CommentItem, CommentsCollection, CommentsListView, MixItemView, Template, vent) {
var MixDetailView;
return MixDetailView = (function(_super) {
__extends(MixDetailView, _super);
function MixDetailView() {
this.modelChanged = __bind(this.modelChanged, this);
return MixDetailView.__super__.constructor.apply(this, arguments);
}
MixDetailView.prototype.template = _.template(Template);
MixDetailView.prototype.regions = {
mix: "#mix",
comments: "#comments"
};
MixDetailView.prototype.ui = {
commentText: '#comment-text'
};
MixDetailView.prototype.events = {
"click #btn-add-comment": "addComment"
};
MixDetailView.prototype.initialize = function() {
return this.model.on('nested-change', this.modelChanged);
};
MixDetailView.prototype.onRender = function() {
var view;
view = new MixItemView({
tagName: "div",
className: "mix-listing audio-listing-single",
model: this.model
});
this.mix.show(view);
return this.renderComments();
};
MixDetailView.prototype.renderComments = function() {
var comments;
console.log("MixDetailView: Rendering comments");
comments = new CommentsCollection();
comments.url = this.model.get("resource_uri") + "/comments/";
comments.mix_id = this.model.id;
comments.mix = this.model;
comments.fetch({
success: function(data) {
var content;
content = new CommentsListView({
collection: comments
}).render();
$("#comments", this.el).html(content.el);
return true;
}
});
return true;
};
MixDetailView.prototype.modelChanged = function() {
console.log("MixDetailView: modelChanged");
return this.render();
};
MixDetailView.prototype.addComment = function() {
var activeTab, comment,
_this = this;
activeTab = $("ul#mix-tab li.active", this.el);
comment = this.ui.commentText.val();
this.model.addComment(comment, (function() {
_this.ui.commentText.val("");
utils.showMessage("Comment saved..");
return activeTab.tab().show();
}), function(error) {
utils.showError("Woops \n" + error);
$('#comment-input').addClass('has-error');
return $('#comment-text').focus();
});
return MixDetailView;
};
return MixDetailView;
})(Marionette.Layout);
});
}).call(this);