diff options
author | Steffen van Bergerem <svbergerem@online.de> | 2016-08-30 17:21:10 +0300 |
---|---|---|
committer | Dennis Schubert <mail@dennis-schubert.de> | 2016-09-04 04:16:24 +0300 |
commit | 8faedd574d77830c8af08e89b92432fc4161db31 (patch) | |
tree | 9416ba555222b9721ce06920e50e2b2ba90575fb /app/assets | |
parent | 68045cec8c7a27ba4dc1f4d2ecb330ed3a5ed61a (diff) |
Move post controls to a separate view
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/app/views/post_controls_view.js | 78 | ||||
-rw-r--r-- | app/assets/javascripts/app/views/stream_post_views.js | 86 | ||||
-rw-r--r-- | app/assets/templates/post-controls_tpl.jst.hbs | 24 | ||||
-rw-r--r-- | app/assets/templates/stream-element_tpl.jst.hbs | 29 |
4 files changed, 117 insertions, 100 deletions
diff --git a/app/assets/javascripts/app/views/post_controls_view.js b/app/assets/javascripts/app/views/post_controls_view.js new file mode 100644 index 000000000..796e8565a --- /dev/null +++ b/app/assets/javascripts/app/views/post_controls_view.js @@ -0,0 +1,78 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +app.views.PostControls = app.views.Base.extend({ + templateName: "post-controls", + className: "control-icons", + + events: { + "click .remove_post": "destroyModel", + "click .hide_post": "hidePost", + "click .post_report": "report", + "click .block_user": "blockUser", + "click .create_participation": "createParticipation", + "click .destroy_participation": "destroyParticipation" + }, + + tooltipSelector: [".post_report", + ".block_user", + ".delete", + ".create_participation", + ".destroy_participation"].join(", "), + + initialize: function(opts) { + this.model.bind("change", this.render, this); + this.post = opts.post; + }, + + presenter: function() { + return _.extend(this.defaultPresenter(), { + authorIsCurrentUser: app.currentUser.isAuthorOf(this.model) + }); + }, + + blockUser: function(evt) { + if (evt) { evt.preventDefault(); } + if (!confirm(Diaspora.I18n.t("ignore_user"))) { return; } + + this.model.blockAuthor().fail(function() { + app.flashMessages.error(Diaspora.I18n.t("ignore_failed")); + }); + }, + + hidePost: function(evt) { + if (evt) { evt.preventDefault(); } + if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; } + + var self = this; + $.ajax({ + url: Routes.shareVisibility(42), + type: "PUT", + data: { + /* eslint-disable camelcase */ + post_id: this.model.id + /* eslint-enable camelcase */ + } + }).done(function() { + self.post.remove(); + }).fail(function() { + app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); + }); + }, + + createParticipation: function(evt) { + if (evt) { evt.preventDefault(); } + var that = this; + $.post(Routes.postParticipation(this.model.get("id")), {}, function() { + that.model.set({participation: true}); + }); + }, + + destroyParticipation: function(evt) { + if (evt) { evt.preventDefault(); } + var that = this; + $.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() { + that.model.set({participation: false}); + }); + } +}); +// @license-end diff --git a/app/assets/javascripts/app/views/stream_post_views.js b/app/assets/javascripts/app/views/stream_post_views.js index b298cd0ad..60812f6b9 100644 --- a/app/assets/javascripts/app/views/stream_post_views.js +++ b/app/assets/javascripts/app/views/stream_post_views.js @@ -5,38 +5,26 @@ app.views.StreamPost = app.views.Post.extend({ className : "stream_element loaded", subviews : { - ".feedback" : "feedbackView", - ".likes" : "likesInfoView", - ".reshares" : "resharesInfoView", - ".comments" : "commentStreamView", - ".post-content" : "postContentView", - ".oembed" : "oEmbedView", - ".opengraph" : "openGraphView", - ".poll" : "pollView", - ".status-message-location" : "postLocationStreamView" + ".feedback": "feedbackView", + ".comments": "commentStreamView", + ".likes": "likesInfoView", + ".reshares": "resharesInfoView", + ".post-controls": "postControlsView", + ".post-content": "postContentView", + ".oembed": "oEmbedView", + ".opengraph": "openGraphView", + ".poll": "pollView", + ".status-message-location": "postLocationStreamView" }, 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 .post_report": "report", - "click .block_user": "blockUser", - - "click .create_participation": "createParticipation", - "click .destroy_participation": "destroyParticipation" + "click .toggle_nsfw_state": "toggleNsfwState" }, tooltipSelector : [".timeago", ".post_scope", - ".post_report", - ".block_user", - ".delete", - ".create_participation", - ".destroy_participation", ".permalink"].join(", "), initialize : function(){ @@ -51,6 +39,9 @@ app.views.StreamPost = app.views.Post.extend({ this.pollView = new app.views.Poll({model : this.model}); }, + postControlsView: function() { + return new app.views.PostControls({model: this.model, post: this}); + }, likesInfoView : function(){ return new app.views.LikesInfo({model : this.model}); @@ -87,60 +78,12 @@ app.views.StreamPost = app.views.Post.extend({ app.currentUser.toggleNsfwState(); }, - - blockUser: function(evt){ - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("ignore_user"))) { return } - - this.model.blockAuthor() - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("ignore_failed")); - }); - }, - remove : function() { $(this.el).slideUp(400, _.bind(function(){this.$el.remove()}, this)); app.stream.remove(this.model); return this; }, - hidePost : function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("confirm_dialog"))) { return } - - var self = this; - $.ajax({ - url : "/share_visibilities/42", - type : "PUT", - data : { - post_id : this.model.id - } - }).done(function() { - self.remove(); - }) - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); - }); - }, - - createParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var that = this; - $.post(Routes.postParticipation(this.model.get("id")), {}, function () { - that.model.set({participation: true}); - that.render(); - }); - }, - - destroyParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var that = this; - $.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () { - that.model.set({participation: false}); - that.render(); - }); - }, - focusCommentTextarea: function(evt){ evt.preventDefault(); this.$(".new-comment-form-wrapper").removeClass("hidden"); @@ -148,6 +91,5 @@ app.views.StreamPost = app.views.Post.extend({ return this; } - }); // @license-end diff --git a/app/assets/templates/post-controls_tpl.jst.hbs b/app/assets/templates/post-controls_tpl.jst.hbs new file mode 100644 index 000000000..560f366f4 --- /dev/null +++ b/app/assets/templates/post-controls_tpl.jst.hbs @@ -0,0 +1,24 @@ +{{#if authorIsCurrentUser}} + <a href="#" rel="nofollow" class="delete remove_post" title="{{t "delete"}}"> + <i class="entypo-trash"></i> + </a> +{{else}} + <a href="#" rel="nofollow" data-type="Post" class="post_report" title="{{t "report.name"}}"> + <i class="entypo-warning"></i> + </a> + <a href="#" rel="nofollow" class="block_user" title="{{t "ignore"}}"> + <i class="entypo-block"></i> + </a> + {{#if participation}} + <a href="#" rel="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}"> + <i class="entypo-bell"></i> + </a> + {{else}} + <a href="#" rel="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}"> + <i class="entypo-bell"></i> + </a> + {{/if}} + <a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}"> + <i class="entypo-cross"></i> + </a> +{{/if}} diff --git a/app/assets/templates/stream-element_tpl.jst.hbs b/app/assets/templates/stream-element_tpl.jst.hbs index 2520c1e67..2c65c427a 100644 --- a/app/assets/templates/stream-element_tpl.jst.hbs +++ b/app/assets/templates/stream-element_tpl.jst.hbs @@ -7,34 +7,7 @@ <div class="bd"> {{#if loggedIn}} - <div class="control-icons"> - {{#unless preview}} - {{#if authorIsCurrentUser}} - <a href="#" rel="nofollow" class="delete remove_post" title="{{t "delete"}}"> - <i class="entypo-trash"></i> - </a> - {{else}} - <a href="#" rel="nofollow" data-type="Post" class="post_report" title="{{t "report.name"}}"> - <i class="entypo-warning"></i> - </a> - <a href="#" rel="nofollow" class="block_user" title="{{t "ignore"}}"> - <i class="entypo-block"></i> - </a> - {{#if participation}} - <a href="#" rel="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}"> - <i class="entypo-bell"></i> - </a> - {{else}} - <a href="#" rel="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}"> - <i class="entypo-bell"></i> - </a> - {{/if}} - <a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}"> - <i class="entypo-cross"></i> - </a> - {{/if}} - {{/unless}} - </div> + <div class="post-controls"></div> {{/if}} <div> |