Commit 80ba3b3f by Tom Giannattasio

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into…

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into feature/tomg/new-discussions
parents fde33678 513b0606
...@@ -8,7 +8,6 @@ DiscussionApp = ...@@ -8,7 +8,6 @@ DiscussionApp =
threads = element.data("threads") threads = element.data("threads")
content_info = element.data("content-info") content_info = element.data("content-info")
window.user = new DiscussionUser(user_info) window.user = new DiscussionUser(user_info)
console.log content_info
Content.loadContentInfos(content_info) Content.loadContentInfos(content_info)
discussion = new Discussion(threads) discussion = new Discussion(threads)
new DiscussionRouter({discussion: discussion}) new DiscussionRouter({discussion: discussion})
......
class @DiscussionContentView extends Backbone.View class @DiscussionContentView extends Backbone.View
partialRenderer: attrRenderer:
endorsed: (endorsed) -> endorsed: (endorsed) ->
if endorsed
@$(".action-endorse").addClass("is-endorsed")
else
@$(".action-endorse").removeClass("is-endorsed")
closed: (closed) -> # we should just re-render the whole thread, or update according to new abilities closed: (closed) ->
return if not @$(".action-openclose").length
return if not @$(".post-status-closed").length
if closed
@$(".post-status-closed").show()
@$(".action-openclose").html(@$(".action-openclose").html().replace("Close", "Open"))
@$(".discussion-reply-new").hide()
else
@$(".post-status-closed").hide()
@$(".action-openclose").html(@$(".action-openclose").html().replace("Open", "Close"))
@$(".discussion-reply-new").show()
voted: (voted) -> voted: (voted) ->
if voted
@$(".discussion-vote").addClass("is-cast")
else
@$(".discussion-vote").removeClass("is-cast")
votes_point: (votes_point) -> votes_point: (votes_point) ->
@$(".discussion-vote .votes-count-number").html(votes_point)
comments_count: (comments_count) -> comments_count: (comments_count) ->
...@@ -23,7 +32,6 @@ class @DiscussionContentView extends Backbone.View ...@@ -23,7 +32,6 @@ class @DiscussionContentView extends Backbone.View
@$(".dogear").removeClass("is-followed") @$(".dogear").removeClass("is-followed")
ability: (ability) -> ability: (ability) ->
console.log "ability changed"
for action, selector of @abilityRenderer for action, selector of @abilityRenderer
if not ability[action] if not ability[action]
selector.disable.apply(@) selector.disable.apply(@)
...@@ -40,12 +48,19 @@ class @DiscussionContentView extends Backbone.View ...@@ -40,12 +48,19 @@ class @DiscussionContentView extends Backbone.View
can_endorse: can_endorse:
enable: -> @$(".action-endorse").css("cursor", "auto") enable: -> @$(".action-endorse").css("cursor", "auto")
disable: -> @$(".action-endorse").css("cursor", "default") disable: -> @$(".action-endorse").css("cursor", "default")
can_openclose:
enable: -> @$(".action-openclose").closest("li").show()
disable: -> @$(".action-openclose").closest("li").hide()
renderPartial: -> renderPartialAttrs: ->
console.log "changed"
for attr, value of @model.changedAttributes() for attr, value of @model.changedAttributes()
if @partialRenderer[attr] if @attrRenderer[attr]
@partialRenderer[attr].apply(@, [value]) @attrRenderer[attr].apply(@, [value])
renderAttrs: ->
for attr, value of @model.attributes
if @attrRenderer[attr]
@attrRenderer[attr].apply(@, [value])
initialize: -> initialize: ->
@model.bind('change', @renderPartial, @) @model.bind('change', @renderPartialAttrs, @)
class @DiscussionThreadView extends DiscussionContentView class @DiscussionThreadView extends DiscussionContentView
abilityRenderer:
editable:
enable: -> @$(".action-edit").closest("li").show()
disable: -> @$(".action-edit").closest("li").hide()
can_delete:
enable: -> @$(".action-delete").closest("li").show()
disable: -> @$(".action-delete").closest("li").hide()
can_endorse:
enable: ->
@$(".action-endorse").css("cursor", "auto")
disable: ->
@$(".action-endorse").css("cursor", "default")
events: events:
"click .discussion-vote": "toggleVote" "click .discussion-vote": "toggleVote"
"click .action-follow": "toggleFollowing" "click .action-follow": "toggleFollowing"
"click .discussion-submit-post": "submitComment" "click .discussion-submit-post": "submitComment"
"click .action-edit": "edit" "click .action-edit": "edit"
"click .action-delete": "delete" "click .action-delete": "delete"
"click .action-openclose": "toggleClosed"
template: _.template($("#thread-template").html()) template: _.template($("#thread-template").html())
initialize: -> initialize: ->
super()
@model.on "change", @updateModelDetails @model.on "change", @updateModelDetails
render: -> render: ->
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
@renderDogear() @renderDogear()
@renderVoted() @renderVoted()
@renderAttrs()
@$("span.timeago").timeago() @$("span.timeago").timeago()
Markdown.makeWmdEditor @$(".reply-body"), "", DiscussionUtil.urlFor("upload"), (text) -> DiscussionUtil.postMathJaxProcessor(text) Markdown.makeWmdEditor @$(".reply-body"), "", DiscussionUtil.urlFor("upload"), (text) -> DiscussionUtil.postMathJaxProcessor(text)
@convertMath() @convertMath()
...@@ -135,7 +125,21 @@ class @DiscussionThreadView extends DiscussionContentView ...@@ -135,7 +125,21 @@ class @DiscussionThreadView extends DiscussionContentView
delete: -> delete: ->
toggleEndorse: -> toggleClosed: (event) ->
$elem = $(event.target)
url = @model.urlFor('close')
closed = @model.get('closed')
data = { closed: not closed }
DiscussionUtil.safeAjax
$elem: $elem
url: url
data: data
type: "POST"
success: (response, textStatus) =>
@model.set('closed', not closed)
@model.set('ability', response.ability)
toggleEndorse: (event) ->
$elem = $(event.target) $elem = $(event.target)
url = @model.urlFor('endorse') url = @model.urlFor('endorse')
endorsed = @model.get('endorsed') endorsed = @model.get('endorsed')
......
...@@ -3,6 +3,7 @@ class @ResponseCommentView extends DiscussionContentView ...@@ -3,6 +3,7 @@ class @ResponseCommentView extends DiscussionContentView
template: _.template($("#response-comment-template").html()) template: _.template($("#response-comment-template").html())
render: -> render: ->
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
@renderAttrs()
@$(".timeago").timeago() @$(".timeago").timeago()
@convertMath() @convertMath()
@ @
......
...@@ -11,6 +11,7 @@ class @ThreadResponseView extends DiscussionContentView ...@@ -11,6 +11,7 @@ class @ThreadResponseView extends DiscussionContentView
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
if window.user.voted(@model) if window.user.voted(@model)
@$(".vote-btn").addClass("is-cast") @$(".vote-btn").addClass("is-cast")
@renderAttrs()
@$(".posted-details").timeago() @$(".posted-details").timeago()
@convertMath() @convertMath()
@renderComments() @renderComments()
......
...@@ -13,14 +13,13 @@ ...@@ -13,14 +13,13 @@
<div class="post-body"> <div class="post-body">
${'<%- body %>'} ${'<%- body %>'}
</div> </div>
<div class="post-status"> <div class="post-status-closed" style="display: none">
${'<% if (closed) { %>'} This thread is closed.
This thread is closed.
${'<% } %>'}
</div> </div>
<ul class="moderator-actions"> <ul class="moderator-actions">
<li style="display: none"><a class="action-edit" href="javascript:void(0)"><span class="edit-icon"></span> Edit</a></li> <li style="display: none"><a class="action-edit" href="javascript:void(0)"><span class="edit-icon"></span> Edit</a></li>
<li style="display: none"><a class="action-delete" href="javascript:void(0)"><span class="delete-icon"></span> Delete</a></li> <li style="display: none"><a class="action-delete" href="javascript:void(0)"><span class="delete-icon"></span> Delete</a></li>
<li style="display: none"><a class="action-openclose" href="javascript:void(0)"><span class="edit-icon"></span> Close</a></li>
</ul> </ul>
</div> </div>
<ol class="responses"> <ol class="responses">
...@@ -60,4 +59,4 @@ ...@@ -60,4 +59,4 @@
<script type="text/template" id="thread-list-item-template"> <script type="text/template" id="thread-list-item-template">
<a href="${'<%- id %>'}" data-id="${'<%- id %>'}"><span class="title">${"<%- title %>"}</span> <span class="comments-count">${"<%- comments_count %>"}</span><span class="votes-count">+${"<%- votes['up_count'] %>"}</span></a> <a href="${'<%- id %>'}" data-id="${'<%- id %>'}"><span class="title">${"<%- title %>"}</span> <span class="comments-count">${"<%- comments_count %>"}</span><span class="votes-count">+${"<%- votes['up_count'] %>"}</span></a>
</script> </script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment