diff options
author | Dennis Collinson <dennis.collective@gmail.com> | 2012-03-24 03:50:13 +0400 |
---|---|---|
committer | Dennis Collinson <dennis.collective@gmail.com> | 2012-03-28 01:54:27 +0400 |
commit | 663abcb0aa8691a3ec6673287859b19a7e6a156d (patch) | |
tree | 5a19f6976ea95362a607d30c0aa7294f9e7b6e19 /public | |
parent | 2bb677b34ba6279db832bcf885a0bf1433c4965b (diff) |
MS DC Pull out stream post logic into own class
Diffstat (limited to 'public')
-rw-r--r-- | public/javascripts/app/pages/framer.js | 2 | ||||
-rw-r--r-- | public/javascripts/app/templates/stream-element.handlebars | 4 | ||||
-rw-r--r-- | public/javascripts/app/views/post_view.js | 124 | ||||
-rw-r--r-- | public/javascripts/app/views/stream_object_view.js | 3 | ||||
-rw-r--r-- | public/javascripts/app/views/stream_post_views.js | 102 | ||||
-rw-r--r-- | public/javascripts/app/views/stream_view.js | 2 |
6 files changed, 113 insertions, 124 deletions
diff --git a/public/javascripts/app/pages/framer.js b/public/javascripts/app/pages/framer.js index 1aee8f318..3939f832f 100644 --- a/public/javascripts/app/pages/framer.js +++ b/public/javascripts/app/pages/framer.js @@ -33,7 +33,7 @@ app.pages.Framer = app.views.Base.extend({ this._postView.feedbackView = new Backbone.View - this.model.authorIsNotCurrentUser = function(){ return false } + this.model.authorIsCurrentUser = function(){ return true } return this._postView }, diff --git a/public/javascripts/app/templates/stream-element.handlebars b/public/javascripts/app/templates/stream-element.handlebars index 2e0fe9a83..024c51a0b 100644 --- a/public/javascripts/app/templates/stream-element.handlebars +++ b/public/javascripts/app/templates/stream-element.handlebars @@ -2,7 +2,7 @@ {{#if current_user}} <div class="controls"> - {{#if authorIsNotCurrentUser}} + {{#unless authorIsCurrentUser}} <a href="#" rel=nofollow> <img src="{{imageUrl "/images/icons/ignoreuser.png"}}"" alt="Ignoreuser" class="block_user control_icon" title="{{t "ignore"}}" /> </a> @@ -13,7 +13,7 @@ <a href="#" rel=nofollow> <img src="{{imageUrl "/images/deletelabel.png"}}" class="delete control_icon remove_post" title="{{t "delete"}}" /> </a> - {{/if}} + {{/unless}} </div> {{/if}} diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 5900bf75c..bc6345e50 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -1,133 +1,21 @@ app.views.Post = app.views.StreamObject.extend({ - - templateName: "stream-element", - - className : "stream_element loaded", - - events: { - "click .focus_comment_textarea": "focusCommentTextarea", - "click .show_nsfw_post": "removeNsfwShield", - "click .toggle_nsfw_state": "toggleNsfwState", - - "click .remove_post": "destroyModel", - "click .hide_post": "hidePost", - "click .block_user": "blockUser" - }, - - subviews : { - ".feedback" : "feedbackView", - ".likes" : "likesInfoView", - ".comments" : "commentStreamView", - ".post-content" : "postContentView" - }, - - tooltipSelector : ".delete, .block_user, .post_scope", - initialize : function(options) { - // allow for a custom template name to be passed in via the options hash - this.templateName = options.templateName || this.templateName - - this.model.bind('remove', this.remove, this); - this.model.bind('destroy', this.destroy, this); - - //subviews - this.commentStreamView = new app.views.CommentStream({ model : this.model}); - - return this; - }, - - likesInfoView : function(){ - return new app.views.LikesInfo({ model : this.model}); - }, - - feedbackView : function(){ - if(!app.currentUser.authenticated()) { return null } - return new app.views.Feedback({model : this.model}); - }, - - postContentView: function(){ - var normalizedClass = this.model.get("post_type").replace(/::/, "__"); - var postClass = app.views[normalizedClass] || app.views.StatusMessage; - return new postClass({ model : this.model }); + this.templateName = options.templateName }, presenter : function() { return _.extend(this.defaultPresenter(), { - authorIsNotCurrentUser : this.authorIsNotCurrentUser(), + authorIsCurrentUser : this.authorIsCurrentUser(), showPost : this.showPost(), text : app.helpers.textFormatter(this.model) }) }, - showPost : function() { - return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw") - }, - - removeNsfwShield: function(evt){ - if(evt){ evt.preventDefault(); } - this.model.set({nsfw : false}) - this.render(); - }, - - toggleNsfwState: function(evt){ - if(evt){ evt.preventDefault(); } - app.currentUser.toggleNsfwState(); - }, - - blockUser: function(evt){ - if(evt) { evt.preventDefault(); } - if(!confirm("Ignore this user?")) { return } - - var personId = this.model.get("author").id; - var block = new app.models.Block(); - - block.save({block : {person_id : personId}}, { - success : function(){ - if(!app.stream) { return } - - _.each(app.stream.posts.models, function(model){ - if(model.get("author").id == personId) { - app.stream.posts.remove(model); - } - }) - } - }) - }, - - hidePost : function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t('confirm_dialog'))) { return } - - $.ajax({ - url : "/share_visibilities/42", - type : "PUT", - data : { - post_id : this.model.id - } - }) - - this.slideAndRemove(); - }, - - focusCommentTextarea: function(evt){ - evt.preventDefault(); - this.$(".new_comment_form_wrapper").removeClass("hidden"); - this.$(".comment_box").focus(); - - return this; + authorIsCurrentUser : function() { + return app.currentUser.authenticated() && this.model.get("author").id == app.user().id }, - authorIsNotCurrentUser : function() { - return this.model.get("author").id != app.user().id - }, - - isOnShowPage : function() { - return (!this.model.collection) && (this.model.url() == document.location.pathname); - }, - - destroy : function() { - if (this.isOnShowPage()) { - document.location.replace(Backbone.history.options.root); - } + showPost : function() { + return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw") } }); diff --git a/public/javascripts/app/views/stream_object_view.js b/public/javascripts/app/views/stream_object_view.js index 1f46e732b..42d7bc6d4 100644 --- a/public/javascripts/app/views/stream_object_view.js +++ b/public/javascripts/app/views/stream_object_view.js @@ -1,6 +1,5 @@ app.views.StreamObject = app.views.Base.extend({ - - destroyModel: function(evt) { + destroyModel: function(evt) { if (evt) { evt.preventDefault(); } diff --git a/public/javascripts/app/views/stream_post_views.js b/public/javascripts/app/views/stream_post_views.js new file mode 100644 index 000000000..5d955c54d --- /dev/null +++ b/public/javascripts/app/views/stream_post_views.js @@ -0,0 +1,102 @@ +app.views.StreamPost = app.views.Post.extend({ + templateName: "stream-element", + className : "stream_element loaded", + + subviews : { + ".feedback" : "feedbackView", + ".likes" : "likesInfoView", + ".comments" : "commentStreamView", + ".post-content" : "postContentView" + }, + + events: { + "click .focus_comment_textarea": "focusCommentTextarea", + "click .show_nsfw_post": "removeNsfwShield", + "click .toggle_nsfw_state": "toggleNsfwState", + + "click .remove_post": "destroyModel", + "click .hide_post": "hidePost", + "click .block_user": "blockUser" + }, + + tooltipSelector : ".delete, .block_user, .post_scope", + + initialize : function(){ + this.model.bind('remove', this.remove, this); + + //subviews + this.commentStreamView = new app.views.CommentStream({ model : this.model}); + }, + + + likesInfoView : function(){ + return new app.views.LikesInfo({ model : this.model}); + }, + + feedbackView : function(){ + if(!app.currentUser.authenticated()) { return null } + return new app.views.Feedback({model : this.model}); + }, + + postContentView: function(){ + var normalizedClass = this.model.get("post_type").replace(/::/, "__"); + var postClass = app.views[normalizedClass] || app.views.StatusMessage; + return new postClass({ model : this.model }); + }, + + removeNsfwShield: function(evt){ + if(evt){ evt.preventDefault(); } + this.model.set({nsfw : false}) + this.render(); + }, + + toggleNsfwState: function(evt){ + if(evt){ evt.preventDefault(); } + app.currentUser.toggleNsfwState(); + }, + + + blockUser: function(evt){ + if(evt) { evt.preventDefault(); } + if(!confirm("Ignore this user?")) { return } + + var personId = this.model.get("author").id; + var block = new app.models.Block(); + + block.save({block : {person_id : personId}}, { + success : function(){ + if(!app.stream) { return } + + _.each(app.stream.posts.models, function(model){ + if(model.get("author").id == personId) { + app.stream.posts.remove(model); + } + }) + } + }) + }, + + hidePost : function(evt) { + if(evt) { evt.preventDefault(); } + if(!confirm(Diaspora.I18n.t('confirm_dialog'))) { return } + + $.ajax({ + url : "/share_visibilities/42", + type : "PUT", + data : { + post_id : this.model.id + } + }) + + this.slideAndRemove(); + }, + + focusCommentTextarea: function(evt){ + evt.preventDefault(); + this.$(".new_comment_form_wrapper").removeClass("hidden"); + this.$(".comment_box").focus(); + + return this; + } + +})
\ No newline at end of file diff --git a/public/javascripts/app/views/stream_view.js b/public/javascripts/app/views/stream_view.js index a39892dd9..b17ae4c60 100644 --- a/public/javascripts/app/views/stream_view.js +++ b/public/javascripts/app/views/stream_view.js @@ -27,7 +27,7 @@ app.views.Stream = Backbone.View.extend({ }, addPost : function(post) { - var postView = new app.views.Post({ model: post }); + var postView = new app.views.StreamPost({ model: post }); $(this.el)[ (this.collection.at(0).id == post.id) |