make views associated in stream inherit from App.Views.StreamObject (location of shared deletion function)
This commit is contained in:
parent
f5172fa977
commit
525fd3c4e4
6 changed files with 30 additions and 42 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
17
public/javascripts/app/views/stream_object_view.js
Normal file
17
public/javascripts/app/views/stream_object_view.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue