Commit 525fd3c4 authored by danielgrippi's avatar danielgrippi Committed by Dennis Collinson

make views associated in stream inherit from App.Views.StreamObject (location...

make views associated in stream inherit from App.Views.StreamObject (location of shared deletion function)
parent f5172fa9
......@@ -19,6 +19,7 @@ javascripts:
- public/javascripts/app/router.js
- public/javascripts/app/models/*
- public/javascripts/app/collections/*
- public/javascripts/app/views/stream_object_view.js
- public/javascripts/app/views/*
- public/javascripts/rails.validations.js
......
App.Views.Comment = Backbone.View.extend({
events : {
"click .delete": "destroyComment"
},
App.Views.Comment = App.Views.StreamObject.extend({
initialize: function(options) {
this.model = options.model;
this.template = _.template($("#comment-template").html());
template_name: "#comment-template",
events : {
"click .delete:first": "destroyModel"
},
render: function() {
......@@ -17,18 +15,5 @@ App.Views.Comment = Backbone.View.extend({
this.delegateEvents(); //we need this because we are explicitly setting this.el in this.render()
return this;
},
// NOTE: pull this out into a base class
destroyComment: function(evt) {
if(evt) { evt.preventDefault() }
var domElement = this.el;
this.model.destroy({
success: function(){
$(domElement).remove();
}
});
}
});
......@@ -19,6 +19,8 @@ App.Views.CommentStream = Backbone.View.extend({
App.user()
)));
this.$("label").inFieldLabels();
this.model.comments.each(this.appendComment);
return this;
......
App.Views.Post = Backbone.View.extend({
App.Views.Post = App.Views.StreamObject.extend({
template_name: "#stream-element-template",
events: {
"click .focus_comment_textarea": "focusCommentTextarea",
"focus .comment_box": "commentTextareaFocused",
"click .delete:first": "destroyPost"
},
initialize: function(options) {
this.model = options.model;
this.template = _.template($("#stream-element-template").html());
"click .delete:first": "destroyModel"
},
render: function() {
......@@ -27,7 +24,6 @@ App.Views.Post = Backbone.View.extend({
this.renderPostContent();
this.$(".details time").timeago();
this.$("label").inFieldLabels();
return this;
},
......@@ -52,19 +48,5 @@ App.Views.Post = Backbone.View.extend({
commentTextareaFocused: function(evt){
this.$("form").removeClass('hidden').addClass("open");
},
// NOTE: pull this out into a base class
destroyPost: function(evt){
if(evt){ evt.preventDefault(); }
var domElement = this.el;
this.model.destroy({
success: function(){
$(domElement).remove();
}
});
}
});
App.Views.StreamObject = Backbone.View.extend({
initialize: function(options) {
this.model = options.model;
this.template = _.template($(this.template_name).html());
},
destroyModel: function(evt){
if(evt){ evt.preventDefault(); }
var domElement = this.el;
this.model.destroy({
success: function(){
$(domElement).remove();
}
});
}
});
......@@ -40,6 +40,7 @@ src_files:
- public/javascripts/app/router.js
- public/javascripts/app/models/*
- public/javascripts/app/collections/*
- public/javascripts/app/views/stream_object_view.js
- public/javascripts/app/views/*
- public/javascripts/mobile.js
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment