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/router.js
|
||||||
- public/javascripts/app/models/*
|
- public/javascripts/app/models/*
|
||||||
- public/javascripts/app/collections/*
|
- public/javascripts/app/collections/*
|
||||||
|
- public/javascripts/app/views/stream_object_view.js
|
||||||
- public/javascripts/app/views/*
|
- public/javascripts/app/views/*
|
||||||
|
|
||||||
- public/javascripts/rails.validations.js
|
- public/javascripts/rails.validations.js
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
App.Views.Comment = Backbone.View.extend({
|
App.Views.Comment = App.Views.StreamObject.extend({
|
||||||
events : {
|
|
||||||
"click .delete": "destroyComment"
|
|
||||||
},
|
|
||||||
|
|
||||||
initialize: function(options) {
|
template_name: "#comment-template",
|
||||||
this.model = options.model;
|
|
||||||
this.template = _.template($("#comment-template").html());
|
events : {
|
||||||
|
"click .delete:first": "destroyModel"
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
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()
|
this.delegateEvents(); //we need this because we are explicitly setting this.el in this.render()
|
||||||
|
|
||||||
return this;
|
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()
|
App.user()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
this.$("label").inFieldLabels();
|
||||||
|
|
||||||
this.model.comments.each(this.appendComment);
|
this.model.comments.each(this.appendComment);
|
||||||
|
|
||||||
return this;
|
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: {
|
events: {
|
||||||
"click .focus_comment_textarea": "focusCommentTextarea",
|
"click .focus_comment_textarea": "focusCommentTextarea",
|
||||||
"focus .comment_box": "commentTextareaFocused",
|
"focus .comment_box": "commentTextareaFocused",
|
||||||
"click .delete:first": "destroyPost"
|
"click .delete:first": "destroyModel"
|
||||||
},
|
|
||||||
|
|
||||||
initialize: function(options) {
|
|
||||||
this.model = options.model;
|
|
||||||
this.template = _.template($("#stream-element-template").html());
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
@ -27,7 +24,6 @@ App.Views.Post = Backbone.View.extend({
|
||||||
this.renderPostContent();
|
this.renderPostContent();
|
||||||
|
|
||||||
this.$(".details time").timeago();
|
this.$(".details time").timeago();
|
||||||
this.$("label").inFieldLabels();
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -52,19 +48,5 @@ App.Views.Post = Backbone.View.extend({
|
||||||
|
|
||||||
commentTextareaFocused: function(evt){
|
commentTextareaFocused: function(evt){
|
||||||
this.$("form").removeClass('hidden').addClass("open");
|
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/router.js
|
||||||
- public/javascripts/app/models/*
|
- public/javascripts/app/models/*
|
||||||
- public/javascripts/app/collections/*
|
- public/javascripts/app/collections/*
|
||||||
|
- public/javascripts/app/views/stream_object_view.js
|
||||||
- public/javascripts/app/views/*
|
- public/javascripts/app/views/*
|
||||||
|
|
||||||
- public/javascripts/mobile.js
|
- public/javascripts/mobile.js
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue