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
cc477138
Commit
cc477138
authored
Aug 02, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some refactoring on error handling
parent
5ba879fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
49 deletions
+59
-49
lms/static/coffee/src/discussion/content.coffee
+42
-47
lms/static/coffee/src/discussion/discussion.coffee
+0
-2
lms/static/coffee/src/discussion/utils.coffee
+17
-0
No files found.
lms/static/coffee/src/discussion/content.coffee
View file @
cc477138
...
...
@@ -28,9 +28,10 @@ Discussion = @Discussion
if
$replyView
.
length
$replyView
.
show
()
else
thread_id
=
$discussionContent
.
parents
(
".thread"
).
attr
(
"_id"
)
view
=
{
id
:
id
showWatchCheckbox
:
$discussionContent
.
parents
(
".thread"
).
attr
(
"_id"
)
not
in
$$user_info
.
subscribed_thread_ids
showWatchCheckbox
:
not
Discussion
.
isSubscribed
(
thread_id
,
"thread"
)
}
$discussionContent
.
append
Mustache
.
render
Discussion
.
replyTemplate
,
view
Markdown
.
makeWmdEditor
$local
(
".reply-body"
),
"-reply-body-
#{
id
}
"
,
Discussion
.
urlFor
(
'upload'
)
...
...
@@ -61,19 +62,15 @@ Discussion = @Discussion
autowatch
=
false
||
$local
(
".discussion-auto-watch"
).
is
(
":checked"
)
Discussion
.
safeAjax
$elem
:
$
(
elem
)
url
:
url
type
:
"POST"
data
:
body
:
body
anonymous
:
anonymous
autowatch
:
autowatch
success
:
(
response
,
textStatus
)
->
if
response
.
errors
?
and
response
.
errors
.
length
>
0
errorsField
=
$local
(
".discussion-errors"
).
empty
()
for
error
in
response
.
errors
errorsField
.
append
(
$
(
"<li>"
).
addClass
(
"new-post-form-error"
).
html
(
error
))
else
Discussion
.
handleAnchorAndReload
(
response
)
success
:
Discussion
.
formErrorHandler
$local
(
".discussion-errors"
),
(
response
,
textStatus
)
->
Discussion
.
handleAnchorAndReload
(
response
)
dataType
:
'json'
handleVote
=
(
elem
,
value
)
->
...
...
@@ -119,14 +116,13 @@ Discussion = @Discussion
title
=
$local
(
".thread-title-edit"
).
val
()
body
=
$local
(
"#wmd-input-thread-body-edit-
#{
id
}
"
).
val
()
tags
=
$local
(
".thread-tags-edit"
).
val
()
$
.
post
url
,
{
title
:
title
,
body
:
body
,
tags
:
tags
},
(
response
,
textStatus
)
->
if
response
.
errors
errorsField
=
$local
(
".discussion-update-errors"
).
empty
()
for
error
in
response
.
errors
errorsField
.
append
(
$
(
"<li>"
).
addClass
(
"new-post-form-error"
).
html
(
error
))
else
$
.
ajax
url
:
url
type
:
"POST"
data
:
{
title
:
title
,
body
:
body
,
tags
:
tags
},
success
:
Discussion
.
formErrorHandler
$local
(
".discussion-update-errors"
),
(
response
,
textStatus
)
->
Discussion
.
handleAnchorAndReload
(
response
)
,
'json'
dataType
:
'json'
handleEditComment
=
(
elem
)
->
$local
(
".discussion-content-wrapper"
).
hide
()
...
...
@@ -134,10 +130,7 @@ Discussion = @Discussion
if
$editView
.
length
$editView
.
show
()
else
view
=
{
id
:
id
body
:
$local
(
".comment-raw-body"
).
html
()
}
view
=
{
id
:
id
,
body
:
$local
(
".comment-raw-body"
).
html
()
}
$discussionContent
.
append
Mustache
.
render
Discussion
.
editCommentTemplate
,
view
Markdown
.
makeWmdEditor
$local
(
".comment-body-edit"
),
"-comment-body-edit-
#{
id
}
"
,
Discussion
.
urlFor
(
'update_comment'
,
id
)
$local
(
".discussion-submit-update"
).
unbind
(
"click"
).
click
->
handleSubmitEditComment
(
this
)
...
...
@@ -146,14 +139,13 @@ Discussion = @Discussion
handleSubmitEditComment
=
(
elem
)
->
url
=
Discussion
.
urlFor
(
'update_comment'
,
id
)
body
=
$local
(
"#wmd-input-comment-body-edit-
#{
id
}
"
).
val
()
$
.
post
url
,
{
body
:
body
},
(
response
,
textStatus
)
->
if
response
.
errors
errorsField
=
$local
(
".discussion-update-errors"
).
empty
()
for
error
in
response
.
errors
errorsField
.
append
(
$
(
"<li>"
).
addClass
(
"new-post-form-error"
).
html
(
error
))
else
$
.
ajax
url
:
url
data
:
{
body
:
body
}
type
:
"POST"
success
:
Discussion
.
formErrorHandler
$local
(
".discussion-update-errors"
),
(
response
,
textStatus
)
->
Discussion
.
handleAnchorAndReload
(
response
)
,
'json'
dataType
:
"json"
handleEndorse
=
(
elem
)
->
url
=
Discussion
.
urlFor
(
'endorse_comment'
,
id
)
...
...
@@ -203,35 +195,38 @@ Discussion = @Discussion
rebindHideEvents
()
dataType
:
'json'
$local
(
".thread-title"
).
click
handleShowSingleThread
Discussion
.
bindLocalEvents
$local
,
$local
(
".discussion-show-comments"
).
click
handleShowSingleThread
"click .thread-title"
:
->
handleShowSingleThread
(
this
)
$local
(
".discussion-reply-thread"
).
click
->
handleShowSingleThread
(
$local
(
".thread-title"
))
handleReply
(
this
)
"click .discussion-show-comments"
:
->
handleShowSingleThread
(
this
)
$local
(
".discussion-reply-comment"
).
click
->
handleReply
(
this
)
"click .discussion-reply-thread"
:
->
handleShowSingleThread
(
$local
(
".thread-title"
))
handleReply
(
this
)
$local
(
".discussion-cancel-reply"
).
click
->
handleCancel
Reply
(
this
)
"click .discussion-reply-comment"
:
->
handle
Reply
(
this
)
$local
(
".discussion-vote-up"
).
click
->
handleVote
(
this
,
"up"
)
"click .discussion-cancel-reply"
:
->
handleCancelReply
(
this
)
$local
(
".discussion-vote-down"
).
click
->
handleVote
(
this
,
"down
"
)
"click .discussion-vote-up"
:
->
handleVote
(
this
,
"up
"
)
$local
(
".discussion-endorse"
).
click
->
handleEndorse
(
this
)
"click .discussion-vote-down"
:
->
handleVote
(
this
,
"down"
)
$local
(
".discussion-edit"
).
click
->
if
$content
.
hasClass
(
"thread"
)
handleEditThread
(
this
)
else
handleEditComment
(
this
)
"click .discussion-endorse"
:
->
handleEndorse
(
this
)
"click .discussion-edit"
:
->
if
$content
.
hasClass
(
"thread"
)
handleEditThread
(
this
)
else
handleEditComment
(
this
)
initializeContent
:
(
content
)
->
$content
=
$
(
content
)
...
...
lms/static/coffee/src/discussion/discussion.coffee
View file @
cc477138
...
...
@@ -128,8 +128,6 @@ initializeFollowThread = (index, thread) ->
$
(
elem
).
hide
()
handleUpdateDiscussionContent
=
(
$elem
,
$discussion
,
url
)
->
handleAjaxSearch
=
(
elem
)
->
handle
$elem
=
$
(
elem
)
...
...
lms/static/coffee/src/discussion/utils.coffee
View file @
cc477138
...
...
@@ -65,3 +65,20 @@ Discussion = @Discussion
height
:
"30px"
width
:
"100%"
removeWithBackspace
:
true
isSubscribed
:
(
id
,
type
)
->
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
formErrorHandler
:
(
errorsField
,
success
)
->
(
response
,
textStatus
,
xhr
)
->
if
response
.
errors
?
and
response
.
errors
.
length
>
0
errorsField
.
empty
()
for
error
in
response
.
errors
errorsField
.
append
(
$
(
"<li>"
).
addClass
(
"new-post-form-error"
).
html
(
error
))
else
success
(
response
,
textStatus
,
xhr
)
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