/Src/Bowerbird.Website/js/bowerbird/views/commentCompositeView.js

https://github.com/Bowerbird/bowerbird-web · JavaScript · 66 lines · 41 code · 15 blank · 10 comment · 0 complexity · 6b64c148c6743ce7396561e55d041452 MD5 · raw file

  1. /// <reference path="../../libs/log.js" />
  2. /// <reference path="../../libs/require/require.js" />
  3. /// <reference path="../../libs/jquery/jquery-1.7.2.js" />
  4. /// <reference path="../../libs/underscore/underscore.js" />
  5. /// <reference path="../../libs/backbone/backbone.js" />
  6. /// <reference path="../../libs/backbone.marionette/backbone.marionette.js" />
  7. // CommentItemView
  8. // ---------------
  9. // Shows an individual project item
  10. define(['jquery', 'underscore', 'backbone', 'app', 'ich', 'views/commentformview', 'models/comment'],
  11. function ($, _, Backbone, app, ich, CommentFormView, Comment) {
  12. var CommentCompositeView = Backbone.Marionette.CompositeView.extend({
  13. tagName: 'li',
  14. className: 'comment-item',
  15. template: 'CommentItem',
  16. itemView: CommentCompositeView,
  17. events: {
  18. 'click .reply-button': 'addReply',
  19. 'click .save-reply-button': 'saveReply',
  20. 'click .cancel-reply-button': 'cancelReply'
  21. },
  22. initialize: function (options) {
  23. //this.Comments = options.Comment.Comments;
  24. },
  25. serializeData: function () {
  26. return this.model.toJSON();
  27. },
  28. onRender: function () {
  29. log('commentCompositeView.onRender');
  30. this.$el.find('.reply').append(ich.ReplyForm());
  31. },
  32. addReply: function (e) {
  33. e.preventDefault();
  34. var model = new Comment({ ContributionId: this.model.get('ContributionId'), ParentCommentId: this.model.id, IsNested: true });
  35. this.$el.find('.reply').empty().append(ich.PostReplyForm());
  36. },
  37. saveReply: function (e) {
  38. var model = new Comment({
  39. ContributionId: this.model.get('ContributionId'),
  40. ParentCommentId: this.model.id,
  41. IsNested: true,
  42. Message: this.$el.find('.add-reply-text').val()
  43. });
  44. model.save();
  45. },
  46. cancelReply: function (e) {
  47. this.$el.find('.reply').empty().append(ich.ReplyForm());
  48. }
  49. });
  50. return CommentCompositeView;
  51. });