Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into feature/tomg/new-discussions
This commit is contained in:
@@ -8,7 +8,6 @@ DiscussionApp =
|
||||
threads = element.data("threads")
|
||||
content_info = element.data("content-info")
|
||||
window.user = new DiscussionUser(user_info)
|
||||
console.log content_info
|
||||
Content.loadContentInfos(content_info)
|
||||
discussion = new Discussion(threads)
|
||||
new DiscussionRouter({discussion: discussion})
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
class @DiscussionContentView extends Backbone.View
|
||||
|
||||
partialRenderer:
|
||||
attrRenderer:
|
||||
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) ->
|
||||
if voted
|
||||
@$(".discussion-vote").addClass("is-cast")
|
||||
else
|
||||
@$(".discussion-vote").removeClass("is-cast")
|
||||
|
||||
votes_point: (votes_point) ->
|
||||
@$(".discussion-vote .votes-count-number").html(votes_point)
|
||||
|
||||
comments_count: (comments_count) ->
|
||||
|
||||
@@ -23,7 +32,6 @@ class @DiscussionContentView extends Backbone.View
|
||||
@$(".dogear").removeClass("is-followed")
|
||||
|
||||
ability: (ability) ->
|
||||
console.log "ability changed"
|
||||
for action, selector of @abilityRenderer
|
||||
if not ability[action]
|
||||
selector.disable.apply(@)
|
||||
@@ -40,12 +48,19 @@ class @DiscussionContentView extends Backbone.View
|
||||
can_endorse:
|
||||
enable: -> @$(".action-endorse").css("cursor", "auto")
|
||||
disable: -> @$(".action-endorse").css("cursor", "default")
|
||||
can_openclose:
|
||||
enable: -> @$(".action-openclose").closest("li").show()
|
||||
disable: -> @$(".action-openclose").closest("li").hide()
|
||||
|
||||
renderPartial: ->
|
||||
console.log "changed"
|
||||
renderPartialAttrs: ->
|
||||
for attr, value of @model.changedAttributes()
|
||||
if @partialRenderer[attr]
|
||||
@partialRenderer[attr].apply(@, [value])
|
||||
if @attrRenderer[attr]
|
||||
@attrRenderer[attr].apply(@, [value])
|
||||
|
||||
renderAttrs: ->
|
||||
for attr, value of @model.attributes
|
||||
if @attrRenderer[attr]
|
||||
@attrRenderer[attr].apply(@, [value])
|
||||
|
||||
initialize: ->
|
||||
@model.bind('change', @renderPartial, @)
|
||||
@model.bind('change', @renderPartialAttrs, @)
|
||||
|
||||
@@ -1,34 +1,24 @@
|
||||
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:
|
||||
"click .discussion-vote": "toggleVote"
|
||||
"click .action-follow": "toggleFollowing"
|
||||
"click .discussion-submit-post": "submitComment"
|
||||
"click .action-edit": "edit"
|
||||
"click .action-delete": "delete"
|
||||
"click .action-openclose": "toggleClosed"
|
||||
|
||||
template: _.template($("#thread-template").html())
|
||||
|
||||
initialize: ->
|
||||
super()
|
||||
@model.on "change", @updateModelDetails
|
||||
|
||||
render: ->
|
||||
@$el.html(@template(@model.toJSON()))
|
||||
@renderDogear()
|
||||
@renderVoted()
|
||||
@renderAttrs()
|
||||
@$("span.timeago").timeago()
|
||||
Markdown.makeWmdEditor @$(".reply-body"), "", DiscussionUtil.urlFor("upload"), (text) -> DiscussionUtil.postMathJaxProcessor(text)
|
||||
@convertMath()
|
||||
@@ -135,7 +125,21 @@ class @DiscussionThreadView extends DiscussionContentView
|
||||
|
||||
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)
|
||||
url = @model.urlFor('endorse')
|
||||
endorsed = @model.get('endorsed')
|
||||
|
||||
@@ -3,6 +3,7 @@ class @ResponseCommentView extends DiscussionContentView
|
||||
template: _.template($("#response-comment-template").html())
|
||||
render: ->
|
||||
@$el.html(@template(@model.toJSON()))
|
||||
@renderAttrs()
|
||||
@$(".timeago").timeago()
|
||||
@convertMath()
|
||||
@
|
||||
|
||||
@@ -11,6 +11,7 @@ class @ThreadResponseView extends DiscussionContentView
|
||||
@$el.html(@template(@model.toJSON()))
|
||||
if window.user.voted(@model)
|
||||
@$(".vote-btn").addClass("is-cast")
|
||||
@renderAttrs()
|
||||
@$(".posted-details").timeago()
|
||||
@convertMath()
|
||||
@renderComments()
|
||||
|
||||
@@ -13,14 +13,13 @@
|
||||
<div class="post-body">
|
||||
${'<%- body %>'}
|
||||
</div>
|
||||
<div class="post-status">
|
||||
${'<% if (closed) { %>'}
|
||||
This thread is closed.
|
||||
${'<% } %>'}
|
||||
<div class="post-status-closed" style="display: none">
|
||||
This thread is closed.
|
||||
</div>
|
||||
<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-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>
|
||||
</div>
|
||||
<ol class="responses">
|
||||
@@ -60,4 +59,4 @@
|
||||
|
||||
<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>
|
||||
</script>
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user