Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
952c9d56
Commit
952c9d56
authored
Aug 22, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved some stuff
parent
ee217518
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1504 additions
and
1504 deletions
+1504
-1504
lms/static/coffee/src/backbone_discussion/content.coffee
+0
-410
lms/static/coffee/src/backbone_discussion/discussion.coffee
+0
-167
lms/static/coffee/src/backbone_discussion/discussion_module.coffee
+0
-32
lms/static/coffee/src/backbone_discussion/main.coffee
+0
-15
lms/static/coffee/src/backbone_discussion/templates.coffee
+0
-0
lms/static/coffee/src/discussion/content.coffee
+396
-398
lms/static/coffee/src/discussion/discussion.coffee
+166
-189
lms/static/coffee/src/discussion/discussion_module.coffee
+27
-37
lms/static/coffee/src/discussion/main.coffee
+10
-18
lms/static/coffee/src/discussion/templates.coffee
+0
-73
lms/static/coffee/src/discussion/utils.coffee
+85
-80
lms/static/coffee/src/old_discussion/content.coffee
+412
-0
lms/static/coffee/src/old_discussion/discussion.coffee
+190
-0
lms/static/coffee/src/old_discussion/discussion_module.coffee
+42
-0
lms/static/coffee/src/old_discussion/main.coffee
+23
-0
lms/static/coffee/src/old_discussion/templates.coffee
+73
-0
lms/static/coffee/src/old_discussion/user_profile.coffee
+0
-0
lms/static/coffee/src/old_discussion/utils.coffee
+80
-85
No files found.
lms/static/coffee/src/backbone_discussion/content.coffee
deleted
100644 → 0
View file @
ee217518
class
@
Content
extends
Backbone
.
Model
template
:
->
DiscussionUtil
.
getTemplate
(
'_content'
)
actions
:
editable
:
'.admin-edit'
can_reply
:
'.discussion-reply'
can_endorse
:
'.admin-endorse'
can_delete
:
'.admin-delete'
can_openclose
:
'.admin-openclose'
urlMappers
:
{}
urlFor
:
(
name
)
->
@
urlMappers
[
name
].
apply
(
@
)
can
:
(
action
)
->
DiscussionUtil
.
getContentInfo
@
id
,
action
updateInfo
:
(
info
)
->
@
set
(
'ability'
,
info
.
ability
)
@
set
(
'voted'
,
info
.
voted
)
@
set
(
'subscribed'
,
info
.
subscribed
)
addComment
:
(
comment
,
options
)
->
options
||=
{}
if
not
options
.
silent
thread
=
@
get
(
'thread'
)
comments_count
=
parseInt
(
thread
.
get
(
'comments_count'
))
thread
.
set
(
'comments_count'
,
comments_count
+
1
)
@
get
(
'children'
).
push
comment
model
=
new
Comment
$
.
extend
{},
comment
,
{
thread
:
@
get
(
'thread'
)
}
@
get
(
'comments'
).
add
model
model
removeComment
:
(
comment
)
->
thread
=
@
get
(
'thread'
)
comments_count
=
parseInt
(
thread
.
get
(
'comments_count'
))
thread
.
set
(
'comments_count'
,
comments_count
-
1
-
comment
.
getCommentsCount
())
resetComments
:
(
children
)
->
@
set
'children'
,
[]
@
set
'comments'
,
new
Comments
()
for
comment
in
(
children
||
[])
@
addComment
comment
,
{
silent
:
true
}
initialize
:
->
DiscussionUtil
.
addContent
@
id
,
@
@
resetComments
(
@
get
(
'children'
))
class
@
ContentView
extends
Backbone
.
View
$
:
(
selector
)
->
@
$local
.
find
(
selector
)
partial
:
endorsed
:
(
endorsed
)
->
if
endorsed
@
$el
.
addClass
(
"endorsed"
)
else
@
$el
.
removeClass
(
"endorsed"
)
closed
:
(
closed
)
->
# we should just re-render the whole thread, or update according to new abilities
if
closed
@
$el
.
addClass
(
"closed"
)
@
$
(
".admin-openclose"
).
text
"Re-open Thread"
else
@
$el
.
removeClass
(
"closed"
)
@
$
(
".admin-openclose"
).
text
"Close Thread"
voted
:
(
voted
)
->
@
$
(
".discussion-vote-up"
).
removeClass
(
"voted"
)
if
voted
!=
"up"
@
$
(
".discussion-vote-down"
).
removeClass
(
"voted"
)
if
voted
!=
"down"
@
$
(
".discussion-vote-
#{
voted
}
"
).
addClass
(
"voted"
)
if
voted
in
[
"up"
,
"down"
]
votes_point
:
(
votes_point
)
->
@
$
(
".discussion-votes-point"
).
html
(
votes_point
)
comments_count
:
(
comments_count
)
->
@
$
(
".comments-count"
).
html
(
comments_count
)
subscribed
:
(
subscribed
)
->
if
subscribed
@
$
(
".discussion-follow-thread"
).
addClass
(
"discussion-unfollow-thread"
).
html
(
"Unfollow"
)
else
@
$
(
".discussion-follow-thread"
).
removeClass
(
"discussion-unfollow-thread"
).
html
(
"Follow"
)
ability
:
(
ability
)
->
for
action
,
elemSelector
of
@
model
.
actions
if
not
ability
[
action
]
@
$
(
elemSelector
).
parent
().
remove
()
$discussionContent
:
->
@
_discussionContent
||=
@
$el
.
children
(
".discussion-content"
)
$showComments
:
->
@
_showComments
||=
@
$
(
".discussion-show-comments"
)
updateShowComments
:
->
if
@
showed
@
$showComments
().
html
@
$showComments
().
html
().
replace
"Show"
,
"Hide"
else
@
$showComments
().
html
@
$showComments
().
html
().
replace
"Hide"
,
"Show"
retrieved
:
->
@
$showComments
().
hasClass
(
"retrieved"
)
hideSingleThread
:
(
event
)
->
@
$el
.
children
(
".comments"
).
hide
()
@
showed
=
false
@
updateShowComments
()
showSingleThread
:
(
event
)
->
if
@
retrieved
()
@
$el
.
children
(
".comments"
).
show
()
@
showed
=
true
@
updateShowComments
()
else
$elem
=
$
.
merge
@
$
(
".thread-title"
),
@
$showComments
()
url
=
@
model
.
urlFor
(
'retrieve'
)
DiscussionUtil
.
get
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
showed
=
true
@
updateShowComments
()
@
$showComments
().
addClass
(
"retrieved"
)
@
$el
.
children
(
".comments"
).
replaceWith
response
.
html
@
model
.
resetComments
response
.
content
.
children
@
initCommentViews
()
DiscussionUtil
.
bulkUpdateContentInfo
response
.
annotated_content_info
toggleSingleThread
:
(
event
)
->
if
@
showed
@
hideSingleThread
(
event
)
else
@
showSingleThread
(
event
)
initCommentViews
:
->
@
$el
.
children
(
".comments"
).
children
(
".comment"
).
each
(
index
,
elem
)
=>
model
=
@
model
.
get
(
'comments'
).
find
$
(
elem
).
attr
(
"_id"
)
if
not
model
.
view
commentView
=
new
CommentView
el
:
elem
,
model
:
model
reply
:
->
if
@
model
.
get
(
'type'
)
==
'thread'
@
showSingleThread
()
$replyView
=
@
$
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
show
()
else
view
=
{}
view
.
id
=
@
model
.
id
view
.
showWatchCheckbox
=
not
@
model
.
get
(
'thread'
).
get
(
'subscribed'
)
html
=
Mustache
.
render
DiscussionUtil
.
getTemplate
(
'_reply'
),
view
@
$discussionContent
().
append
html
DiscussionUtil
.
makeWmdEditor
@
$el
,
$
.
proxy
(
@
$
,
@
),
"reply-body"
@
$
(
".discussion-submit-post"
).
click
$
.
proxy
(
@
submitReply
,
@
)
@
$
(
".discussion-cancel-post"
).
click
$
.
proxy
(
@
cancelReply
,
@
)
@
$
(
".discussion-reply"
).
hide
()
@
$
(
".discussion-edit"
).
hide
()
submitReply
:
(
event
)
->
url
=
@
model
.
urlFor
(
'reply'
)
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"reply-body"
anonymous
=
false
||
@
$
(
".discussion-post-anonymously"
).
is
(
":checked"
)
autowatch
=
false
||
@
$
(
".discussion-auto-watch"
).
is
(
":checked"
)
DiscussionUtil
.
safeAjax
$elem
:
$
(
event
.
target
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
body
:
body
anonymous
:
anonymous
auto_subscribe
:
autowatch
error
:
DiscussionUtil
.
formErrorHandler
@
$
(
".discussion-errors"
)
success
:
(
response
,
textStatus
)
=>
DiscussionUtil
.
clearFormErrors
@
$
(
".discussion-errors"
)
$comment
=
$
(
response
.
html
)
@
$el
.
children
(
".comments"
).
prepend
$comment
DiscussionUtil
.
setWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"reply-body"
,
""
comment
=
@
model
.
addComment
response
.
content
commentView
=
new
CommentView
el
:
$comment
[
0
],
model
:
comment
comment
.
updateInfo
response
.
annotated_content_info
@
cancelReply
()
cancelReply
:
->
$replyView
=
@
$
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
hide
()
@
$
(
".discussion-reply"
).
show
()
@
$
(
".discussion-edit"
).
show
()
unvote
:
(
event
)
->
url
=
@
model
.
urlFor
(
'unvote'
)
$elem
=
@
$
(
".discussion-vote"
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
model
.
set
(
'voted'
,
''
)
@
model
.
set
(
'votes_point'
,
response
.
votes
.
point
)
vote
:
(
event
,
value
)
->
url
=
@
model
.
urlFor
(
"
#{
value
}
vote"
)
$elem
=
@
$
(
".discussion-vote"
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
model
.
set
(
'voted'
,
value
)
@
model
.
set
(
'votes_point'
,
response
.
votes
.
point
)
toggleVote
:
(
event
)
->
$elem
=
$
(
event
.
target
)
value
=
$elem
.
attr
(
"value"
)
if
@
model
.
get
(
"voted"
)
==
value
@
unvote
(
event
)
else
@
vote
(
event
,
value
)
toggleEndorse
:
(
event
)
->
$elem
=
$
(
event
.
target
)
url
=
@
model
.
urlFor
(
'endorse'
)
endorsed
=
@
model
.
get
(
'endorsed'
)
data
=
{
endorsed
:
not
endorsed
}
DiscussionUtil
.
post
$elem
,
url
,
data
,
(
response
,
textStatus
)
=>
@
model
.
set
(
'endorsed'
,
not
endorsed
)
toggleFollow
:
(
event
)
->
$elem
=
$
(
event
.
target
)
subscribed
=
@
model
.
get
(
'subscribed'
)
if
subscribed
url
=
@
model
.
urlFor
(
'unfollow'
)
else
url
=
@
model
.
urlFor
(
'follow'
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
model
.
set
(
'subscribed'
,
not
subscribed
)
toggleClosed
:
(
event
)
->
$elem
=
$
(
event
.
target
)
url
=
@
model
.
urlFor
(
'close'
)
closed
=
@
model
.
get
(
'closed'
)
data
=
{
closed
:
not
closed
}
DiscussionUtil
.
post
$elem
,
url
,
data
,
(
response
,
textStatus
)
=>
@
model
.
set
(
'closed'
,
not
closed
)
edit
:
(
event
)
->
@
$
(
".discussion-content-wrapper"
).
hide
()
$editView
=
@
$
(
".discussion-content-edit"
)
if
$editView
.
length
$editView
.
show
()
else
view
=
{}
view
.
id
=
@
model
.
id
if
@
model
.
get
(
'type'
)
==
'thread'
view
.
title
=
@
$
(
".thread-raw-title"
).
html
()
view
.
body
=
@
$
(
".thread-raw-body"
).
html
()
view
.
tags
=
@
$
(
".thread-raw-tags"
).
html
()
else
view
.
body
=
@
$
(
".comment-raw-body"
).
html
()
@
$discussionContent
().
append
Mustache
.
render
DiscussionUtil
.
getTemplate
(
"_edit_
#{
@
model
.
get
(
'type'
)
}
"
),
view
Discussion
.
makeWmdEditor
@
$el
,
$
.
proxy
(
@
$
,
@
),
"
#{
@
model
.
get
(
'type'
)
}
-body-edit"
@
$
(
".thread-tags-edit"
).
tagsInput
DiscussionUtil
.
tagsInputOptions
()
@
$
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
$
.
proxy
(
@
submitEdit
,
@
)
@
$
(
".discussion-cancel-update"
).
unbind
(
"click"
).
click
$
.
proxy
(
@
cancelEdit
,
@
)
submitEdit
:
(
event
)
->
url
=
@
model
.
urlFor
(
'update'
)
data
=
{}
if
@
model
.
get
(
'type'
)
==
'thread'
data
.
title
=
@
$
(
".thread-title-edit"
).
val
()
data
.
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"thread-body-edit"
data
.
tags
=
@
$
(
".thread-tags-edit"
).
val
()
else
data
.
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"comment-body-edit"
DiscussionUtil
.
safeAjax
$elem
:
$
(
event
.
target
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
data
error
:
DiscussionUtil
.
formErrorHandler
@
$
(
".discussion-update-errors"
)
success
:
(
response
,
textStatus
)
=>
DiscussionUtil
.
clearFormErrors
@
$
(
".discussion-update-errors"
)
@
$discussionContent
().
replaceWith
(
response
.
html
)
@
model
.
set
response
.
content
@
model
.
updateInfo
response
.
annotated_content_info
cancelEdit
:
(
event
)
->
@
$
(
".discussion-content-edit"
).
hide
()
@
$
(
".discussion-content-wrapper"
).
show
()
delete
:
(
event
)
->
url
=
@
model
.
urlFor
(
'delete'
)
if
@
model
.
get
(
'type'
)
==
'thread'
c
=
confirm
"Are you sure to delete thread
\"
#{
@
model
.
get
(
'title'
)
}
\"
?"
else
c
=
confirm
"Are you sure to delete this comment? "
if
not
c
return
$elem
=
$
(
event
.
target
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
$el
.
remove
()
@
model
.
get
(
'thread'
).
removeComment
(
@
model
)
events
:
"click .discussion-follow-thread"
:
"toggleFollow"
"click .thread-title"
:
"toggleSingleThread"
"click .discussion-show-comments"
:
"toggleSingleThread"
"click .discussion-reply-thread"
:
"reply"
"click .discussion-reply-comment"
:
"reply"
"click .discussion-cancel-reply"
:
"cancelReply"
"click .discussion-vote-up"
:
"toggleVote"
"click .discussion-vote-down"
:
"toggleVote"
"click .admin-endorse"
:
"toggleEndorse"
"click .admin-openclose"
:
"toggleClosed"
"click .admin-edit"
:
"edit"
"click .admin-delete"
:
"delete"
initLocal
:
->
@
$local
=
@
$el
.
children
(
".local"
)
@
$delegateElement
=
@
$local
initTitle
:
->
$contentTitle
=
@
$
(
".thread-title"
)
if
$contentTitle
.
length
$contentTitle
.
html
DiscussionUtil
.
unescapeHighlightTag
DiscussionUtil
.
stripLatexHighlight
$contentTitle
.
html
()
initBody
:
->
$contentBody
=
@
$
(
".content-body"
)
$contentBody
.
html
DiscussionUtil
.
postMathJaxProcessor
DiscussionUtil
.
markdownWithHighlight
$contentBody
.
html
()
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
$contentBody
.
attr
(
"id"
)]
initTimeago
:
->
@
$
(
"span.timeago"
).
timeago
()
initPermalink
:
->
@
$
(
".discussion-permanent-link"
).
attr
"href"
,
@
model
.
permalink
()
renderPartial
:
->
for
attr
,
value
of
@
model
.
changedAttributes
()
if
@
partial
[
attr
]
@
partial
[
attr
].
apply
(
@
,
[
value
])
initBindings
:
->
@
model
.
view
=
@
@
model
.
bind
(
'change'
,
@
renderPartial
,
@
)
initialize
:
->
@
initBindings
()
@
initLocal
()
@
initTimeago
()
@
initTitle
()
@
initBody
()
@
initCommentViews
()
class
@
Thread
extends
@
Content
urlMappers
:
'retrieve'
:
->
DiscussionUtil
.
urlFor
(
'retrieve_single_thread'
,
@
discussion
.
id
,
@
id
)
'reply'
:
->
DiscussionUtil
.
urlFor
(
'create_comment'
,
@
id
)
'unvote'
:
->
DiscussionUtil
.
urlFor
(
"undo_vote_for_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'upvote'
:
->
DiscussionUtil
.
urlFor
(
"upvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'downvote'
:
->
DiscussionUtil
.
urlFor
(
"downvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'close'
:
->
DiscussionUtil
.
urlFor
(
'openclose_thread'
,
@
id
)
'update'
:
->
DiscussionUtil
.
urlFor
(
'update_thread'
,
@
id
)
'delete'
:
->
DiscussionUtil
.
urlFor
(
'delete_thread'
,
@
id
)
'follow'
:
->
DiscussionUtil
.
urlFor
(
'follow_thread'
,
@
id
)
'unfollow'
:
->
DiscussionUtil
.
urlFor
(
'unfollow_thread'
,
@
id
)
initialize
:
->
@
set
(
'thread'
,
@
)
super
()
permalink
:
->
discussion_id
=
@
get
(
'commentable_id'
)
return
Discussion
.
urlFor
(
"permanent_link_thread"
,
discussion_id
,
@
id
)
class
@
ThreadView
extends
@
ContentView
class
@
Comment
extends
@
Content
urlMappers
:
'reply'
:
->
DiscussionUtil
.
urlFor
(
'create_sub_comment'
,
@
id
)
'unvote'
:
->
DiscussionUtil
.
urlFor
(
"undo_vote_for_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'upvote'
:
->
DiscussionUtil
.
urlFor
(
"upvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'downvote'
:
->
DiscussionUtil
.
urlFor
(
"downvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'endorse'
:
->
DiscussionUtil
.
urlFor
(
'endorse_comment'
,
@
id
)
'update'
:
->
DiscussionUtil
.
urlFor
(
'update_comment'
,
@
id
)
'delete'
:
->
DiscussionUtil
.
urlFor
(
'delete_comment'
,
@
id
)
permalink
:
->
thread_id
=
@
get
(
'thread'
).
id
discussion_id
=
@
get
(
'thread'
).
get
(
'commentable_id'
)
return
Discussion
.
urlFor
(
"permanent_link_comment"
,
discussion_id
,
thread_id
,
@
id
)
getCommentsCount
:
->
count
=
0
@
get
(
'comments'
).
each
(
comment
)
->
count
+=
comment
.
getCommentsCount
()
+
1
count
class
@
CommentView
extends
@
ContentView
class
@
Comments
extends
Backbone
.
Collection
model
:
Comment
initialize
:
->
@
bind
"add"
,
(
item
)
=>
item
.
collection
=
@
find
:
(
id
)
->
_
.
first
@
where
(
id
:
id
)
lms/static/coffee/src/backbone_discussion/discussion.coffee
deleted
100644 → 0
View file @
ee217518
class
@
Discussion
extends
Backbone
.
Collection
model
:
Thread
initialize
:
->
DiscussionUtil
.
addDiscussion
@
id
,
@
@
bind
"add"
,
(
item
)
=>
item
.
discussion
=
@
find
:
(
id
)
->
_
.
first
@
where
(
id
:
id
)
addThread
:
(
thread
,
options
)
->
options
||=
{}
model
=
new
Thread
thread
@
add
model
model
class
@
DiscussionView
extends
Backbone
.
View
$
:
(
selector
)
->
@
$local
.
find
(
selector
)
initLocal
:
->
@
$local
=
@
$el
.
children
(
".local"
)
@
$delegateElement
=
@
$local
initialize
:
->
@
initLocal
()
@
model
.
id
=
@
$el
.
attr
(
"_id"
)
@
model
.
view
=
@
@
$el
.
children
(
".threads"
).
children
(
".thread"
).
each
(
index
,
elem
)
=>
threadView
=
new
ThreadView
el
:
elem
,
model
:
@
model
.
find
$
(
elem
).
attr
(
"_id"
)
if
@
$el
.
hasClass
(
"forum-discussion"
)
$
(
".discussion-sidebar"
).
find
(
".sidebar-new-post-button"
)
.
unbind
(
'click'
).
click
$
.
proxy
@
newPost
,
@
else
if
@
$el
.
hasClass
(
"inline-discussion"
)
@
newPost
()
reload
:
(
$elem
,
url
)
->
if
not
url
then
return
DiscussionUtil
.
get
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
$parent
=
@
$el
.
parent
()
@
$el
.
replaceWith
(
response
.
html
)
$discussion
=
$parent
.
find
(
"section.discussion"
)
@
model
.
reset
(
response
.
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
el
:
$discussion
[
0
],
model
:
@
model
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
loadSimilarPost
:
(
event
)
->
$title
=
@
$
(
".new-post-title"
)
$wrapper
=
@
$
(
".new-post-similar-posts-wrapper"
)
$similarPosts
=
@
$
(
".new-post-similar-posts"
)
prevText
=
$title
.
attr
(
"prev-text"
)
text
=
$title
.
val
()
if
text
==
prevText
if
@
$
(
".similar-post"
).
length
$wrapper
.
show
()
else
if
$
.
trim
(
text
).
length
$elem
=
$
(
event
.
target
)
url
=
DiscussionUtil
.
urlFor
'search_similar_threads'
,
@
model
.
id
data
=
{
text
:
@
$
(
".new-post-title"
).
val
()
}
DiscussionUtil
.
get
$elem
,
url
,
data
,
(
response
,
textStatus
)
=>
$similarPosts
.
empty
()
if
$
.
type
(
response
)
==
"array"
and
response
.
length
$wrapper
.
show
()
for
thread
in
response
$similarPost
=
$
(
"<a>"
).
addClass
(
"similar-post"
)
.
html
(
thread
[
"title"
])
.
attr
(
"href"
,
"javascript:void(0)"
)
#TODO
.
appendTo
(
$similarPosts
)
else
$wrapper
.
hide
()
else
$wrapper
.
hide
()
$title
.
attr
(
"prev-text"
,
text
)
newPost
:
->
if
not
@
$
(
".wmd-panel"
).
length
view
=
{
discussion_id
:
@
model
.
id
}
@
$el
.
children
(
".discussion-non-content"
).
append
Mustache
.
render
DiscussionUtil
.
getTemplate
(
"_new_post"
),
view
$newPostBody
=
@
$
(
".new-post-body"
)
DiscussionUtil
.
makeWmdEditor
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
$input
=
DiscussionUtil
.
getWmdInput
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
$input
.
attr
(
"placeholder"
,
"post a new topic..."
)
if
@
$el
.
hasClass
(
"inline-discussion"
)
$input
.
bind
'focus'
,
(
e
)
=>
@
$
(
".new-post-form"
).
removeClass
(
'collapsed'
)
else
if
@
$el
.
hasClass
(
"forum-discussion"
)
@
$
(
".new-post-form"
).
removeClass
(
'collapsed'
)
@
$
(
".new-post-tags"
).
tagsInput
DiscussionUtil
.
tagsInputOptions
()
@
$
(
".new-post-title"
).
blur
$
.
proxy
(
@
loadSimilarPost
,
@
)
@
$
(
".hide-similar-posts"
).
click
=>
@
$
(
".new-post-similar-posts-wrapper"
).
hide
()
@
$
(
".discussion-submit-post"
).
click
$
.
proxy
(
@
submitNewPost
,
@
)
@
$
(
".discussion-cancel-post"
).
click
$
.
proxy
(
@
cancelNewPost
,
@
)
@
$
(
".new-post-form"
).
show
()
submitNewPost
:
(
event
)
->
title
=
@
$
(
".new-post-title"
).
val
()
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
tags
=
@
$
(
".new-post-tags"
).
val
()
anonymous
=
false
||
@
$
(
".discussion-post-anonymously"
).
is
(
":checked"
)
autowatch
=
false
||
@
$
(
".discussion-auto-watch"
).
is
(
":checked"
)
url
=
DiscussionUtil
.
urlFor
(
'create_thread'
,
@
model
.
id
)
DiscussionUtil
.
safeAjax
$elem
:
$
(
event
.
target
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
title
:
title
body
:
body
tags
:
tags
anonymous
:
anonymous
auto_subscribe
:
autowatch
error
:
DiscussionUtil
.
formErrorHandler
(
@
$
(
".new-post-form-errors"
))
success
:
(
response
,
textStatus
)
=>
DiscussionUtil
.
clearFormErrors
(
@
$
(
".new-post-form-errors"
))
$thread
=
$
(
response
.
html
)
@
$el
.
children
(
".threads"
).
prepend
(
$thread
)
@
$
(
".new-post-title"
).
val
(
""
)
DiscussionUtil
.
setWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
,
""
@
$
(
".new-post-tags"
).
val
(
""
)
@
$
(
".new-post-tags"
).
importTags
(
""
)
thread
=
@
model
.
addThread
response
.
content
threadView
=
new
ThreadView
el
:
$thread
[
0
],
model
:
thread
thread
.
updateInfo
response
.
annotated_content_info
@
cancelNewPost
()
cancelNewPost
:
(
event
)
->
if
@
$el
.
hasClass
(
"inline-discussion"
)
@
$
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
if
@
$el
.
hasClass
(
"forum-discussion"
)
@
$
(
".new-post-form"
).
hide
()
search
:
(
event
)
->
event
.
preventDefault
()
$elem
=
$
(
event
.
target
)
url
=
URI
(
$elem
.
attr
(
"action"
)).
addSearch
({
text
:
@
$
(
".search-input"
).
val
()})
@
reload
(
$elem
,
url
)
sort
:
->
$elem
=
$
(
event
.
target
)
url
=
$elem
.
attr
(
"sort-url"
)
@
reload
(
$elem
,
url
)
page
:
(
event
)
->
$elem
=
$
(
event
.
target
)
url
=
$elem
.
attr
(
"page-url"
)
@
reload
(
$elem
,
url
)
events
:
"submit .search-wrapper>.discussion-search-form"
:
"search"
"click .discussion-search-link"
:
"search"
"click .discussion-sort-link"
:
"sort"
"click .discussion-page-link"
:
"page"
lms/static/coffee/src/backbone_discussion/discussion_module.coffee
deleted
100644 → 0
View file @
ee217518
class
@
DiscussionModuleView
extends
Backbone
.
View
events
:
"click .discussion-show"
:
"toggleDiscussion"
toggleDiscussion
:
(
event
)
->
if
@
showed
@
$
(
"section.discussion"
).
hide
()
$
(
event
.
target
).
html
(
"Show Discussion"
)
@
showed
=
false
else
if
@
retrieved
@
$
(
"section.discussion"
).
show
()
$
(
event
.
target
).
html
(
"Hide Discussion"
)
@
showed
=
true
else
$elem
=
$
(
event
.
target
)
discussion_id
=
$elem
.
attr
(
"discussion_id"
)
url
=
DiscussionUtil
.
urlFor
'retrieve_discussion'
,
discussion_id
Discussion
.
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
dataType
:
'json'
success
:
(
response
,
textStatus
)
=>
@
$el
.
append
(
response
.
html
)
$discussion
=
@
$el
.
find
(
"section.discussion"
)
$
(
event
.
target
).
html
(
"Hide Discussion"
)
discussion
=
new
Discussion
()
discussion
.
reset
(
response
.
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
(
el
:
$discussion
[
0
],
model
:
discussion
)
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
@
retrieved
=
true
@
showed
=
true
lms/static/coffee/src/backbone_discussion/main.coffee
deleted
100644 → 0
View file @
ee217518
$
->
window
.
$
$contents
=
{}
window
.
$
$discussions
=
{}
$
(
".discussion-module"
).
each
(
index
,
elem
)
->
view
=
new
DiscussionModuleView
(
el
:
elem
)
$
(
"section.discussion"
).
each
(
index
,
elem
)
->
discussionData
=
DiscussionUtil
.
getDiscussionData
(
$
(
elem
).
attr
(
"_id"
))
discussion
=
new
Discussion
()
discussion
.
reset
(
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
(
el
:
elem
,
model
:
discussion
)
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
lms/static/coffee/src/backbone_discussion/templates.coffee
deleted
100644 → 0
View file @
ee217518
lms/static/coffee/src/discussion/content.coffee
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
initializeVote
=
(
content
)
->
$content
=
$
(
content
)
$local
=
Discussion
.
generateLocal
(
$content
.
children
(
".discussion-content"
))
id
=
$content
.
attr
(
"_id"
)
if
Discussion
.
isUpvoted
id
$local
(
".discussion-vote-up"
).
addClass
(
"voted"
)
else
if
Discussion
.
isDownvoted
id
$local
(
".discussion-vote-down"
).
addClass
(
"voted"
)
initializeFollowThread
=
(
thread
)
->
$thread
=
$
(
thread
)
id
=
$thread
.
attr
(
"_id"
)
$thread
.
children
(
".discussion-content"
)
.
find
(
".follow-wrapper"
)
.
append
(
Discussion
.
subscriptionLink
(
'thread'
,
id
))
@
Discussion
=
$
.
extend
@
Discussion
,
bindContentEvents
:
(
content
)
->
$content
=
$
(
content
)
$discussionContent
=
$content
.
children
(
".discussion-content"
)
$local
=
Discussion
.
generateLocal
(
$discussionContent
)
id
=
$content
.
attr
(
"_id"
)
handleReply
=
(
elem
)
->
$replyView
=
$local
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
show
()
else
thread_id
=
$discussionContent
.
parents
(
".thread"
).
attr
(
"_id"
)
view
=
id
:
id
showWatchCheckbox
:
not
Discussion
.
isSubscribed
(
thread_id
,
"thread"
)
$discussionContent
.
append
Mustache
.
render
Discussion
.
replyTemplate
,
view
Discussion
.
makeWmdEditor
$content
,
$local
,
"reply-body"
$local
(
".discussion-submit-post"
).
click
->
handleSubmitReply
(
this
)
$local
(
".discussion-cancel-post"
).
click
->
handleCancelReply
(
this
)
$local
(
".discussion-reply"
).
hide
()
$local
(
".discussion-edit"
).
hide
()
handleCancelReply
=
(
elem
)
->
$replyView
=
$local
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
hide
()
$local
(
".discussion-reply"
).
show
()
$local
(
".discussion-edit"
).
show
()
handleSubmitReply
=
(
elem
)
->
if
$content
.
hasClass
(
"thread"
)
url
=
Discussion
.
urlFor
(
'create_comment'
,
id
)
else
if
$content
.
hasClass
(
"comment"
)
url
=
Discussion
.
urlFor
(
'create_sub_comment'
,
id
)
else
return
body
=
Discussion
.
getWmdContent
$content
,
$local
,
"reply-body"
anonymous
=
false
||
$local
(
".discussion-post-anonymously"
).
is
(
":checked"
)
autowatch
=
false
||
$local
(
".discussion-auto-watch"
).
is
(
":checked"
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
body
:
body
anonymous
:
anonymous
autowatch
:
autowatch
error
:
Discussion
.
formErrorHandler
(
$local
(
".discussion-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".discussion-errors"
))
$comment
=
$
(
response
.
html
)
$content
.
children
(
".comments"
).
prepend
(
$comment
)
Discussion
.
setWmdContent
$content
,
$local
,
"reply-body"
,
""
Discussion
.
setContentInfo
response
.
content
[
'id'
],
'can_reply'
,
true
Discussion
.
setContentInfo
response
.
content
[
'id'
],
'editable'
,
true
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$comment
)
Discussion
.
bindContentEvents
(
$comment
)
@
cancelReply
()
$local
(
".discussion-reply-new"
).
hide
()
$local
(
".discussion-reply"
).
show
()
$local
(
".discussion-edit"
).
show
()
$discussionContent
.
attr
(
"status"
,
"normal"
)
handleVote
=
(
elem
,
value
)
->
contentType
=
if
$content
.
hasClass
(
"thread"
)
then
"thread"
else
"comment"
url
=
Discussion
.
urlFor
(
"
#{
value
}
vote_
#{
contentType
}
"
,
id
)
Discussion
.
safeAjax
$elem
:
$local
(
".discussion-vote"
)
url
:
url
type
:
"POST"
dataType
:
"json"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$local
(
".discussion-vote"
).
removeClass
(
"voted"
)
$local
(
".discussion-vote-
#{
value
}
"
).
addClass
(
"voted"
)
$local
(
".discussion-votes-point"
).
html
response
.
votes
.
point
handleUnvote
=
(
elem
,
value
)
->
contentType
=
if
$content
.
hasClass
(
"thread"
)
then
"thread"
else
"comment"
url
=
Discussion
.
urlFor
(
"undo_vote_for_
#{
contentType
}
"
,
id
)
Discussion
.
safeAjax
$elem
:
$local
(
".discussion-vote"
)
url
:
url
type
:
"POST"
dataType
:
"json"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$local
(
".discussion-vote"
).
removeClass
(
"voted"
)
$local
(
".discussion-votes-point"
).
html
response
.
votes
.
point
handleCancelEdit
=
(
elem
)
->
$local
(
".discussion-content-edit"
).
hide
()
$local
(
".discussion-content-wrapper"
).
show
()
handleEditThread
=
(
elem
)
->
$local
(
".discussion-content-wrapper"
).
hide
()
$editView
=
$local
(
".discussion-content-edit"
)
if
$editView
.
length
$editView
.
show
()
else
view
=
{
id
:
id
title
:
$local
(
".thread-raw-title"
).
html
()
body
:
$local
(
".thread-raw-body"
).
html
()
tags
:
$local
(
".thread-raw-tags"
).
html
()
}
$discussionContent
.
append
Mustache
.
render
Discussion
.
editThreadTemplate
,
view
Discussion
.
makeWmdEditor
$content
,
$local
,
"thread-body-edit"
$local
(
".thread-tags-edit"
).
tagsInput
Discussion
.
tagsInputOptions
()
$local
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
->
handleSubmitEditThread
(
this
)
$local
(
".discussion-cancel-update"
).
unbind
(
"click"
).
click
->
handleCancelEdit
(
this
)
handleSubmitEditThread
=
(
elem
)
->
url
=
Discussion
.
urlFor
(
'update_thread'
,
id
)
title
=
$local
(
".thread-title-edit"
).
val
()
body
=
Discussion
.
getWmdContent
$content
,
$local
,
"thread-body-edit"
tags
=
$local
(
".thread-tags-edit"
).
val
()
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
{
title
:
title
,
body
:
body
,
tags
:
tags
},
error
:
Discussion
.
formErrorHandler
(
$local
(
".discussion-update-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".discussion-update-errors"
))
$discussionContent
.
replaceWith
(
response
.
html
)
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$content
)
Discussion
.
bindContentEvents
(
$content
)
handleEditComment
=
(
elem
)
->
$local
(
".discussion-content-wrapper"
).
hide
()
$editView
=
$local
(
".discussion-content-edit"
)
if
$editView
.
length
$editView
.
show
()
else
view
=
{
id
:
id
,
body
:
$local
(
".comment-raw-body"
).
html
()
}
$discussionContent
.
append
Mustache
.
render
Discussion
.
editCommentTemplate
,
view
Discussion
.
makeWmdEditor
$content
,
$local
,
"comment-body-edit"
$local
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
->
handleSubmitEditComment
(
this
)
$local
(
".discussion-cancel-update"
).
unbind
(
"click"
).
click
->
handleCancelEdit
(
this
)
handleSubmitEditComment
=
(
elem
)
->
url
=
Discussion
.
urlFor
(
'update_comment'
,
id
)
body
=
Discussion
.
getWmdContent
$content
,
$local
,
"comment-body-edit"
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{
body
:
body
}
error
:
Discussion
.
formErrorHandler
(
$local
(
".discussion-update-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".discussion-update-errors"
))
$discussionContent
.
replaceWith
(
response
.
html
)
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$content
)
Discussion
.
bindContentEvents
(
$content
)
handleEndorse
=
(
elem
,
endorsed
)
->
url
=
Discussion
.
urlFor
(
'endorse_comment'
,
id
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{
endorsed
:
endorsed
}
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
if
endorsed
$
(
content
).
addClass
(
"endorsed"
)
else
$
(
content
).
removeClass
(
"endorsed"
)
$
(
elem
).
unbind
(
'click'
).
click
->
handleEndorse
(
elem
,
!
endorsed
)
handleOpenClose
=
(
elem
,
text
)
->
url
=
Discussion
.
urlFor
(
'openclose_thread'
,
id
)
closed
=
undefined
if
text
.
match
(
/Close/
)
closed
=
true
else
if
text
.
match
(
/[Oo]pen/
)
closed
=
false
class
@
Content
extends
Backbone
.
Model
template
:
->
DiscussionUtil
.
getTemplate
(
'_content'
)
actions
:
editable
:
'.admin-edit'
can_reply
:
'.discussion-reply'
can_endorse
:
'.admin-endorse'
can_delete
:
'.admin-delete'
can_openclose
:
'.admin-openclose'
urlMappers
:
{}
urlFor
:
(
name
)
->
@
urlMappers
[
name
].
apply
(
@
)
can
:
(
action
)
->
DiscussionUtil
.
getContentInfo
@
id
,
action
updateInfo
:
(
info
)
->
@
set
(
'ability'
,
info
.
ability
)
@
set
(
'voted'
,
info
.
voted
)
@
set
(
'subscribed'
,
info
.
subscribed
)
addComment
:
(
comment
,
options
)
->
options
||=
{}
if
not
options
.
silent
thread
=
@
get
(
'thread'
)
comments_count
=
parseInt
(
thread
.
get
(
'comments_count'
))
thread
.
set
(
'comments_count'
,
comments_count
+
1
)
@
get
(
'children'
).
push
comment
model
=
new
Comment
$
.
extend
{},
comment
,
{
thread
:
@
get
(
'thread'
)
}
@
get
(
'comments'
).
add
model
model
removeComment
:
(
comment
)
->
thread
=
@
get
(
'thread'
)
comments_count
=
parseInt
(
thread
.
get
(
'comments_count'
))
thread
.
set
(
'comments_count'
,
comments_count
-
1
-
comment
.
getCommentsCount
())
resetComments
:
(
children
)
->
@
set
'children'
,
[]
@
set
'comments'
,
new
Comments
()
for
comment
in
(
children
||
[])
@
addComment
comment
,
{
silent
:
true
}
initialize
:
->
DiscussionUtil
.
addContent
@
id
,
@
@
resetComments
(
@
get
(
'children'
))
class
@
ContentView
extends
Backbone
.
View
$
:
(
selector
)
->
@
$local
.
find
(
selector
)
partial
:
endorsed
:
(
endorsed
)
->
if
endorsed
@
$el
.
addClass
(
"endorsed"
)
else
console
.
log
"Unexpected text "
+
text
+
"for open/close thread."
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{
closed
:
closed
}
success
:
(
response
,
textStatus
)
=>
if
textStatus
==
"success"
if
closed
$
(
content
).
addClass
(
"closed"
)
$
(
elem
).
text
"Re-open Thread"
else
$
(
content
).
removeClass
(
"closed"
)
$
(
elem
).
text
"Close Thread"
error
:
(
response
,
textStatus
,
e
)
->
console
.
log
e
handleDelete
=
(
elem
)
->
if
$content
.
hasClass
(
"thread"
)
url
=
Discussion
.
urlFor
(
'delete_thread'
,
id
)
c
=
confirm
"Are you sure to delete thread
\"
"
+
$content
.
find
(
"a.thread-title"
).
text
()
+
"
\"
?"
else
url
=
Discussion
.
urlFor
(
'delete_comment'
,
id
)
c
=
confirm
"Are you sure to delete this comment? "
if
c
!=
true
return
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{}
success
:
(
response
,
textStatus
)
=>
if
textStatus
==
"success"
$
(
content
).
remove
()
error
:
(
response
,
textStatus
,
e
)
->
console
.
log
e
handleHideSingleThread
=
(
elem
)
->
$threadTitle
=
$local
(
".thread-title"
)
$hideComments
=
$local
(
".discussion-hide-comments"
)
$hideComments
.
removeClass
(
"discussion-hide-comments"
)
.
addClass
(
"discussion-show-comments"
)
$content
.
children
(
".comments"
).
hide
()
$threadTitle
.
unbind
(
'click'
).
click
handleShowSingleThread
$hideComments
.
unbind
(
'click'
).
click
handleShowSingleThread
prevHtml
=
$hideComments
.
html
()
$hideComments
.
html
prevHtml
.
replace
"Hide"
,
"Show"
handleShowSingleThread
=
->
$threadTitle
=
$local
(
".thread-title"
)
$showComments
=
$local
(
".discussion-show-comments"
)
if
not
$showComments
.
hasClass
(
"first-time"
)
and
(
not
$showComments
.
length
or
not
$threadTitle
.
length
)
return
rebindHideEvents
=
->
$threadTitle
.
unbind
(
'click'
).
click
handleHideSingleThread
$showComments
.
unbind
(
'click'
).
click
handleHideSingleThread
$showComments
.
removeClass
(
"discussion-show-comments"
)
.
addClass
(
"discussion-hide-comments"
)
prevHtml
=
$showComments
.
html
()
$showComments
.
html
prevHtml
.
replace
"Show"
,
"Hide"
if
not
$showComments
.
hasClass
(
"first-time"
)
and
$content
.
children
(
".comments"
).
length
$content
.
children
(
".comments"
).
show
()
rebindHideEvents
()
else
discussion_id
=
$threadTitle
.
parents
(
".discussion"
).
attr
(
"_id"
)
url
=
Discussion
.
urlFor
(
'retrieve_single_thread'
,
discussion_id
,
id
)
Discussion
.
safeAjax
$elem
:
$
.
merge
(
$threadTitle
,
$showComments
)
url
:
url
type
:
"GET"
dataType
:
'json'
success
:
(
response
,
textStatus
)
->
Discussion
.
bulkExtendContentInfo
response
[
'annotated_content_info'
]
$content
.
append
(
response
[
'html'
])
$content
.
find
(
".comment"
).
each
(
index
,
comment
)
->
Discussion
.
initializeContent
(
comment
)
Discussion
.
bindContentEvents
(
comment
)
$showComments
.
removeClass
(
"first-time"
)
rebindHideEvents
()
Discussion
.
bindLocalEvents
$local
,
"click .thread-title"
:
->
handleShowSingleThread
(
this
)
"click .discussion-show-comments"
:
->
handleShowSingleThread
(
this
)
"click .discussion-hide-comments"
:
->
handleHideSingleThread
(
this
)
"click .discussion-reply-thread"
:
->
handleShowSingleThread
(
$local
(
".thread-title"
))
handleReply
(
this
)
"click .discussion-reply-comment"
:
->
handleReply
(
this
)
"click .discussion-cancel-reply"
:
->
handleCancelReply
(
this
)
"click .discussion-vote-up"
:
->
$elem
=
$
(
this
)
if
$elem
.
hasClass
(
"voted"
)
handleUnvote
(
$elem
)
else
handleVote
(
$elem
,
"up"
)
"click .discussion-vote-down"
:
->
$elem
=
$
(
this
)
if
$elem
.
hasClass
(
"voted"
)
handleUnvote
(
$elem
)
else
handleVote
(
$elem
,
"down"
)
"click .admin-endorse"
:
->
handleEndorse
(
this
,
not
$content
.
hasClass
(
"endorsed"
))
@
$el
.
removeClass
(
"endorsed"
)
"click .admin-openclose"
:
->
handleOpenClose
(
this
,
$
(
this
).
text
())
"click .admin-edit"
:
->
if
$content
.
hasClass
(
"thread"
)
handleEditThread
(
this
)
else
handleEditComment
(
this
)
"click .admin-delete"
:
->
handleDelete
(
this
)
initializeContent
:
(
content
)
->
unescapeHighlightTag
=
(
text
)
->
text
.
replace
(
/\<\;highlight\>\;/g
,
"<span class='search-highlight'>"
)
.
replace
(
/\<\;\/highlight\>\;/g
,
"</span>"
)
closed
:
(
closed
)
->
# we should just re-render the whole thread, or update according to new abilities
if
closed
@
$el
.
addClass
(
"closed"
)
@
$
(
".admin-openclose"
).
text
"Re-open Thread"
else
@
$el
.
removeClass
(
"closed"
)
@
$
(
".admin-openclose"
).
text
"Close Thread"
stripHighlight
=
(
text
,
type
)
->
text
.
replace
(
/\&(amp\;)?lt\;highlight\&(amp\;)?gt\;/g
,
""
)
.
replace
(
/\&(amp\;)?lt\;\/highlight\&(amp\;)?gt\;/g
,
""
)
voted
:
(
voted
)
->
@
$
(
".discussion-vote-up"
).
removeClass
(
"voted"
)
if
voted
!=
"up"
@
$
(
".discussion-vote-down"
).
removeClass
(
"voted"
)
if
voted
!=
"down"
@
$
(
".discussion-vote-
#{
voted
}
"
).
addClass
(
"voted"
)
if
voted
in
[
"up"
,
"down"
]
votes_point
:
(
votes_point
)
->
@
$
(
".discussion-votes-point"
).
html
(
votes_point
)
stripLatexHighlight
=
(
text
)
->
Discussion
.
processEachMathAndCode
text
,
stripHighlight
comments_count
:
(
comments_count
)
->
@
$
(
".comments-count"
).
html
(
comments_count
)
subscribed
:
(
subscribed
)
->
if
subscribed
@
$
(
".discussion-follow-thread"
).
addClass
(
"discussion-unfollow-thread"
).
html
(
"Unfollow"
)
else
@
$
(
".discussion-follow-thread"
).
removeClass
(
"discussion-unfollow-thread"
).
html
(
"Follow"
)
markdownWithHighlight
=
(
text
)
->
converter
=
Markdown
.
getMathCompatibleConverter
()
unescapeHighlightTag
stripLatexHighlight
converter
.
makeHtml
text
ability
:
(
ability
)
->
for
action
,
elemSelector
of
@
model
.
actions
if
not
ability
[
action
]
@
$
(
elemSelector
).
parent
().
remove
()
$content
=
$
(
content
)
initializeVote
$content
if
$content
.
hasClass
(
"thread"
)
initializeFollowThread
$content
$local
=
Discussion
.
generateLocal
(
$content
.
children
(
".discussion-content"
))
$discussionContent
:
->
@
_discussionContent
||=
@
$el
.
children
(
".discussion-content"
)
$local
(
"span.timeago"
).
timeago
()
$showComments
:
->
@
_showComments
||=
@
$
(
".discussion-show-comments"
)
$contentTitle
=
$local
(
".thread-title"
)
updateShowComments
:
->
if
@
showed
@
$showComments
().
html
@
$showComments
().
html
().
replace
"Show"
,
"Hide"
else
@
$showComments
().
html
@
$showComments
().
html
().
replace
"Hide"
,
"Show"
retrieved
:
->
@
$showComments
().
hasClass
(
"retrieved"
)
hideSingleThread
:
(
event
)
->
@
$el
.
children
(
".comments"
).
hide
()
@
showed
=
false
@
updateShowComments
()
showSingleThread
:
(
event
)
->
if
@
retrieved
()
@
$el
.
children
(
".comments"
).
show
()
@
showed
=
true
@
updateShowComments
()
else
$elem
=
$
.
merge
@
$
(
".thread-title"
),
@
$showComments
()
url
=
@
model
.
urlFor
(
'retrieve'
)
DiscussionUtil
.
get
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
showed
=
true
@
updateShowComments
()
@
$showComments
().
addClass
(
"retrieved"
)
@
$el
.
children
(
".comments"
).
replaceWith
response
.
html
@
model
.
resetComments
response
.
content
.
children
@
initCommentViews
()
DiscussionUtil
.
bulkUpdateContentInfo
response
.
annotated_content_info
toggleSingleThread
:
(
event
)
->
if
@
showed
@
hideSingleThread
(
event
)
else
@
showSingleThread
(
event
)
initCommentViews
:
->
@
$el
.
children
(
".comments"
).
children
(
".comment"
).
each
(
index
,
elem
)
=>
model
=
@
model
.
get
(
'comments'
).
find
$
(
elem
).
attr
(
"_id"
)
if
not
model
.
view
commentView
=
new
CommentView
el
:
elem
,
model
:
model
reply
:
->
if
@
model
.
get
(
'type'
)
==
'thread'
@
showSingleThread
()
$replyView
=
@
$
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
show
()
else
view
=
{}
view
.
id
=
@
model
.
id
view
.
showWatchCheckbox
=
not
@
model
.
get
(
'thread'
).
get
(
'subscribed'
)
html
=
Mustache
.
render
DiscussionUtil
.
getTemplate
(
'_reply'
),
view
@
$discussionContent
().
append
html
DiscussionUtil
.
makeWmdEditor
@
$el
,
$
.
proxy
(
@
$
,
@
),
"reply-body"
@
$
(
".discussion-submit-post"
).
click
$
.
proxy
(
@
submitReply
,
@
)
@
$
(
".discussion-cancel-post"
).
click
$
.
proxy
(
@
cancelReply
,
@
)
@
$
(
".discussion-reply"
).
hide
()
@
$
(
".discussion-edit"
).
hide
()
submitReply
:
(
event
)
->
url
=
@
model
.
urlFor
(
'reply'
)
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"reply-body"
anonymous
=
false
||
@
$
(
".discussion-post-anonymously"
).
is
(
":checked"
)
autowatch
=
false
||
@
$
(
".discussion-auto-watch"
).
is
(
":checked"
)
DiscussionUtil
.
safeAjax
$elem
:
$
(
event
.
target
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
body
:
body
anonymous
:
anonymous
auto_subscribe
:
autowatch
error
:
DiscussionUtil
.
formErrorHandler
@
$
(
".discussion-errors"
)
success
:
(
response
,
textStatus
)
=>
DiscussionUtil
.
clearFormErrors
@
$
(
".discussion-errors"
)
$comment
=
$
(
response
.
html
)
@
$el
.
children
(
".comments"
).
prepend
$comment
DiscussionUtil
.
setWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"reply-body"
,
""
comment
=
@
model
.
addComment
response
.
content
commentView
=
new
CommentView
el
:
$comment
[
0
],
model
:
comment
comment
.
updateInfo
response
.
annotated_content_info
@
cancelReply
()
cancelReply
:
->
$replyView
=
@
$
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
hide
()
@
$
(
".discussion-reply"
).
show
()
@
$
(
".discussion-edit"
).
show
()
unvote
:
(
event
)
->
url
=
@
model
.
urlFor
(
'unvote'
)
$elem
=
@
$
(
".discussion-vote"
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
model
.
set
(
'voted'
,
''
)
@
model
.
set
(
'votes_point'
,
response
.
votes
.
point
)
vote
:
(
event
,
value
)
->
url
=
@
model
.
urlFor
(
"
#{
value
}
vote"
)
$elem
=
@
$
(
".discussion-vote"
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
model
.
set
(
'voted'
,
value
)
@
model
.
set
(
'votes_point'
,
response
.
votes
.
point
)
toggleVote
:
(
event
)
->
$elem
=
$
(
event
.
target
)
value
=
$elem
.
attr
(
"value"
)
if
@
model
.
get
(
"voted"
)
==
value
@
unvote
(
event
)
else
@
vote
(
event
,
value
)
toggleEndorse
:
(
event
)
->
$elem
=
$
(
event
.
target
)
url
=
@
model
.
urlFor
(
'endorse'
)
endorsed
=
@
model
.
get
(
'endorsed'
)
data
=
{
endorsed
:
not
endorsed
}
DiscussionUtil
.
post
$elem
,
url
,
data
,
(
response
,
textStatus
)
=>
@
model
.
set
(
'endorsed'
,
not
endorsed
)
toggleFollow
:
(
event
)
->
$elem
=
$
(
event
.
target
)
subscribed
=
@
model
.
get
(
'subscribed'
)
if
subscribed
url
=
@
model
.
urlFor
(
'unfollow'
)
else
url
=
@
model
.
urlFor
(
'follow'
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
model
.
set
(
'subscribed'
,
not
subscribed
)
toggleClosed
:
(
event
)
->
$elem
=
$
(
event
.
target
)
url
=
@
model
.
urlFor
(
'close'
)
closed
=
@
model
.
get
(
'closed'
)
data
=
{
closed
:
not
closed
}
DiscussionUtil
.
post
$elem
,
url
,
data
,
(
response
,
textStatus
)
=>
@
model
.
set
(
'closed'
,
not
closed
)
edit
:
(
event
)
->
@
$
(
".discussion-content-wrapper"
).
hide
()
$editView
=
@
$
(
".discussion-content-edit"
)
if
$editView
.
length
$editView
.
show
()
else
view
=
{}
view
.
id
=
@
model
.
id
if
@
model
.
get
(
'type'
)
==
'thread'
view
.
title
=
@
$
(
".thread-raw-title"
).
html
()
view
.
body
=
@
$
(
".thread-raw-body"
).
html
()
view
.
tags
=
@
$
(
".thread-raw-tags"
).
html
()
else
view
.
body
=
@
$
(
".comment-raw-body"
).
html
()
@
$discussionContent
().
append
Mustache
.
render
DiscussionUtil
.
getTemplate
(
"_edit_
#{
@
model
.
get
(
'type'
)
}
"
),
view
Discussion
.
makeWmdEditor
@
$el
,
$
.
proxy
(
@
$
,
@
),
"
#{
@
model
.
get
(
'type'
)
}
-body-edit"
@
$
(
".thread-tags-edit"
).
tagsInput
DiscussionUtil
.
tagsInputOptions
()
@
$
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
$
.
proxy
(
@
submitEdit
,
@
)
@
$
(
".discussion-cancel-update"
).
unbind
(
"click"
).
click
$
.
proxy
(
@
cancelEdit
,
@
)
submitEdit
:
(
event
)
->
url
=
@
model
.
urlFor
(
'update'
)
data
=
{}
if
@
model
.
get
(
'type'
)
==
'thread'
data
.
title
=
@
$
(
".thread-title-edit"
).
val
()
data
.
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"thread-body-edit"
data
.
tags
=
@
$
(
".thread-tags-edit"
).
val
()
else
data
.
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"comment-body-edit"
DiscussionUtil
.
safeAjax
$elem
:
$
(
event
.
target
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
data
error
:
DiscussionUtil
.
formErrorHandler
@
$
(
".discussion-update-errors"
)
success
:
(
response
,
textStatus
)
=>
DiscussionUtil
.
clearFormErrors
@
$
(
".discussion-update-errors"
)
@
$discussionContent
().
replaceWith
(
response
.
html
)
@
model
.
set
response
.
content
@
model
.
updateInfo
response
.
annotated_content_info
cancelEdit
:
(
event
)
->
@
$
(
".discussion-content-edit"
).
hide
()
@
$
(
".discussion-content-wrapper"
).
show
()
delete
:
(
event
)
->
url
=
@
model
.
urlFor
(
'delete'
)
if
@
model
.
get
(
'type'
)
==
'thread'
c
=
confirm
"Are you sure to delete thread
\"
#{
@
model
.
get
(
'title'
)
}
\"
?"
else
c
=
confirm
"Are you sure to delete this comment? "
if
not
c
return
$elem
=
$
(
event
.
target
)
DiscussionUtil
.
post
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
@
$el
.
remove
()
@
model
.
get
(
'thread'
).
removeComment
(
@
model
)
events
:
"click .discussion-follow-thread"
:
"toggleFollow"
"click .thread-title"
:
"toggleSingleThread"
"click .discussion-show-comments"
:
"toggleSingleThread"
"click .discussion-reply-thread"
:
"reply"
"click .discussion-reply-comment"
:
"reply"
"click .discussion-cancel-reply"
:
"cancelReply"
"click .discussion-vote-up"
:
"toggleVote"
"click .discussion-vote-down"
:
"toggleVote"
"click .admin-endorse"
:
"toggleEndorse"
"click .admin-openclose"
:
"toggleClosed"
"click .admin-edit"
:
"edit"
"click .admin-delete"
:
"delete"
initLocal
:
->
@
$local
=
@
$el
.
children
(
".local"
)
@
$delegateElement
=
@
$local
initTitle
:
->
$contentTitle
=
@
$
(
".thread-title"
)
if
$contentTitle
.
length
$contentTitle
.
html
unescapeHighlightTag
stripLatexHighlight
$contentTitle
.
html
()
$contentBody
=
$local
(
".content-body"
)
$contentBody
.
html
Discussion
.
postMathJaxProcessor
markdownWithHighlight
$contentBody
.
html
()
$contentTitle
.
html
DiscussionUtil
.
unescapeHighlightTag
DiscussionUtil
.
stripLatexHighlight
$contentTitle
.
html
()
initBody
:
->
$contentBody
=
@
$
(
".content-body"
)
$contentBody
.
html
DiscussionUtil
.
postMathJaxProcessor
DiscussionUtil
.
markdownWithHighlight
$contentBody
.
html
()
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
$contentBody
.
attr
(
"id"
)]
id
=
$content
.
attr
(
"_id"
)
if
$content
.
hasClass
(
"thread"
)
discussion_id
=
$content
.
attr
(
"_discussion_id"
)
permalink
=
Discussion
.
urlFor
(
"permanent_link_thread"
,
discussion_id
,
id
)
else
thread_id
=
$content
.
parents
(
".thread"
).
attr
(
"_id"
)
discussion_id
=
$content
.
parents
(
".thread"
).
attr
(
"_discussion_id"
)
permalink
=
Discussion
.
urlFor
(
"permanent_link_comment"
,
discussion_id
,
thread_id
,
id
)
$local
(
".discussion-permanent-link"
).
attr
"href"
,
permalink
if
not
Discussion
.
getContentInfo
id
,
'editable'
$local
(
".admin-edit"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_reply'
$local
(
".discussion-reply"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_endorse'
$local
(
".admin-endorse"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_delete'
$local
(
".admin-delete"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_openclose'
$local
(
".admin-openclose"
).
remove
()
#if not Discussion.getContentInfo id, 'can_vote'
# $local(".discussion-vote").css "visibility", "hidden"
initTimeago
:
->
@
$
(
"span.timeago"
).
timeago
()
initPermalink
:
->
@
$
(
".discussion-permanent-link"
).
attr
"href"
,
@
model
.
permalink
()
renderPartial
:
->
for
attr
,
value
of
@
model
.
changedAttributes
()
if
@
partial
[
attr
]
@
partial
[
attr
].
apply
(
@
,
[
value
])
initBindings
:
->
@
model
.
view
=
@
@
model
.
bind
(
'change'
,
@
renderPartial
,
@
)
initialize
:
->
@
initBindings
()
@
initLocal
()
@
initTimeago
()
@
initTitle
()
@
initBody
()
@
initCommentViews
()
class
@
Thread
extends
@
Content
urlMappers
:
'retrieve'
:
->
DiscussionUtil
.
urlFor
(
'retrieve_single_thread'
,
@
discussion
.
id
,
@
id
)
'reply'
:
->
DiscussionUtil
.
urlFor
(
'create_comment'
,
@
id
)
'unvote'
:
->
DiscussionUtil
.
urlFor
(
"undo_vote_for_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'upvote'
:
->
DiscussionUtil
.
urlFor
(
"upvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'downvote'
:
->
DiscussionUtil
.
urlFor
(
"downvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'close'
:
->
DiscussionUtil
.
urlFor
(
'openclose_thread'
,
@
id
)
'update'
:
->
DiscussionUtil
.
urlFor
(
'update_thread'
,
@
id
)
'delete'
:
->
DiscussionUtil
.
urlFor
(
'delete_thread'
,
@
id
)
'follow'
:
->
DiscussionUtil
.
urlFor
(
'follow_thread'
,
@
id
)
'unfollow'
:
->
DiscussionUtil
.
urlFor
(
'unfollow_thread'
,
@
id
)
initialize
:
->
@
set
(
'thread'
,
@
)
super
()
permalink
:
->
discussion_id
=
@
get
(
'commentable_id'
)
return
Discussion
.
urlFor
(
"permanent_link_thread"
,
discussion_id
,
@
id
)
class
@
ThreadView
extends
@
ContentView
class
@
Comment
extends
@
Content
urlMappers
:
'reply'
:
->
DiscussionUtil
.
urlFor
(
'create_sub_comment'
,
@
id
)
'unvote'
:
->
DiscussionUtil
.
urlFor
(
"undo_vote_for_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'upvote'
:
->
DiscussionUtil
.
urlFor
(
"upvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'downvote'
:
->
DiscussionUtil
.
urlFor
(
"downvote_
#{
@
get
(
'type'
)
}
"
,
@
id
)
'endorse'
:
->
DiscussionUtil
.
urlFor
(
'endorse_comment'
,
@
id
)
'update'
:
->
DiscussionUtil
.
urlFor
(
'update_comment'
,
@
id
)
'delete'
:
->
DiscussionUtil
.
urlFor
(
'delete_comment'
,
@
id
)
permalink
:
->
thread_id
=
@
get
(
'thread'
).
id
discussion_id
=
@
get
(
'thread'
).
get
(
'commentable_id'
)
return
Discussion
.
urlFor
(
"permanent_link_comment"
,
discussion_id
,
thread_id
,
@
id
)
getCommentsCount
:
->
count
=
0
@
get
(
'comments'
).
each
(
comment
)
->
count
+=
comment
.
getCommentsCount
()
+
1
count
class
@
CommentView
extends
@
ContentView
class
@
Comments
extends
Backbone
.
Collection
model
:
Comment
initialize
:
->
@
bind
"add"
,
(
item
)
=>
item
.
collection
=
@
find
:
(
id
)
->
_
.
first
@
where
(
id
:
id
)
lms/static/coffee/src/discussion/discussion.coffee
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
initializeFollowDiscussion
=
(
discussion
)
->
$discussion
=
$
(
discussion
)
id
=
$following
.
attr
(
"_id"
)
$local
=
Discussion
.
generateLocal
()
$discussion
.
children
(
".discussion-non-content"
)
.
find
(
".discussion-title-wrapper"
)
.
append
(
Discussion
.
subscriptionLink
(
'discussion'
,
id
))
@
Discussion
=
$
.
extend
@
Discussion
,
initializeDiscussion
:
(
discussion
)
->
$discussion
=
$
(
discussion
)
$discussion
.
find
(
".thread"
).
each
(
index
,
thread
)
->
Discussion
.
initializeContent
(
thread
)
Discussion
.
bindContentEvents
(
thread
)
$discussion
.
find
(
".comment"
).
each
(
index
,
comment
)
->
Discussion
.
initializeContent
(
comment
)
Discussion
.
bindContentEvents
(
comment
)
#initializeFollowDiscussion(discussion) TODO move this somewhere else
bindDiscussionEvents
:
(
discussion
)
->
$discussion
=
$
(
discussion
)
$discussionNonContent
=
$discussion
.
children
(
".discussion-non-content"
)
$local
=
Discussion
.
generateLocal
(
$discussion
.
children
(
".discussion-local"
))
id
=
$discussion
.
attr
(
"_id"
)
handleSubmitNewPost
=
(
elem
)
->
title
=
$local
(
".new-post-title"
).
val
()
body
=
Discussion
.
getWmdContent
$discussion
,
$local
,
"new-post-body"
tags
=
$local
(
".new-post-tags"
).
val
()
url
=
Discussion
.
urlFor
(
'create_thread'
,
id
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
title
:
title
body
:
body
tags
:
tags
error
:
Discussion
.
formErrorHandler
(
$local
(
".new-post-form-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".new-post-form-errors"
))
$thread
=
$
(
response
.
html
)
$discussion
.
children
(
".threads"
).
prepend
(
$thread
)
$local
(
".new-post-title"
).
val
(
""
)
Discussion
.
setWmdContent
$discussion
,
$local
,
"new-post-body"
,
""
$local
(
".new-post-tags"
).
val
(
""
)
if
$discussion
.
hasClass
(
"inline-discussion"
)
$local
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
hide
()
handleCancelNewPost
=
(
elem
)
->
if
$discussion
.
hasClass
(
"inline-discussion"
)
$local
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
hide
()
handleSimilarPost
=
(
elem
)
->
$title
=
$local
(
".new-post-title"
)
$wrapper
=
$local
(
".new-post-similar-posts-wrapper"
)
$similarPosts
=
$local
(
".new-post-similar-posts"
)
prevText
=
$title
.
attr
(
"prev-text"
)
text
=
$title
.
val
()
if
text
==
prevText
if
$local
(
".similar-post"
).
length
class
@
Discussion
extends
Backbone
.
Collection
model
:
Thread
initialize
:
->
DiscussionUtil
.
addDiscussion
@
id
,
@
@
bind
"add"
,
(
item
)
=>
item
.
discussion
=
@
find
:
(
id
)
->
_
.
first
@
where
(
id
:
id
)
addThread
:
(
thread
,
options
)
->
options
||=
{}
model
=
new
Thread
thread
@
add
model
model
class
@
DiscussionView
extends
Backbone
.
View
$
:
(
selector
)
->
@
$local
.
find
(
selector
)
initLocal
:
->
@
$local
=
@
$el
.
children
(
".local"
)
@
$delegateElement
=
@
$local
initialize
:
->
@
initLocal
()
@
model
.
id
=
@
$el
.
attr
(
"_id"
)
@
model
.
view
=
@
@
$el
.
children
(
".threads"
).
children
(
".thread"
).
each
(
index
,
elem
)
=>
threadView
=
new
ThreadView
el
:
elem
,
model
:
@
model
.
find
$
(
elem
).
attr
(
"_id"
)
if
@
$el
.
hasClass
(
"forum-discussion"
)
$
(
".discussion-sidebar"
).
find
(
".sidebar-new-post-button"
)
.
unbind
(
'click'
).
click
$
.
proxy
@
newPost
,
@
else
if
@
$el
.
hasClass
(
"inline-discussion"
)
@
newPost
()
reload
:
(
$elem
,
url
)
->
if
not
url
then
return
DiscussionUtil
.
get
$elem
,
url
,
{},
(
response
,
textStatus
)
=>
$parent
=
@
$el
.
parent
()
@
$el
.
replaceWith
(
response
.
html
)
$discussion
=
$parent
.
find
(
"section.discussion"
)
@
model
.
reset
(
response
.
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
el
:
$discussion
[
0
],
model
:
@
model
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
loadSimilarPost
:
(
event
)
->
$title
=
@
$
(
".new-post-title"
)
$wrapper
=
@
$
(
".new-post-similar-posts-wrapper"
)
$similarPosts
=
@
$
(
".new-post-similar-posts"
)
prevText
=
$title
.
attr
(
"prev-text"
)
text
=
$title
.
val
()
if
text
==
prevText
if
@
$
(
".similar-post"
).
length
$wrapper
.
show
()
else
if
$
.
trim
(
text
).
length
$elem
=
$
(
event
.
target
)
url
=
DiscussionUtil
.
urlFor
'search_similar_threads'
,
@
model
.
id
data
=
{
text
:
@
$
(
".new-post-title"
).
val
()
}
DiscussionUtil
.
get
$elem
,
url
,
data
,
(
response
,
textStatus
)
=>
$similarPosts
.
empty
()
if
$
.
type
(
response
)
==
"array"
and
response
.
length
$wrapper
.
show
()
else
if
$
.
trim
(
text
).
length
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
Discussion
.
urlFor
'search_similar_threads'
,
id
type
:
"GET"
dateType
:
'json'
data
:
text
:
$local
(
".new-post-title"
).
val
()
success
:
(
response
,
textStatus
)
->
$similarPosts
.
empty
()
console
.
log
response
if
$
.
type
(
response
)
==
"array"
and
response
.
length
$wrapper
.
show
()
for
thread
in
response
#singleThreadUrl = Discussion.urlFor 'retrieve_single_thread
$similarPost
=
$
(
"<a>"
).
addClass
(
"similar-post"
)
.
html
(
thread
[
"title"
])
.
attr
(
"href"
,
"javascript:void(0)"
)
#TODO
.
appendTo
(
$similarPosts
)
else
$wrapper
.
hide
()
else
$wrapper
.
hide
()
$title
.
attr
(
"prev-text"
,
text
)
initializeNewPost
=
->
view
=
{
discussion_id
:
id
}
$discussionNonContent
=
$discussion
.
children
(
".discussion-non-content"
)
if
not
$local
(
".wmd-panel"
).
length
$discussionNonContent
.
append
Mustache
.
render
Discussion
.
newPostTemplate
,
view
$newPostBody
=
$local
(
".new-post-body"
)
Discussion
.
makeWmdEditor
$discussion
,
$local
,
"new-post-body"
$input
=
Discussion
.
getWmdInput
(
$discussion
,
$local
,
"new-post-body"
)
$input
.
attr
(
"placeholder"
,
"post a new topic..."
)
if
$discussion
.
hasClass
(
"inline-discussion"
)
$input
.
bind
'focus'
,
(
e
)
->
$local
(
".new-post-form"
).
removeClass
(
'collapsed'
)
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
removeClass
(
'collapsed'
)
$local
(
".new-post-tags"
).
tagsInput
Discussion
.
tagsInputOptions
()
$local
(
".new-post-title"
).
blur
->
handleSimilarPost
(
this
)
$local
(
".hide-similar-posts"
).
click
->
$local
(
".new-post-similar-posts-wrapper"
).
hide
()
$local
(
".discussion-submit-post"
).
click
->
handleSubmitNewPost
(
this
)
$local
(
".discussion-cancel-post"
).
click
->
handleCancelNewPost
(
this
)
$local
(
".new-post-form"
).
show
()
handleAjaxReloadDiscussion
=
(
elem
,
url
)
->
if
not
url
then
return
$elem
=
$
(
elem
)
$discussion
=
$elem
.
parents
(
"section.discussion"
)
Discussion
.
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
dataType
:
'html'
success
:
(
data
,
textStatus
)
->
$data
=
$
(
data
)
$parent
=
$discussion
.
parent
()
$discussion
.
replaceWith
(
$data
)
$discussion
=
$parent
.
children
(
".discussion"
)
Discussion
.
initializeDiscussion
(
$discussion
)
Discussion
.
bindDiscussionEvents
(
$discussion
)
handleAjaxSearch
=
(
elem
)
->
$elem
=
$
(
elem
)
url
=
URI
(
$elem
.
attr
(
"action"
)).
addSearch
({
text
:
$local
(
".search-input"
).
val
()})
handleAjaxReloadDiscussion
(
$elem
,
url
)
handleAjaxSort
=
(
elem
)
->
$elem
=
$
(
elem
)
url
=
$elem
.
attr
(
"sort-url"
)
handleAjaxReloadDiscussion
(
$elem
,
url
)
handleAjaxPage
=
(
elem
)
->
$elem
=
$
(
elem
)
url
=
$elem
.
attr
(
"page-url"
)
handleAjaxReloadDiscussion
(
$elem
,
url
)
if
$discussion
.
hasClass
(
"inline-discussion"
)
initializeNewPost
()
if
$discussion
.
hasClass
(
"forum-discussion"
)
$discussionSidebar
=
$
(
".discussion-sidebar"
)
if
$discussionSidebar
.
length
$sidebarLocal
=
Discussion
.
generateLocal
(
$discussionSidebar
)
Discussion
.
bindLocalEvents
$sidebarLocal
,
"click .sidebar-new-post-button"
:
(
event
)
->
initializeNewPost
()
Discussion
.
bindLocalEvents
$local
,
"submit .search-wrapper>.discussion-search-form"
:
(
event
)
->
event
.
preventDefault
()
handleAjaxSearch
(
this
)
"click .discussion-search-link"
:
->
handleAjaxSearch
(
$local
(
".search-wrapper>.discussion-search-form"
))
"click .discussion-sort-link"
:
->
handleAjaxSort
(
this
)
$discussion
.
children
(
".discussion-paginator"
).
find
(
".discussion-page-link"
).
unbind
(
'click'
).
click
->
handleAjaxPage
(
this
)
for
thread
in
response
$similarPost
=
$
(
"<a>"
).
addClass
(
"similar-post"
)
.
html
(
thread
[
"title"
])
.
attr
(
"href"
,
"javascript:void(0)"
)
#TODO
.
appendTo
(
$similarPosts
)
else
$wrapper
.
hide
()
else
$wrapper
.
hide
()
$title
.
attr
(
"prev-text"
,
text
)
newPost
:
->
if
not
@
$
(
".wmd-panel"
).
length
view
=
{
discussion_id
:
@
model
.
id
}
@
$el
.
children
(
".discussion-non-content"
).
append
Mustache
.
render
DiscussionUtil
.
getTemplate
(
"_new_post"
),
view
$newPostBody
=
@
$
(
".new-post-body"
)
DiscussionUtil
.
makeWmdEditor
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
$input
=
DiscussionUtil
.
getWmdInput
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
$input
.
attr
(
"placeholder"
,
"post a new topic..."
)
if
@
$el
.
hasClass
(
"inline-discussion"
)
$input
.
bind
'focus'
,
(
e
)
=>
@
$
(
".new-post-form"
).
removeClass
(
'collapsed'
)
else
if
@
$el
.
hasClass
(
"forum-discussion"
)
@
$
(
".new-post-form"
).
removeClass
(
'collapsed'
)
@
$
(
".new-post-tags"
).
tagsInput
DiscussionUtil
.
tagsInputOptions
()
@
$
(
".new-post-title"
).
blur
$
.
proxy
(
@
loadSimilarPost
,
@
)
@
$
(
".hide-similar-posts"
).
click
=>
@
$
(
".new-post-similar-posts-wrapper"
).
hide
()
@
$
(
".discussion-submit-post"
).
click
$
.
proxy
(
@
submitNewPost
,
@
)
@
$
(
".discussion-cancel-post"
).
click
$
.
proxy
(
@
cancelNewPost
,
@
)
@
$
(
".new-post-form"
).
show
()
submitNewPost
:
(
event
)
->
title
=
@
$
(
".new-post-title"
).
val
()
body
=
DiscussionUtil
.
getWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
tags
=
@
$
(
".new-post-tags"
).
val
()
anonymous
=
false
||
@
$
(
".discussion-post-anonymously"
).
is
(
":checked"
)
autowatch
=
false
||
@
$
(
".discussion-auto-watch"
).
is
(
":checked"
)
url
=
DiscussionUtil
.
urlFor
(
'create_thread'
,
@
model
.
id
)
DiscussionUtil
.
safeAjax
$elem
:
$
(
event
.
target
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
title
:
title
body
:
body
tags
:
tags
anonymous
:
anonymous
auto_subscribe
:
autowatch
error
:
DiscussionUtil
.
formErrorHandler
(
@
$
(
".new-post-form-errors"
))
success
:
(
response
,
textStatus
)
=>
DiscussionUtil
.
clearFormErrors
(
@
$
(
".new-post-form-errors"
))
$thread
=
$
(
response
.
html
)
@
$el
.
children
(
".threads"
).
prepend
(
$thread
)
@
$
(
".new-post-title"
).
val
(
""
)
DiscussionUtil
.
setWmdContent
@
$el
,
$
.
proxy
(
@
$
,
@
),
"new-post-body"
,
""
@
$
(
".new-post-tags"
).
val
(
""
)
@
$
(
".new-post-tags"
).
importTags
(
""
)
thread
=
@
model
.
addThread
response
.
content
threadView
=
new
ThreadView
el
:
$thread
[
0
],
model
:
thread
thread
.
updateInfo
response
.
annotated_content_info
@
cancelNewPost
()
cancelNewPost
:
(
event
)
->
if
@
$el
.
hasClass
(
"inline-discussion"
)
@
$
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
if
@
$el
.
hasClass
(
"forum-discussion"
)
@
$
(
".new-post-form"
).
hide
()
search
:
(
event
)
->
event
.
preventDefault
()
$elem
=
$
(
event
.
target
)
url
=
URI
(
$elem
.
attr
(
"action"
)).
addSearch
({
text
:
@
$
(
".search-input"
).
val
()})
@
reload
(
$elem
,
url
)
sort
:
->
$elem
=
$
(
event
.
target
)
url
=
$elem
.
attr
(
"sort-url"
)
@
reload
(
$elem
,
url
)
page
:
(
event
)
->
$elem
=
$
(
event
.
target
)
url
=
$elem
.
attr
(
"page-url"
)
@
reload
(
$elem
,
url
)
events
:
"submit .search-wrapper>.discussion-search-form"
:
"search"
"click .discussion-search-link"
:
"search"
"click .discussion-sort-link"
:
"sort"
"click .discussion-page-link"
:
"page"
lms/static/coffee/src/discussion/discussion_module.coffee
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
@
Discussion
=
$
.
extend
@
Discussion
,
initializeDiscussionModule
:
(
elem
)
->
$discussionModule
=
$
(
elem
)
$local
=
Discussion
.
generateLocal
(
$discussionModule
)
handleShowDiscussion
=
(
elem
)
->
$elem
=
$
(
elem
)
if
not
$local
(
"section.discussion"
).
length
class
@
DiscussionModuleView
extends
Backbone
.
View
events
:
"click .discussion-show"
:
"toggleDiscussion"
toggleDiscussion
:
(
event
)
->
if
@
showed
@
$
(
"section.discussion"
).
hide
()
$
(
event
.
target
).
html
(
"Show Discussion"
)
@
showed
=
false
else
if
@
retrieved
@
$
(
"section.discussion"
).
show
()
$
(
event
.
target
).
html
(
"Hide Discussion"
)
@
showed
=
true
else
$elem
=
$
(
event
.
target
)
discussion_id
=
$elem
.
attr
(
"discussion_id"
)
url
=
Discussion
.
urlFor
'retrieve_discussion'
,
discussion_id
url
=
Discussion
Util
.
urlFor
'retrieve_discussion'
,
discussion_id
Discussion
.
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
success
:
(
data
,
textStatus
,
xhr
)
->
$discussionModule
.
append
(
data
)
discussion
=
$local
(
"section.discussion"
)
Discussion
.
initializeDiscussion
(
discussion
)
Discussion
.
bindDiscussionEvents
(
discussion
)
$elem
.
html
(
"Hide Discussion"
)
$elem
.
unbind
(
'click'
).
click
->
handleHideDiscussion
(
this
)
dataType
:
'html'
else
$local
(
"section.discussion"
).
show
()
$elem
.
html
(
"Hide Discussion"
)
$elem
.
unbind
(
'click'
).
click
->
handleHideDiscussion
(
this
)
handleHideDiscussion
=
(
elem
)
->
$local
(
"section.discussion"
).
hide
()
$elem
=
$
(
elem
)
$elem
.
html
(
"Show Discussion"
)
$elem
.
unbind
(
'click'
).
click
->
handleShowDiscussion
(
this
)
$local
(
".discussion-show"
).
click
->
handleShowDiscussion
(
this
)
dataType
:
'json'
success
:
(
response
,
textStatus
)
=>
@
$el
.
append
(
response
.
html
)
$discussion
=
@
$el
.
find
(
"section.discussion"
)
$
(
event
.
target
).
html
(
"Hide Discussion"
)
discussion
=
new
Discussion
()
discussion
.
reset
(
response
.
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
(
el
:
$discussion
[
0
],
model
:
discussion
)
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
@
retrieved
=
true
@
showed
=
true
lms/static/coffee/src/discussion/main.coffee
View file @
952c9d56
$
->
#toggle = ->
# $('.course-wrapper').toggleClass('closed')
window
.
$
$contents
=
{}
window
.
$
$discussions
=
{}
#Discussion = window.Discussion
#if $('#accordion').length
# active = $('#accordion ul:has(li.active)').index('#accordion ul')
# $('#accordion').bind('accordionchange', @log).accordion
# active: if active >= 0 then active else 1
# header: 'h3'
# autoHeight: false
# $('#open_close_accordion a').click toggle
# $('#accordion').show()
$
(
".discussion-module"
).
each
(
index
,
elem
)
->
view
=
new
DiscussionModuleView
(
el
:
elem
)
#$(".discussion-module").each (index, elem) ->
# Discussion.initializeDiscussionModule(elem)
$
(
"section.discussion"
).
each
(
index
,
elem
)
->
discussionData
=
DiscussionUtil
.
getDiscussionData
(
$
(
elem
).
attr
(
"_id"
))
discussion
=
new
Discussion
()
discussion
.
reset
(
discussionData
,
{
silent
:
false
})
view
=
new
DiscussionView
(
el
:
elem
,
model
:
discussion
)
#$("section.discussion").each (index, discussion) ->
# Discussion.initializeDiscussion(discussion)
# Discussion.bindDiscussionEvents(discussion)
#Discussion.initializeUserProfile($(".discussion-sidebar>.user-profile"))
DiscussionUtil
.
bulkUpdateContentInfo
(
window
.
$
$annotated_content_info
)
lms/static/coffee/src/discussion/templates.coffee
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
@
Discussion
=
$
.
extend
@
Discussion
,
newPostTemplate
:
"""
<form class="new-post-form collapsed" id="new-post-form" style="display: block; ">
<ul class="new-post-form-errors discussion-errors"></ul>
<input type="text" class="new-post-title title-input" placeholder="Title" />
<div class="new-post-similar-posts-wrapper" style="display: none">
Similar Posts:
<a class="hide-similar-posts" href="javascript:void(0)">Hide</a>
<div class="new-post-similar-posts"></div>
</div>
<div class="new-post-body reply-body"></div>
<input class="new-post-tags" placeholder="Tags" />
<div class="post-options">
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-${discussion_id}">
<label for="discussion-post-anonymously-${discussion_id}">post anonymously</label>
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-${discussion_id}" checked="">
<label for="discussion-auto-watch-${discussion_id}">follow this thread</label>
</div>
<div class="new-post-control post-control">
<a class="discussion-cancel-post" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-post control-button" href="javascript:void(0)">Submit</a>
</div>
</form>
"""
replyTemplate
:
"""
<form class="discussion-reply-new">
<ul class="discussion-errors"></ul>
<div class="reply-body"></div>
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-{{id}}" />
<label for="discussion-post-anonymously-{{id}}">post anonymously</label>
{{#showWatchCheckbox}}
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-{{id}}" checked />
<label for="discussion-auto-watch-{{id}}">follow this thread</label>
{{/showWatchCheckbox}}
<br />
<div class = "reply-post-control">
<a class="discussion-cancel-post" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-post control-button" href="javascript:void(0)">Submit</a>
</div>
</form>
"""
editThreadTemplate
:
"""
<form class="discussion-content-edit discussion-thread-edit" _id="{{id}}">
<ul class="discussion-errors discussion-update-errors"></ul>
<input type="text" class="thread-title-edit title-input" placeholder="Title" value="{{title}}"/>
<div class="thread-body-edit body-input">{{body}}</div>
<input class="thread-tags-edit" placeholder="Tags" value="{{tags}}" />
<div class = "edit-post-control">
<a class="discussion-cancel-update" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-update control-button" href="javascript:void(0)">Update</a>
</div>
</form>
"""
editCommentTemplate
:
"""
<form class="discussion-content-edit discussion-comment-edit" _id="{{id}}">
<ul class="discussion-errors discussion-update-errors"></ul>
<div class="comment-body-edit body-input">{{body}}</div>
<div class = "edit-post-control">
<a class="discussion-cancel-update" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-update control-button" href="javascript:void(0)">Update</a>
</div>
</form>
"""
lms/static/coffee/src/discussion/utils.coffee
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
class
@
DiscussionUtil
Discussion
=
@
Discussion
@
wmdEditors
:
{}
wmdEditors
=
{}
@
getTemplate
:
(
id
)
->
$
(
"script#
#{
id
}
"
).
html
()
@
Discussion
=
$
.
extend
@
Discussion
,
@
getDiscussionData
:
(
id
)
->
return
$$discussion_data
[
id
]
generateLocal
:
(
elem
)
->
(
selector
)
->
$
(
elem
).
find
(
selector
)
@
addContent
:
(
id
,
content
)
->
window
.
$
$contents
[
id
]
=
content
generateDiscussionLink
:
(
cls
,
txt
,
handler
)
->
@
getContent
:
(
id
)
->
window
.
$
$contents
[
id
]
@
addDiscussion
:
(
id
,
discussion
)
->
window
.
$
$discussions
[
id
]
=
discussion
@
getDiscussion
:
(
id
)
->
window
.
$
$discussions
[
id
]
@
bulkUpdateContentInfo
:
(
infos
)
->
for
id
,
info
of
infos
@
getContent
(
id
).
updateInfo
(
info
)
@
generateDiscussionLink
:
(
cls
,
txt
,
handler
)
->
$
(
"<a>"
).
addClass
(
"discussion-link"
)
.
attr
(
"href"
,
"javascript:void(0)"
)
.
addClass
(
cls
).
html
(
txt
)
.
click
->
handler
(
this
)
urlFor
:
(
name
,
param
,
param1
,
param2
)
->
@
urlFor
:
(
name
,
param
,
param1
,
param2
)
->
{
follow_discussion
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/follow"
unfollow_discussion
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/unfollow"
...
...
@@ -48,7 +58,7 @@ wmdEditors = {}
permanent_link_comment
:
"/courses/
#{
$$course_id
}
/discussion/forum/
#{
param
}
/threads/
#{
param1
}
#
#{
param2
}
"
}[
name
]
safeAjax
:
(
params
)
->
@
safeAjax
:
(
params
)
->
$elem
=
params
.
$elem
if
$elem
.
attr
(
"disabled"
)
return
...
...
@@ -56,17 +66,31 @@ wmdEditors = {}
$
.
ajax
(
params
).
always
->
$elem
.
removeAttr
(
"disabled"
)
handleAnchorAndReload
:
(
response
)
->
#window.location = window.location.pathname + "#" + response['id']
window
.
location
.
reload
()
bindLocalEvents
:
(
$local
,
eventsHandler
)
->
@
get
:
(
$elem
,
url
,
data
,
success
)
->
@
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
dataType
:
"json"
data
:
data
success
:
success
@
post
:
(
$elem
,
url
,
data
,
success
)
->
@
safeAjax
$elem
:
$elem
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
data
success
:
success
@
bindLocalEvents
:
(
$local
,
eventsHandler
)
->
for
eventSelector
,
handler
of
eventsHandler
[
event
,
selector
]
=
eventSelector
.
split
(
' '
)
$local
(
selector
).
unbind
(
event
)[
event
]
handler
tagsInputOptions
:
->
autocomplete_url
:
Discussion
.
urlFor
(
'tags_autocomplete'
)
@
tagsInputOptions
:
->
autocomplete_url
:
@
urlFor
(
'tags_autocomplete'
)
autocomplete
:
remoteDataType
:
'json'
interactive
:
true
...
...
@@ -75,23 +99,7 @@ wmdEditors = {}
defaultText
:
"Tag your post: press enter after each tag"
removeWithBackspace
:
true
isSubscribed
:
(
id
,
type
)
->
$$user_info
?
and
(
if
type
==
"thread"
id
in
$$user_info
.
subscribed_thread_ids
else
if
type
==
"commentable"
or
type
==
"discussion"
id
in
$$user_info
.
subscribed_commentable_ids
else
id
in
$$user_info
.
subscribed_user_ids
)
isUpvoted
:
(
id
)
->
$$user_info
?
and
(
id
in
$$user_info
.
upvoted_ids
)
isDownvoted
:
(
id
)
->
$$user_info
?
and
(
id
in
$$user_info
.
downvoted_ids
)
formErrorHandler
:
(
errorsField
)
->
@
formErrorHandler
:
(
errorsField
)
->
(
xhr
,
textStatus
,
error
)
->
response
=
JSON
.
parse
(
xhr
.
responseText
)
if
response
.
errors
?
and
response
.
errors
.
length
>
0
...
...
@@ -99,13 +107,13 @@ wmdEditors = {}
for
error
in
response
.
errors
errorsField
.
append
(
$
(
"<li>"
).
addClass
(
"new-post-form-error"
).
html
(
error
))
clearFormErrors
:
(
errorsField
)
->
@
clearFormErrors
:
(
errorsField
)
->
errorsField
.
empty
()
postMathJaxProcessor
:
(
text
)
->
@
postMathJaxProcessor
:
(
text
)
->
RE_INLINEMATH
=
/^\$([^\$]*)\$/g
RE_DISPLAYMATH
=
/^\$\$([^\$]*)\$\$/g
Discussion
.
processEachMathAndCode
text
,
(
s
,
type
)
->
@
processEachMathAndCode
text
,
(
s
,
type
)
->
if
type
==
'display'
s
.
replace
RE_DISPLAYMATH
,
(
$0
,
$1
)
->
"
\\
["
+
$1
+
"
\\
]"
...
...
@@ -115,61 +123,43 @@ wmdEditors = {}
else
s
makeWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
@
makeWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
elem
=
$local
(
".
#{
cls_identifier
}
"
)
id
=
$content
.
attr
(
"_id"
)
appended_id
=
"-
#{
cls_identifier
}
-
#{
id
}
"
imageUploadUrl
=
Discussion
.
urlFor
(
'upload'
)
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
,
Discussion
.
postMathJaxProcessor
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
imageUploadUrl
=
@
urlFor
(
'upload'
)
_processor
=
(
_this
)
->
(
text
)
->
_this
.
postMathJaxProcessor
(
text
)
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
,
_processor
(
@
)
@
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
editor
getWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
@
getWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
id
=
$content
.
attr
(
"_id"
)
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
@
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
getWmdInput
:
(
$content
,
$local
,
cls_identifier
)
->
@
getWmdInput
:
(
$content
,
$local
,
cls_identifier
)
->
id
=
$content
.
attr
(
"_id"
)
$local
(
"#wmd-input-
#{
cls_identifier
}
-
#{
id
}
"
)
getWmdContent
:
(
$content
,
$local
,
cls_identifier
)
->
Discussion
.
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
()
setWmdContent
:
(
$content
,
$local
,
cls_identifier
,
text
)
->
Discussion
.
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
(
text
)
Discussion
.
getWmdEditor
(
$content
,
$local
,
cls_identifier
).
refreshPreview
()
getContentInfo
:
(
id
,
attr
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
(
window
.
$
$annotated_content_info
[
id
]
||
{})[
attr
]
setContentInfo
:
(
id
,
attr
,
value
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
[
id
]
||=
{}
window
.
$
$annotated_content_info
[
id
][
attr
]
=
value
extendContentInfo
:
(
id
,
newInfo
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
[
id
]
=
newInfo
bulkExtendContentInfo
:
(
newInfos
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
=
$
.
extend
window
.
$
$annotated_content_info
,
newInfos
subscriptionLink
:
(
type
,
id
)
->
@
getWmdContent
:
(
$content
,
$local
,
cls_identifier
)
->
@
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
()
@
setWmdContent
:
(
$content
,
$local
,
cls_identifier
,
text
)
->
@
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
(
text
)
@
getWmdEditor
(
$content
,
$local
,
cls_identifier
).
refreshPreview
()
@
subscriptionLink
:
(
type
,
id
)
->
followLink
=
->
Discussion
.
generateDiscussionLink
(
"discussion-follow-
#{
type
}
"
,
"Follow"
,
handleFollow
)
@
generateDiscussionLink
(
"discussion-follow-
#{
type
}
"
,
"Follow"
,
handleFollow
)
unfollowLink
=
->
Discussion
.
generateDiscussionLink
(
"discussion-unfollow-
#{
type
}
"
,
"Unfollow"
,
handleUnfollow
)
@
generateDiscussionLink
(
"discussion-unfollow-
#{
type
}
"
,
"Unfollow"
,
handleUnfollow
)
handleFollow
=
(
elem
)
->
Discussion
.
safeAjax
@
safeAjax
$elem
:
$
(
elem
)
url
:
Discussion
.
urlFor
(
"follow_
#{
type
}
"
,
id
)
url
:
@
urlFor
(
"follow_
#{
type
}
"
,
id
)
type
:
"POST"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
...
...
@@ -177,21 +167,21 @@ wmdEditors = {}
dataType
:
'json'
handleUnfollow
=
(
elem
)
->
Discussion
.
safeAjax
@
safeAjax
$elem
:
$
(
elem
)
url
:
Discussion
.
urlFor
(
"unfollow_
#{
type
}
"
,
id
)
url
:
@
urlFor
(
"unfollow_
#{
type
}
"
,
id
)
type
:
"POST"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$
(
elem
).
replaceWith
followLink
()
dataType
:
'json'
if
Discussion
.
isSubscribed
(
id
,
type
)
if
@
isSubscribed
(
id
,
type
)
unfollowLink
()
else
followLink
()
processEachMathAndCode
:
(
text
,
processor
)
->
@
processEachMathAndCode
:
(
text
,
processor
)
->
codeArchive
=
[]
...
...
@@ -242,3 +232,18 @@ wmdEditors = {}
text
=
$div
.
html
()
text
@
unescapeHighlightTag
:
(
text
)
->
text
.
replace
(
/\<\;highlight\>\;/g
,
"<span class='search-highlight'>"
)
.
replace
(
/\<\;\/highlight\>\;/g
,
"</span>"
)
@
stripHighlight
:
(
text
)
->
text
.
replace
(
/\&(amp\;)?lt\;highlight\&(amp\;)?gt\;/g
,
""
)
.
replace
(
/\&(amp\;)?lt\;\/highlight\&(amp\;)?gt\;/g
,
""
)
@
stripLatexHighlight
:
(
text
)
->
@
processEachMathAndCode
text
,
@
stripHighlight
@
markdownWithHighlight
:
(
text
)
->
converter
=
Markdown
.
getMathCompatibleConverter
()
@
unescapeHighlightTag
@
stripLatexHighlight
converter
.
makeHtml
text
lms/static/coffee/src/old_discussion/content.coffee
0 → 100644
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
initializeVote
=
(
content
)
->
$content
=
$
(
content
)
$local
=
Discussion
.
generateLocal
(
$content
.
children
(
".discussion-content"
))
id
=
$content
.
attr
(
"_id"
)
if
Discussion
.
isUpvoted
id
$local
(
".discussion-vote-up"
).
addClass
(
"voted"
)
else
if
Discussion
.
isDownvoted
id
$local
(
".discussion-vote-down"
).
addClass
(
"voted"
)
initializeFollowThread
=
(
thread
)
->
$thread
=
$
(
thread
)
id
=
$thread
.
attr
(
"_id"
)
$thread
.
children
(
".discussion-content"
)
.
find
(
".follow-wrapper"
)
.
append
(
Discussion
.
subscriptionLink
(
'thread'
,
id
))
@
Discussion
=
$
.
extend
@
Discussion
,
bindContentEvents
:
(
content
)
->
$content
=
$
(
content
)
$discussionContent
=
$content
.
children
(
".discussion-content"
)
$local
=
Discussion
.
generateLocal
(
$discussionContent
)
id
=
$content
.
attr
(
"_id"
)
handleReply
=
(
elem
)
->
$replyView
=
$local
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
show
()
else
thread_id
=
$discussionContent
.
parents
(
".thread"
).
attr
(
"_id"
)
view
=
id
:
id
showWatchCheckbox
:
not
Discussion
.
isSubscribed
(
thread_id
,
"thread"
)
$discussionContent
.
append
Mustache
.
render
Discussion
.
replyTemplate
,
view
Discussion
.
makeWmdEditor
$content
,
$local
,
"reply-body"
$local
(
".discussion-submit-post"
).
click
->
handleSubmitReply
(
this
)
$local
(
".discussion-cancel-post"
).
click
->
handleCancelReply
(
this
)
$local
(
".discussion-reply"
).
hide
()
$local
(
".discussion-edit"
).
hide
()
handleCancelReply
=
(
elem
)
->
$replyView
=
$local
(
".discussion-reply-new"
)
if
$replyView
.
length
$replyView
.
hide
()
$local
(
".discussion-reply"
).
show
()
$local
(
".discussion-edit"
).
show
()
handleSubmitReply
=
(
elem
)
->
if
$content
.
hasClass
(
"thread"
)
url
=
Discussion
.
urlFor
(
'create_comment'
,
id
)
else
if
$content
.
hasClass
(
"comment"
)
url
=
Discussion
.
urlFor
(
'create_sub_comment'
,
id
)
else
return
body
=
Discussion
.
getWmdContent
$content
,
$local
,
"reply-body"
anonymous
=
false
||
$local
(
".discussion-post-anonymously"
).
is
(
":checked"
)
autowatch
=
false
||
$local
(
".discussion-auto-watch"
).
is
(
":checked"
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
body
:
body
anonymous
:
anonymous
autowatch
:
autowatch
error
:
Discussion
.
formErrorHandler
(
$local
(
".discussion-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".discussion-errors"
))
$comment
=
$
(
response
.
html
)
$content
.
children
(
".comments"
).
prepend
(
$comment
)
Discussion
.
setWmdContent
$content
,
$local
,
"reply-body"
,
""
Discussion
.
setContentInfo
response
.
content
[
'id'
],
'can_reply'
,
true
Discussion
.
setContentInfo
response
.
content
[
'id'
],
'editable'
,
true
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$comment
)
Discussion
.
bindContentEvents
(
$comment
)
@
cancelReply
()
$local
(
".discussion-reply-new"
).
hide
()
$local
(
".discussion-reply"
).
show
()
$local
(
".discussion-edit"
).
show
()
$discussionContent
.
attr
(
"status"
,
"normal"
)
handleVote
=
(
elem
,
value
)
->
contentType
=
if
$content
.
hasClass
(
"thread"
)
then
"thread"
else
"comment"
url
=
Discussion
.
urlFor
(
"
#{
value
}
vote_
#{
contentType
}
"
,
id
)
Discussion
.
safeAjax
$elem
:
$local
(
".discussion-vote"
)
url
:
url
type
:
"POST"
dataType
:
"json"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$local
(
".discussion-vote"
).
removeClass
(
"voted"
)
$local
(
".discussion-vote-
#{
value
}
"
).
addClass
(
"voted"
)
$local
(
".discussion-votes-point"
).
html
response
.
votes
.
point
handleUnvote
=
(
elem
,
value
)
->
contentType
=
if
$content
.
hasClass
(
"thread"
)
then
"thread"
else
"comment"
url
=
Discussion
.
urlFor
(
"undo_vote_for_
#{
contentType
}
"
,
id
)
Discussion
.
safeAjax
$elem
:
$local
(
".discussion-vote"
)
url
:
url
type
:
"POST"
dataType
:
"json"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$local
(
".discussion-vote"
).
removeClass
(
"voted"
)
$local
(
".discussion-votes-point"
).
html
response
.
votes
.
point
handleCancelEdit
=
(
elem
)
->
$local
(
".discussion-content-edit"
).
hide
()
$local
(
".discussion-content-wrapper"
).
show
()
handleEditThread
=
(
elem
)
->
$local
(
".discussion-content-wrapper"
).
hide
()
$editView
=
$local
(
".discussion-content-edit"
)
if
$editView
.
length
$editView
.
show
()
else
view
=
{
id
:
id
title
:
$local
(
".thread-raw-title"
).
html
()
body
:
$local
(
".thread-raw-body"
).
html
()
tags
:
$local
(
".thread-raw-tags"
).
html
()
}
$discussionContent
.
append
Mustache
.
render
Discussion
.
editThreadTemplate
,
view
Discussion
.
makeWmdEditor
$content
,
$local
,
"thread-body-edit"
$local
(
".thread-tags-edit"
).
tagsInput
Discussion
.
tagsInputOptions
()
$local
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
->
handleSubmitEditThread
(
this
)
$local
(
".discussion-cancel-update"
).
unbind
(
"click"
).
click
->
handleCancelEdit
(
this
)
handleSubmitEditThread
=
(
elem
)
->
url
=
Discussion
.
urlFor
(
'update_thread'
,
id
)
title
=
$local
(
".thread-title-edit"
).
val
()
body
=
Discussion
.
getWmdContent
$content
,
$local
,
"thread-body-edit"
tags
=
$local
(
".thread-tags-edit"
).
val
()
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
{
title
:
title
,
body
:
body
,
tags
:
tags
},
error
:
Discussion
.
formErrorHandler
(
$local
(
".discussion-update-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".discussion-update-errors"
))
$discussionContent
.
replaceWith
(
response
.
html
)
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$content
)
Discussion
.
bindContentEvents
(
$content
)
handleEditComment
=
(
elem
)
->
$local
(
".discussion-content-wrapper"
).
hide
()
$editView
=
$local
(
".discussion-content-edit"
)
if
$editView
.
length
$editView
.
show
()
else
view
=
{
id
:
id
,
body
:
$local
(
".comment-raw-body"
).
html
()
}
$discussionContent
.
append
Mustache
.
render
Discussion
.
editCommentTemplate
,
view
Discussion
.
makeWmdEditor
$content
,
$local
,
"comment-body-edit"
$local
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
->
handleSubmitEditComment
(
this
)
$local
(
".discussion-cancel-update"
).
unbind
(
"click"
).
click
->
handleCancelEdit
(
this
)
handleSubmitEditComment
=
(
elem
)
->
url
=
Discussion
.
urlFor
(
'update_comment'
,
id
)
body
=
Discussion
.
getWmdContent
$content
,
$local
,
"comment-body-edit"
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{
body
:
body
}
error
:
Discussion
.
formErrorHandler
(
$local
(
".discussion-update-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".discussion-update-errors"
))
$discussionContent
.
replaceWith
(
response
.
html
)
Discussion
.
extendContentInfo
response
.
content
[
'id'
],
response
[
'annotated_content_info'
]
Discussion
.
initializeContent
(
$content
)
Discussion
.
bindContentEvents
(
$content
)
handleEndorse
=
(
elem
,
endorsed
)
->
url
=
Discussion
.
urlFor
(
'endorse_comment'
,
id
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{
endorsed
:
endorsed
}
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
if
endorsed
$
(
content
).
addClass
(
"endorsed"
)
else
$
(
content
).
removeClass
(
"endorsed"
)
$
(
elem
).
unbind
(
'click'
).
click
->
handleEndorse
(
elem
,
!
endorsed
)
handleOpenClose
=
(
elem
,
text
)
->
url
=
Discussion
.
urlFor
(
'openclose_thread'
,
id
)
closed
=
undefined
if
text
.
match
(
/Close/
)
closed
=
true
else
if
text
.
match
(
/[Oo]pen/
)
closed
=
false
else
console
.
log
"Unexpected text "
+
text
+
"for open/close thread."
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{
closed
:
closed
}
success
:
(
response
,
textStatus
)
=>
if
textStatus
==
"success"
if
closed
$
(
content
).
addClass
(
"closed"
)
$
(
elem
).
text
"Re-open Thread"
else
$
(
content
).
removeClass
(
"closed"
)
$
(
elem
).
text
"Close Thread"
error
:
(
response
,
textStatus
,
e
)
->
console
.
log
e
handleDelete
=
(
elem
)
->
if
$content
.
hasClass
(
"thread"
)
url
=
Discussion
.
urlFor
(
'delete_thread'
,
id
)
c
=
confirm
"Are you sure to delete thread
\"
"
+
$content
.
find
(
"a.thread-title"
).
text
()
+
"
\"
?"
else
url
=
Discussion
.
urlFor
(
'delete_comment'
,
id
)
c
=
confirm
"Are you sure to delete this comment? "
if
c
!=
true
return
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
{}
success
:
(
response
,
textStatus
)
=>
if
textStatus
==
"success"
$
(
content
).
remove
()
error
:
(
response
,
textStatus
,
e
)
->
console
.
log
e
handleHideSingleThread
=
(
elem
)
->
$threadTitle
=
$local
(
".thread-title"
)
$hideComments
=
$local
(
".discussion-hide-comments"
)
$hideComments
.
removeClass
(
"discussion-hide-comments"
)
.
addClass
(
"discussion-show-comments"
)
$content
.
children
(
".comments"
).
hide
()
$threadTitle
.
unbind
(
'click'
).
click
handleShowSingleThread
$hideComments
.
unbind
(
'click'
).
click
handleShowSingleThread
prevHtml
=
$hideComments
.
html
()
$hideComments
.
html
prevHtml
.
replace
"Hide"
,
"Show"
handleShowSingleThread
=
->
$threadTitle
=
$local
(
".thread-title"
)
$showComments
=
$local
(
".discussion-show-comments"
)
if
not
$showComments
.
hasClass
(
"first-time"
)
and
(
not
$showComments
.
length
or
not
$threadTitle
.
length
)
return
rebindHideEvents
=
->
$threadTitle
.
unbind
(
'click'
).
click
handleHideSingleThread
$showComments
.
unbind
(
'click'
).
click
handleHideSingleThread
$showComments
.
removeClass
(
"discussion-show-comments"
)
.
addClass
(
"discussion-hide-comments"
)
prevHtml
=
$showComments
.
html
()
$showComments
.
html
prevHtml
.
replace
"Show"
,
"Hide"
if
not
$showComments
.
hasClass
(
"first-time"
)
and
$content
.
children
(
".comments"
).
length
$content
.
children
(
".comments"
).
show
()
rebindHideEvents
()
else
discussion_id
=
$threadTitle
.
parents
(
".discussion"
).
attr
(
"_id"
)
url
=
Discussion
.
urlFor
(
'retrieve_single_thread'
,
discussion_id
,
id
)
Discussion
.
safeAjax
$elem
:
$
.
merge
(
$threadTitle
,
$showComments
)
url
:
url
type
:
"GET"
dataType
:
'json'
success
:
(
response
,
textStatus
)
->
Discussion
.
bulkExtendContentInfo
response
[
'annotated_content_info'
]
$content
.
append
(
response
[
'html'
])
$content
.
find
(
".comment"
).
each
(
index
,
comment
)
->
Discussion
.
initializeContent
(
comment
)
Discussion
.
bindContentEvents
(
comment
)
$showComments
.
removeClass
(
"first-time"
)
rebindHideEvents
()
Discussion
.
bindLocalEvents
$local
,
"click .thread-title"
:
->
handleShowSingleThread
(
this
)
"click .discussion-show-comments"
:
->
handleShowSingleThread
(
this
)
"click .discussion-hide-comments"
:
->
handleHideSingleThread
(
this
)
"click .discussion-reply-thread"
:
->
handleShowSingleThread
(
$local
(
".thread-title"
))
handleReply
(
this
)
"click .discussion-reply-comment"
:
->
handleReply
(
this
)
"click .discussion-cancel-reply"
:
->
handleCancelReply
(
this
)
"click .discussion-vote-up"
:
->
$elem
=
$
(
this
)
if
$elem
.
hasClass
(
"voted"
)
handleUnvote
(
$elem
)
else
handleVote
(
$elem
,
"up"
)
"click .discussion-vote-down"
:
->
$elem
=
$
(
this
)
if
$elem
.
hasClass
(
"voted"
)
handleUnvote
(
$elem
)
else
handleVote
(
$elem
,
"down"
)
"click .admin-endorse"
:
->
handleEndorse
(
this
,
not
$content
.
hasClass
(
"endorsed"
))
"click .admin-openclose"
:
->
handleOpenClose
(
this
,
$
(
this
).
text
())
"click .admin-edit"
:
->
if
$content
.
hasClass
(
"thread"
)
handleEditThread
(
this
)
else
handleEditComment
(
this
)
"click .admin-delete"
:
->
handleDelete
(
this
)
initializeContent
:
(
content
)
->
unescapeHighlightTag
=
(
text
)
->
text
.
replace
(
/\<\;highlight\>\;/g
,
"<span class='search-highlight'>"
)
.
replace
(
/\<\;\/highlight\>\;/g
,
"</span>"
)
stripHighlight
=
(
text
,
type
)
->
text
.
replace
(
/\&(amp\;)?lt\;highlight\&(amp\;)?gt\;/g
,
""
)
.
replace
(
/\&(amp\;)?lt\;\/highlight\&(amp\;)?gt\;/g
,
""
)
stripLatexHighlight
=
(
text
)
->
Discussion
.
processEachMathAndCode
text
,
stripHighlight
markdownWithHighlight
=
(
text
)
->
converter
=
Markdown
.
getMathCompatibleConverter
()
unescapeHighlightTag
stripLatexHighlight
converter
.
makeHtml
text
$content
=
$
(
content
)
initializeVote
$content
if
$content
.
hasClass
(
"thread"
)
initializeFollowThread
$content
$local
=
Discussion
.
generateLocal
(
$content
.
children
(
".discussion-content"
))
$local
(
"span.timeago"
).
timeago
()
$contentTitle
=
$local
(
".thread-title"
)
if
$contentTitle
.
length
$contentTitle
.
html
unescapeHighlightTag
stripLatexHighlight
$contentTitle
.
html
()
$contentBody
=
$local
(
".content-body"
)
$contentBody
.
html
Discussion
.
postMathJaxProcessor
markdownWithHighlight
$contentBody
.
html
()
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
$contentBody
.
attr
(
"id"
)]
id
=
$content
.
attr
(
"_id"
)
if
$content
.
hasClass
(
"thread"
)
discussion_id
=
$content
.
attr
(
"_discussion_id"
)
permalink
=
Discussion
.
urlFor
(
"permanent_link_thread"
,
discussion_id
,
id
)
else
thread_id
=
$content
.
parents
(
".thread"
).
attr
(
"_id"
)
discussion_id
=
$content
.
parents
(
".thread"
).
attr
(
"_discussion_id"
)
permalink
=
Discussion
.
urlFor
(
"permanent_link_comment"
,
discussion_id
,
thread_id
,
id
)
$local
(
".discussion-permanent-link"
).
attr
"href"
,
permalink
if
not
Discussion
.
getContentInfo
id
,
'editable'
$local
(
".admin-edit"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_reply'
$local
(
".discussion-reply"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_endorse'
$local
(
".admin-endorse"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_delete'
$local
(
".admin-delete"
).
remove
()
if
not
Discussion
.
getContentInfo
id
,
'can_openclose'
$local
(
".admin-openclose"
).
remove
()
#if not Discussion.getContentInfo id, 'can_vote'
# $local(".discussion-vote").css "visibility", "hidden"
lms/static/coffee/src/old_discussion/discussion.coffee
0 → 100644
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
initializeFollowDiscussion
=
(
discussion
)
->
$discussion
=
$
(
discussion
)
id
=
$following
.
attr
(
"_id"
)
$local
=
Discussion
.
generateLocal
()
$discussion
.
children
(
".discussion-non-content"
)
.
find
(
".discussion-title-wrapper"
)
.
append
(
Discussion
.
subscriptionLink
(
'discussion'
,
id
))
@
Discussion
=
$
.
extend
@
Discussion
,
initializeDiscussion
:
(
discussion
)
->
$discussion
=
$
(
discussion
)
$discussion
.
find
(
".thread"
).
each
(
index
,
thread
)
->
Discussion
.
initializeContent
(
thread
)
Discussion
.
bindContentEvents
(
thread
)
$discussion
.
find
(
".comment"
).
each
(
index
,
comment
)
->
Discussion
.
initializeContent
(
comment
)
Discussion
.
bindContentEvents
(
comment
)
#initializeFollowDiscussion(discussion) TODO move this somewhere else
bindDiscussionEvents
:
(
discussion
)
->
$discussion
=
$
(
discussion
)
$discussionNonContent
=
$discussion
.
children
(
".discussion-non-content"
)
$local
=
Discussion
.
generateLocal
(
$discussion
.
children
(
".discussion-local"
))
id
=
$discussion
.
attr
(
"_id"
)
handleSubmitNewPost
=
(
elem
)
->
title
=
$local
(
".new-post-title"
).
val
()
body
=
Discussion
.
getWmdContent
$discussion
,
$local
,
"new-post-body"
tags
=
$local
(
".new-post-tags"
).
val
()
url
=
Discussion
.
urlFor
(
'create_thread'
,
id
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
dataType
:
'json'
data
:
title
:
title
body
:
body
tags
:
tags
error
:
Discussion
.
formErrorHandler
(
$local
(
".new-post-form-errors"
))
success
:
(
response
,
textStatus
)
->
Discussion
.
clearFormErrors
(
$local
(
".new-post-form-errors"
))
$thread
=
$
(
response
.
html
)
$discussion
.
children
(
".threads"
).
prepend
(
$thread
)
$local
(
".new-post-title"
).
val
(
""
)
Discussion
.
setWmdContent
$discussion
,
$local
,
"new-post-body"
,
""
$local
(
".new-post-tags"
).
val
(
""
)
if
$discussion
.
hasClass
(
"inline-discussion"
)
$local
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
hide
()
handleCancelNewPost
=
(
elem
)
->
if
$discussion
.
hasClass
(
"inline-discussion"
)
$local
(
".new-post-form"
).
addClass
(
"collapsed"
)
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
hide
()
handleSimilarPost
=
(
elem
)
->
$title
=
$local
(
".new-post-title"
)
$wrapper
=
$local
(
".new-post-similar-posts-wrapper"
)
$similarPosts
=
$local
(
".new-post-similar-posts"
)
prevText
=
$title
.
attr
(
"prev-text"
)
text
=
$title
.
val
()
if
text
==
prevText
if
$local
(
".similar-post"
).
length
$wrapper
.
show
()
else
if
$
.
trim
(
text
).
length
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
Discussion
.
urlFor
'search_similar_threads'
,
id
type
:
"GET"
dateType
:
'json'
data
:
text
:
$local
(
".new-post-title"
).
val
()
success
:
(
response
,
textStatus
)
->
$similarPosts
.
empty
()
console
.
log
response
if
$
.
type
(
response
)
==
"array"
and
response
.
length
$wrapper
.
show
()
for
thread
in
response
#singleThreadUrl = Discussion.urlFor 'retrieve_single_thread
$similarPost
=
$
(
"<a>"
).
addClass
(
"similar-post"
)
.
html
(
thread
[
"title"
])
.
attr
(
"href"
,
"javascript:void(0)"
)
#TODO
.
appendTo
(
$similarPosts
)
else
$wrapper
.
hide
()
else
$wrapper
.
hide
()
$title
.
attr
(
"prev-text"
,
text
)
initializeNewPost
=
->
view
=
{
discussion_id
:
id
}
$discussionNonContent
=
$discussion
.
children
(
".discussion-non-content"
)
if
not
$local
(
".wmd-panel"
).
length
$discussionNonContent
.
append
Mustache
.
render
Discussion
.
newPostTemplate
,
view
$newPostBody
=
$local
(
".new-post-body"
)
Discussion
.
makeWmdEditor
$discussion
,
$local
,
"new-post-body"
$input
=
Discussion
.
getWmdInput
(
$discussion
,
$local
,
"new-post-body"
)
$input
.
attr
(
"placeholder"
,
"post a new topic..."
)
if
$discussion
.
hasClass
(
"inline-discussion"
)
$input
.
bind
'focus'
,
(
e
)
->
$local
(
".new-post-form"
).
removeClass
(
'collapsed'
)
else
if
$discussion
.
hasClass
(
"forum-discussion"
)
$local
(
".new-post-form"
).
removeClass
(
'collapsed'
)
$local
(
".new-post-tags"
).
tagsInput
Discussion
.
tagsInputOptions
()
$local
(
".new-post-title"
).
blur
->
handleSimilarPost
(
this
)
$local
(
".hide-similar-posts"
).
click
->
$local
(
".new-post-similar-posts-wrapper"
).
hide
()
$local
(
".discussion-submit-post"
).
click
->
handleSubmitNewPost
(
this
)
$local
(
".discussion-cancel-post"
).
click
->
handleCancelNewPost
(
this
)
$local
(
".new-post-form"
).
show
()
handleAjaxReloadDiscussion
=
(
elem
,
url
)
->
if
not
url
then
return
$elem
=
$
(
elem
)
$discussion
=
$elem
.
parents
(
"section.discussion"
)
Discussion
.
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
dataType
:
'html'
success
:
(
data
,
textStatus
)
->
$data
=
$
(
data
)
$parent
=
$discussion
.
parent
()
$discussion
.
replaceWith
(
$data
)
$discussion
=
$parent
.
children
(
".discussion"
)
Discussion
.
initializeDiscussion
(
$discussion
)
Discussion
.
bindDiscussionEvents
(
$discussion
)
handleAjaxSearch
=
(
elem
)
->
$elem
=
$
(
elem
)
url
=
URI
(
$elem
.
attr
(
"action"
)).
addSearch
({
text
:
$local
(
".search-input"
).
val
()})
handleAjaxReloadDiscussion
(
$elem
,
url
)
handleAjaxSort
=
(
elem
)
->
$elem
=
$
(
elem
)
url
=
$elem
.
attr
(
"sort-url"
)
handleAjaxReloadDiscussion
(
$elem
,
url
)
handleAjaxPage
=
(
elem
)
->
$elem
=
$
(
elem
)
url
=
$elem
.
attr
(
"page-url"
)
handleAjaxReloadDiscussion
(
$elem
,
url
)
if
$discussion
.
hasClass
(
"inline-discussion"
)
initializeNewPost
()
if
$discussion
.
hasClass
(
"forum-discussion"
)
$discussionSidebar
=
$
(
".discussion-sidebar"
)
if
$discussionSidebar
.
length
$sidebarLocal
=
Discussion
.
generateLocal
(
$discussionSidebar
)
Discussion
.
bindLocalEvents
$sidebarLocal
,
"click .sidebar-new-post-button"
:
(
event
)
->
initializeNewPost
()
Discussion
.
bindLocalEvents
$local
,
"submit .search-wrapper>.discussion-search-form"
:
(
event
)
->
event
.
preventDefault
()
handleAjaxSearch
(
this
)
"click .discussion-search-link"
:
->
handleAjaxSearch
(
$local
(
".search-wrapper>.discussion-search-form"
))
"click .discussion-sort-link"
:
->
handleAjaxSort
(
this
)
$discussion
.
children
(
".discussion-paginator"
).
find
(
".discussion-page-link"
).
unbind
(
'click'
).
click
->
handleAjaxPage
(
this
)
lms/static/coffee/src/old_discussion/discussion_module.coffee
0 → 100644
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
@
Discussion
=
$
.
extend
@
Discussion
,
initializeDiscussionModule
:
(
elem
)
->
$discussionModule
=
$
(
elem
)
$local
=
Discussion
.
generateLocal
(
$discussionModule
)
handleShowDiscussion
=
(
elem
)
->
$elem
=
$
(
elem
)
if
not
$local
(
"section.discussion"
).
length
discussion_id
=
$elem
.
attr
(
"discussion_id"
)
url
=
Discussion
.
urlFor
'retrieve_discussion'
,
discussion_id
Discussion
.
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
success
:
(
data
,
textStatus
,
xhr
)
->
$discussionModule
.
append
(
data
)
discussion
=
$local
(
"section.discussion"
)
Discussion
.
initializeDiscussion
(
discussion
)
Discussion
.
bindDiscussionEvents
(
discussion
)
$elem
.
html
(
"Hide Discussion"
)
$elem
.
unbind
(
'click'
).
click
->
handleHideDiscussion
(
this
)
dataType
:
'html'
else
$local
(
"section.discussion"
).
show
()
$elem
.
html
(
"Hide Discussion"
)
$elem
.
unbind
(
'click'
).
click
->
handleHideDiscussion
(
this
)
handleHideDiscussion
=
(
elem
)
->
$local
(
"section.discussion"
).
hide
()
$elem
=
$
(
elem
)
$elem
.
html
(
"Show Discussion"
)
$elem
.
unbind
(
'click'
).
click
->
handleShowDiscussion
(
this
)
$local
(
".discussion-show"
).
click
->
handleShowDiscussion
(
this
)
lms/static/coffee/src/old_discussion/main.coffee
0 → 100644
View file @
952c9d56
$
->
#toggle = ->
# $('.course-wrapper').toggleClass('closed')
#Discussion = window.Discussion
#if $('#accordion').length
# active = $('#accordion ul:has(li.active)').index('#accordion ul')
# $('#accordion').bind('accordionchange', @log).accordion
# active: if active >= 0 then active else 1
# header: 'h3'
# autoHeight: false
# $('#open_close_accordion a').click toggle
# $('#accordion').show()
#$(".discussion-module").each (index, elem) ->
# Discussion.initializeDiscussionModule(elem)
#$("section.discussion").each (index, discussion) ->
# Discussion.initializeDiscussion(discussion)
# Discussion.bindDiscussionEvents(discussion)
#Discussion.initializeUserProfile($(".discussion-sidebar>.user-profile"))
lms/static/coffee/src/old_discussion/templates.coffee
0 → 100644
View file @
952c9d56
if
not
@
Discussion
?
@
Discussion
=
{}
Discussion
=
@
Discussion
@
Discussion
=
$
.
extend
@
Discussion
,
newPostTemplate
:
"""
<form class="new-post-form collapsed" id="new-post-form" style="display: block; ">
<ul class="new-post-form-errors discussion-errors"></ul>
<input type="text" class="new-post-title title-input" placeholder="Title" />
<div class="new-post-similar-posts-wrapper" style="display: none">
Similar Posts:
<a class="hide-similar-posts" href="javascript:void(0)">Hide</a>
<div class="new-post-similar-posts"></div>
</div>
<div class="new-post-body reply-body"></div>
<input class="new-post-tags" placeholder="Tags" />
<div class="post-options">
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-${discussion_id}">
<label for="discussion-post-anonymously-${discussion_id}">post anonymously</label>
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-${discussion_id}" checked="">
<label for="discussion-auto-watch-${discussion_id}">follow this thread</label>
</div>
<div class="new-post-control post-control">
<a class="discussion-cancel-post" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-post control-button" href="javascript:void(0)">Submit</a>
</div>
</form>
"""
replyTemplate
:
"""
<form class="discussion-reply-new">
<ul class="discussion-errors"></ul>
<div class="reply-body"></div>
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-{{id}}" />
<label for="discussion-post-anonymously-{{id}}">post anonymously</label>
{{#showWatchCheckbox}}
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-{{id}}" checked />
<label for="discussion-auto-watch-{{id}}">follow this thread</label>
{{/showWatchCheckbox}}
<br />
<div class = "reply-post-control">
<a class="discussion-cancel-post" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-post control-button" href="javascript:void(0)">Submit</a>
</div>
</form>
"""
editThreadTemplate
:
"""
<form class="discussion-content-edit discussion-thread-edit" _id="{{id}}">
<ul class="discussion-errors discussion-update-errors"></ul>
<input type="text" class="thread-title-edit title-input" placeholder="Title" value="{{title}}"/>
<div class="thread-body-edit body-input">{{body}}</div>
<input class="thread-tags-edit" placeholder="Tags" value="{{tags}}" />
<div class = "edit-post-control">
<a class="discussion-cancel-update" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-update control-button" href="javascript:void(0)">Update</a>
</div>
</form>
"""
editCommentTemplate
:
"""
<form class="discussion-content-edit discussion-comment-edit" _id="{{id}}">
<ul class="discussion-errors discussion-update-errors"></ul>
<div class="comment-body-edit body-input">{{body}}</div>
<div class = "edit-post-control">
<a class="discussion-cancel-update" href="javascript:void(0)">Cancel</a>
<a class="discussion-submit-update control-button" href="javascript:void(0)">Update</a>
</div>
</form>
"""
lms/static/coffee/src/
backbone
_discussion/user_profile.coffee
→
lms/static/coffee/src/
old
_discussion/user_profile.coffee
View file @
952c9d56
File moved
lms/static/coffee/src/
backbone
_discussion/utils.coffee
→
lms/static/coffee/src/
old
_discussion/utils.coffee
View file @
952c9d56
class
@
DiscussionUtil
if
not
@
Discussion
?
@
Discussion
=
{}
@
wmdEditors
:
{}
Discussion
=
@
Discussion
@
getTemplate
:
(
id
)
->
$
(
"script#
#{
id
}
"
).
html
()
wmdEditors
=
{}
@
getDiscussionData
:
(
id
)
->
return
$$discussion_data
[
id
]
@
Discussion
=
$
.
extend
@
Discussion
,
@
addContent
:
(
id
,
content
)
->
window
.
$
$contents
[
id
]
=
content
generateLocal
:
(
elem
)
->
(
selector
)
->
$
(
elem
).
find
(
selector
)
@
getContent
:
(
id
)
->
window
.
$
$contents
[
id
]
@
addDiscussion
:
(
id
,
discussion
)
->
window
.
$
$discussions
[
id
]
=
discussion
@
getDiscussion
:
(
id
)
->
window
.
$
$discussions
[
id
]
@
bulkUpdateContentInfo
:
(
infos
)
->
for
id
,
info
of
infos
@
getContent
(
id
).
updateInfo
(
info
)
@
generateDiscussionLink
:
(
cls
,
txt
,
handler
)
->
generateDiscussionLink
:
(
cls
,
txt
,
handler
)
->
$
(
"<a>"
).
addClass
(
"discussion-link"
)
.
attr
(
"href"
,
"javascript:void(0)"
)
.
addClass
(
cls
).
html
(
txt
)
.
click
->
handler
(
this
)
@
urlFor
:
(
name
,
param
,
param1
,
param2
)
->
urlFor
:
(
name
,
param
,
param1
,
param2
)
->
{
follow_discussion
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/follow"
unfollow_discussion
:
"/courses/
#{
$$course_id
}
/discussion/
#{
param
}
/unfollow"
...
...
@@ -58,7 +48,7 @@ class @DiscussionUtil
permanent_link_comment
:
"/courses/
#{
$$course_id
}
/discussion/forum/
#{
param
}
/threads/
#{
param1
}
#
#{
param2
}
"
}[
name
]
@
safeAjax
:
(
params
)
->
safeAjax
:
(
params
)
->
$elem
=
params
.
$elem
if
$elem
.
attr
(
"disabled"
)
return
...
...
@@ -66,31 +56,17 @@ class @DiscussionUtil
$
.
ajax
(
params
).
always
->
$elem
.
removeAttr
(
"disabled"
)
@
get
:
(
$elem
,
url
,
data
,
success
)
->
@
safeAjax
$elem
:
$elem
url
:
url
type
:
"GET"
dataType
:
"json"
data
:
data
success
:
success
@
post
:
(
$elem
,
url
,
data
,
success
)
->
@
safeAjax
$elem
:
$elem
url
:
url
type
:
"POST"
dataType
:
"json"
data
:
data
success
:
success
@
bindLocalEvents
:
(
$local
,
eventsHandler
)
->
handleAnchorAndReload
:
(
response
)
->
#window.location = window.location.pathname + "#" + response['id']
window
.
location
.
reload
()
bindLocalEvents
:
(
$local
,
eventsHandler
)
->
for
eventSelector
,
handler
of
eventsHandler
[
event
,
selector
]
=
eventSelector
.
split
(
' '
)
$local
(
selector
).
unbind
(
event
)[
event
]
handler
@
tagsInputOptions
:
->
autocomplete_url
:
@
urlFor
(
'tags_autocomplete'
)
tagsInputOptions
:
->
autocomplete_url
:
Discussion
.
urlFor
(
'tags_autocomplete'
)
autocomplete
:
remoteDataType
:
'json'
interactive
:
true
...
...
@@ -99,7 +75,23 @@ class @DiscussionUtil
defaultText
:
"Tag your post: press enter after each tag"
removeWithBackspace
:
true
@
formErrorHandler
:
(
errorsField
)
->
isSubscribed
:
(
id
,
type
)
->
$$user_info
?
and
(
if
type
==
"thread"
id
in
$$user_info
.
subscribed_thread_ids
else
if
type
==
"commentable"
or
type
==
"discussion"
id
in
$$user_info
.
subscribed_commentable_ids
else
id
in
$$user_info
.
subscribed_user_ids
)
isUpvoted
:
(
id
)
->
$$user_info
?
and
(
id
in
$$user_info
.
upvoted_ids
)
isDownvoted
:
(
id
)
->
$$user_info
?
and
(
id
in
$$user_info
.
downvoted_ids
)
formErrorHandler
:
(
errorsField
)
->
(
xhr
,
textStatus
,
error
)
->
response
=
JSON
.
parse
(
xhr
.
responseText
)
if
response
.
errors
?
and
response
.
errors
.
length
>
0
...
...
@@ -107,13 +99,13 @@ class @DiscussionUtil
for
error
in
response
.
errors
errorsField
.
append
(
$
(
"<li>"
).
addClass
(
"new-post-form-error"
).
html
(
error
))
@
clearFormErrors
:
(
errorsField
)
->
clearFormErrors
:
(
errorsField
)
->
errorsField
.
empty
()
@
postMathJaxProcessor
:
(
text
)
->
postMathJaxProcessor
:
(
text
)
->
RE_INLINEMATH
=
/^\$([^\$]*)\$/g
RE_DISPLAYMATH
=
/^\$\$([^\$]*)\$\$/g
@
processEachMathAndCode
text
,
(
s
,
type
)
->
Discussion
.
processEachMathAndCode
text
,
(
s
,
type
)
->
if
type
==
'display'
s
.
replace
RE_DISPLAYMATH
,
(
$0
,
$1
)
->
"
\\
["
+
$1
+
"
\\
]"
...
...
@@ -123,43 +115,61 @@ class @DiscussionUtil
else
s
@
makeWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
makeWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
elem
=
$local
(
".
#{
cls_identifier
}
"
)
id
=
$content
.
attr
(
"_id"
)
appended_id
=
"-
#{
cls_identifier
}
-
#{
id
}
"
imageUploadUrl
=
@
urlFor
(
'upload'
)
_processor
=
(
_this
)
->
(
text
)
->
_this
.
postMathJaxProcessor
(
text
)
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
,
_processor
(
@
)
@
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
imageUploadUrl
=
Discussion
.
urlFor
(
'upload'
)
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
,
Discussion
.
postMathJaxProcessor
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
editor
@
getWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
getWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
id
=
$content
.
attr
(
"_id"
)
@
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
@
getWmdInput
:
(
$content
,
$local
,
cls_identifier
)
->
getWmdInput
:
(
$content
,
$local
,
cls_identifier
)
->
id
=
$content
.
attr
(
"_id"
)
$local
(
"#wmd-input-
#{
cls_identifier
}
-
#{
id
}
"
)
@
getWmdContent
:
(
$content
,
$local
,
cls_identifier
)
->
@
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
()
@
setWmdContent
:
(
$content
,
$local
,
cls_identifier
,
text
)
->
@
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
(
text
)
@
getWmdEditor
(
$content
,
$local
,
cls_identifier
).
refreshPreview
()
@
subscriptionLink
:
(
type
,
id
)
->
getWmdContent
:
(
$content
,
$local
,
cls_identifier
)
->
Discussion
.
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
()
setWmdContent
:
(
$content
,
$local
,
cls_identifier
,
text
)
->
Discussion
.
getWmdInput
(
$content
,
$local
,
cls_identifier
).
val
(
text
)
Discussion
.
getWmdEditor
(
$content
,
$local
,
cls_identifier
).
refreshPreview
()
getContentInfo
:
(
id
,
attr
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
(
window
.
$
$annotated_content_info
[
id
]
||
{})[
attr
]
setContentInfo
:
(
id
,
attr
,
value
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
[
id
]
||=
{}
window
.
$
$annotated_content_info
[
id
][
attr
]
=
value
extendContentInfo
:
(
id
,
newInfo
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
[
id
]
=
newInfo
bulkExtendContentInfo
:
(
newInfos
)
->
if
not
window
.
$
$annotated_content_info
?
window
.
$
$annotated_content_info
=
{}
window
.
$
$annotated_content_info
=
$
.
extend
window
.
$
$annotated_content_info
,
newInfos
subscriptionLink
:
(
type
,
id
)
->
followLink
=
->
@
generateDiscussionLink
(
"discussion-follow-
#{
type
}
"
,
"Follow"
,
handleFollow
)
Discussion
.
generateDiscussionLink
(
"discussion-follow-
#{
type
}
"
,
"Follow"
,
handleFollow
)
unfollowLink
=
->
@
generateDiscussionLink
(
"discussion-unfollow-
#{
type
}
"
,
"Unfollow"
,
handleUnfollow
)
Discussion
.
generateDiscussionLink
(
"discussion-unfollow-
#{
type
}
"
,
"Unfollow"
,
handleUnfollow
)
handleFollow
=
(
elem
)
->
@
safeAjax
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
@
urlFor
(
"follow_
#{
type
}
"
,
id
)
url
:
Discussion
.
urlFor
(
"follow_
#{
type
}
"
,
id
)
type
:
"POST"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
...
...
@@ -167,21 +177,21 @@ class @DiscussionUtil
dataType
:
'json'
handleUnfollow
=
(
elem
)
->
@
safeAjax
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
@
urlFor
(
"unfollow_
#{
type
}
"
,
id
)
url
:
Discussion
.
urlFor
(
"unfollow_
#{
type
}
"
,
id
)
type
:
"POST"
success
:
(
response
,
textStatus
)
->
if
textStatus
==
"success"
$
(
elem
).
replaceWith
followLink
()
dataType
:
'json'
if
@
isSubscribed
(
id
,
type
)
if
Discussion
.
isSubscribed
(
id
,
type
)
unfollowLink
()
else
followLink
()
@
processEachMathAndCode
:
(
text
,
processor
)
->
processEachMathAndCode
:
(
text
,
processor
)
->
codeArchive
=
[]
...
...
@@ -232,18 +242,3 @@ class @DiscussionUtil
text
=
$div
.
html
()
text
@
unescapeHighlightTag
:
(
text
)
->
text
.
replace
(
/\<\;highlight\>\;/g
,
"<span class='search-highlight'>"
)
.
replace
(
/\<\;\/highlight\>\;/g
,
"</span>"
)
@
stripHighlight
:
(
text
)
->
text
.
replace
(
/\&(amp\;)?lt\;highlight\&(amp\;)?gt\;/g
,
""
)
.
replace
(
/\&(amp\;)?lt\;\/highlight\&(amp\;)?gt\;/g
,
""
)
@
stripLatexHighlight
:
(
text
)
->
@
processEachMathAndCode
text
,
@
stripHighlight
@
markdownWithHighlight
:
(
text
)
->
converter
=
Markdown
.
getMathCompatibleConverter
()
@
unescapeHighlightTag
@
stripLatexHighlight
converter
.
makeHtml
text
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment