Merge pull request #520 from edx/feature/kevin/email_notifications_panel

Feature/kevin/email notifications panel
This commit is contained in:
Jim Abramson
2013-07-30 05:30:56 -07:00
34 changed files with 2759 additions and 264 deletions

View File

@@ -20,10 +20,13 @@ if Backbone?
allThreads: ->
@nav.updateSidebar()
@nav.goHome()
setActiveThread: =>
if @thread
@nav.setActiveThread(@thread.get("id"))
else
@nav.goHome
showThread: (forum_name, thread_id) ->
@thread = @discussion.get(thread_id)

View File

@@ -82,6 +82,9 @@ class @DiscussionUtil
user_profile : "/courses/#{$$course_id}/discussion/forum/users/#{param}"
followed_threads : "/courses/#{$$course_id}/discussion/forum/users/#{param}/followed"
threads : "/courses/#{$$course_id}/discussion/forum"
"enable_notifications" : "/notification_prefs/enable/"
"disable_notifications" : "/notification_prefs/disable/"
"notifications_status" : "/notification_prefs/status"
}[name]
@safeAjax: (params) ->

View File

@@ -2,6 +2,7 @@ if Backbone?
class @DiscussionThreadListView extends Backbone.View
events:
"click .search": "showSearch"
"click .home": "goHome"
"click .browse": "toggleTopicDrop"
"keydown .post-search-field": "performSearch"
"click .sort-bar a": "sortThreads"
@@ -43,6 +44,7 @@ if Backbone?
if active
@setActiveThread(thread_id)
#TODO fix this entire chain of events
addAndSelectThread: (thread) =>
commentable_id = thread.get("commentable_id")
@@ -191,6 +193,25 @@ if Backbone?
@$(".browse").removeClass('is-open')
setTimeout (-> @$(".post-search-field").focus()), 200
goHome: ->
@template = _.template($("#discussion-home").html())
$(".discussion-column").html(@template)
$(".post-list a").removeClass("active")
$("input.email-setting").bind "click", @updateEmailNotifications
url = DiscussionUtil.urlFor("notifications_status",window.user.get("id"))
DiscussionUtil.safeAjax
url: url
type: "GET"
success: (response, textStatus) =>
if response.status
$('input.email-setting').attr('checked','checked')
else
$('input.email-setting').removeAttr('checked')
thread_id = null
@trigger("thread:removed")
#select all threads
toggleTopicDrop: (event) =>
event.preventDefault()
event.stopPropagation()
@@ -312,6 +333,7 @@ if Backbone?
if callback?
callback()
retrieveDiscussions: (discussion_ids) ->
@discussionIds = discussion_ids.join(',')
@mode = 'commentables'
@@ -418,3 +440,19 @@ if Backbone?
retrieveFollowed: (event)=>
@mode = 'followed'
@retrieveFirstPage(event)
updateEmailNotifications: () =>
if $('input.email-setting').attr('checked')
DiscussionUtil.safeAjax
url: DiscussionUtil.urlFor("enable_notifications")
type: "POST"
error: () =>
$('input.email-setting').removeAttr('checked')
else
DiscussionUtil.safeAjax
url: DiscussionUtil.urlFor("disable_notifications")
type: "POST"
error: () =>
$('input.email-setting').attr('checked','checked')