Commit 9591b526 by E. Kolpakov Committed by Jonathan Piacenti

Fixed broken backbone history navigation in course mode. Moved runtime-specific…

Fixed broken backbone history navigation in course mode. Moved runtime-specific settings modifications to runtime callbacks.
parent b9ea8031
var $$course_id = "{{course_id}}"; var $$course_id = "{{course_id}}";
function DiscussionCourseBlock(runtime, element) { function DiscussionCourseBlock(runtime, element) {
var el = $(element).find('section.discussion'), var el = $(element).find('section.discussion');
pushState = true;
var testUrl = runtime.handlerUrl(element, 'test'); var testUrl = runtime.handlerUrl(element, 'test');
if (testUrl.match(/^(http|https):\/\//)) { if (testUrl.match(/^(http|https):\/\//)) {
var hostname = testUrl.match(/^(.*:\/\/[a-z\-.]+)\//)[1]; var hostname = testUrl.match(/^(.*:\/\/[a-z0-9:\-.]+)\//)[1];
DiscussionUtil.setBaseUrl(hostname); DiscussionUtil.setBaseUrl(hostname);
DiscussionUtil.localUrls.push('user_profile');
DiscussionUtil.force_async = true;
pushState = false
} }
DiscussionApp.start(el, pushState); if (runtime.local_overrides && runtime.local_overrides.discussion) {
runtime.local_overrides.discussion(element, DiscussionUtil);
}
DiscussionApp.start(el);
} }
...@@ -7,7 +7,10 @@ function DiscussionInlineBlock(runtime, element) { ...@@ -7,7 +7,10 @@ function DiscussionInlineBlock(runtime, element) {
if (testUrl.match(/^(http|https):\/\//)) { if (testUrl.match(/^(http|https):\/\//)) {
var hostname = testUrl.match(/^(.*:\/\/[a-z0-9:\-.]+)\//)[1]; var hostname = testUrl.match(/^(.*:\/\/[a-z0-9:\-.]+)\//)[1];
DiscussionUtil.setBaseUrl(hostname); DiscussionUtil.setBaseUrl(hostname);
DiscussionUtil.force_async = true; }
if (runtime.local_overrides && runtime.local_overrides.discussion) {
runtime.local_overrides.discussion(element, DiscussionUtil);
} }
new DiscussionModuleView({ el: el }); new DiscussionModuleView({ el: el });
......
...@@ -16,7 +16,6 @@ JS_URLS = [ ...@@ -16,7 +16,6 @@ JS_URLS = [
'js/vendor/jquery.leanModal.min.js', 'js/vendor/jquery.leanModal.min.js',
'js/vendor/jquery.timeago.js', 'js/vendor/jquery.timeago.js',
'js/vendor/underscore-min.js', 'js/vendor/underscore-min.js',
'js/vendor/backbone-min.js',
'js/vendor/mustache.js', 'js/vendor/mustache.js',
'js/vendor/mathjax-MathJax-c9db6ac/MathJax.js?config=TeX-MML-AM_HTMLorMML-full', 'js/vendor/mathjax-MathJax-c9db6ac/MathJax.js?config=TeX-MML-AM_HTMLorMML-full',
......
if Backbone? if Backbone?
class @DiscussionRouter extends Backbone.Router class @DiscussionRouter extends Backbone.Router
routes:
"": "allThreads"
":forum_name/threads/:thread_id" : "showThread"
initialize: (options) -> initialize: (options) ->
@route("#{DiscussionUtil.route_prefix}", "allThreads")
@route("#{DiscussionUtil.route_prefix}:forum_name/threads/:thread_id", "showThread")
@discussion = options['discussion'] @discussion = options['discussion']
@course_settings = options['course_settings'] @course_settings = options['course_settings']
...@@ -14,7 +13,7 @@ if Backbone? ...@@ -14,7 +13,7 @@ if Backbone?
courseSettings: @course_settings courseSettings: @course_settings
) )
@nav.on "thread:selected", @navigateToThread @nav.on "thread:selected", @navigateToThread
@nav.on "thread:removed", @navigateToAllThreads @nav.on "thread:deselected", @navigateToAllThreads
@nav.on "threads:rendered", @setActiveThread @nav.on "threads:rendered", @setActiveThread
@nav.on "thread:created", @navigateToThread @nav.on "thread:created", @navigateToThread
@nav.render() @nav.render()
...@@ -59,6 +58,7 @@ if Backbone? ...@@ -59,6 +58,7 @@ if Backbone?
@main = new DiscussionThreadView( @main = new DiscussionThreadView(
el: $(".forum-content"), el: $(".forum-content"),
model: @thread, model: @thread,
mode: "tab", mode: "tab",
course_settings: @course_settings, course_settings: @course_settings,
...@@ -70,10 +70,10 @@ if Backbone? ...@@ -70,10 +70,10 @@ if Backbone?
navigateToThread: (thread_id) => navigateToThread: (thread_id) =>
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
@navigate("#{thread.get("commentable_id")}/threads/#{thread_id}", trigger: true) @navigate("#{DiscussionUtil.route_prefix}#{thread.get("commentable_id")}/threads/#{thread_id}", trigger: true)
navigateToAllThreads: => navigateToAllThreads: =>
@navigate("", trigger: true) @navigate("#{DiscussionUtil.route_prefix}", trigger: true)
showNewPost: (event) => showNewPost: (event) =>
$('.forum-content').fadeOut( $('.forum-content').fadeOut(
......
if Backbone? if Backbone?
@DiscussionApp = @DiscussionApp =
start: (elem, pushState = true)-> start: (elem)->
# TODO: Perhaps eliminate usage of global variables when possible # TODO: Perhaps eliminate usage of global variables when possible
DiscussionUtil.loadRolesFromContainer() DiscussionUtil.loadRolesFromContainer()
element = $(elem) element = $(elem)
...@@ -17,7 +17,10 @@ if Backbone? ...@@ -17,7 +17,10 @@ if Backbone?
discussion = new Discussion(threads, {pages: thread_pages, sort: sort_preference}) discussion = new Discussion(threads, {pages: thread_pages, sort: sort_preference})
course_settings = new DiscussionCourseSettings(element.data("course-settings")) course_settings = new DiscussionCourseSettings(element.data("course-settings"))
new DiscussionRouter({discussion: discussion, course_settings: course_settings}) new DiscussionRouter({discussion: discussion, course_settings: course_settings})
Backbone.history.start({pushState: pushState, root: "/courses/#{$$course_id}/discussion/forum/"}) if !Backbone.History.started
Backbone.history.start({pushState: true, root: "/courses/#{$$course_id}/discussion/forum/"})
else
Backbone.history.loadUrl(window.location.pathname)
@DiscussionProfileApp = @DiscussionProfileApp =
start: (elem) -> start: (elem) ->
# Roles are not included in user profile page, but they are not used for anything # Roles are not included in user profile page, but they are not used for anything
......
...@@ -19,6 +19,7 @@ class @DiscussionUtil ...@@ -19,6 +19,7 @@ class @DiscussionUtil
@localUrls: [] @localUrls: []
@force_async = false @force_async = false
@route_prefix = ''
@getTemplate: (id) -> @getTemplate: (id) ->
$("script##{id}").html() $("script##{id}").html()
......
...@@ -15,6 +15,7 @@ if Backbone? ...@@ -15,6 +15,7 @@ if Backbone?
"change .forum-nav-filter-cohort-control": "chooseCohort" "change .forum-nav-filter-cohort-control": "chooseCohort"
initialize: (options) -> initialize: (options) ->
@active_thread_id = null
@courseSettings = options.courseSettings @courseSettings = options.courseSettings
@displayedCollection = new Discussion(@collection.models, pages: @collection.pages) @displayedCollection = new Discussion(@collection.models, pages: @collection.pages)
@collection.on "change", @reloadDisplayedCollection @collection.on "change", @reloadDisplayedCollection
...@@ -29,8 +30,9 @@ if Backbone? ...@@ -29,8 +30,9 @@ if Backbone?
# if target.length > 0 # if target.length > 0
# @filterTopic($.Event("filter", {'target': target[0]})) # @filterTopic($.Event("filter", {'target': target[0]}))
@collection.on "add", @addAndSelectThread @collection.on "add", @addAndSelectThread
@collection.on "thread:remove", @threadRemoved
@sidebar_padding = 10 @sidebar_padding = 10
@boardName @boardName = null
@template = _.template($("#thread-list-template").html()) @template = _.template($("#thread-list-template").html())
@current_search = "" @current_search = ""
@mode = 'all' @mode = 'all'
...@@ -239,11 +241,13 @@ if Backbone? ...@@ -239,11 +241,13 @@ if Backbone?
@trigger("thread:selected", thread_id) # This triggers a callback in the DiscussionRouter which calls the line above... @trigger("thread:selected", thread_id) # This triggers a callback in the DiscussionRouter which calls the line above...
false false
threadRemoved: (thread_id) => threadRemoved: (thread) =>
@trigger("thread:removed", thread_id) if @active_thread_id == thread.id
@trigger("thread:deselected", thread.id)
setActiveThread: (thread_id) -> setActiveThread: (thread_id) ->
@$(".forum-nav-thread-link").find(".sr").remove() @$(".forum-nav-thread-link").find(".sr").remove()
@active_thread_id = thread_id
@$(".forum-nav-thread[data-id!='#{thread_id}'] .forum-nav-thread-link").removeClass("is-active") @$(".forum-nav-thread[data-id!='#{thread_id}'] .forum-nav-thread-link").removeClass("is-active")
@$(".forum-nav-thread[data-id='#{thread_id}'] .forum-nav-thread-link").addClass("is-active").find(".forum-nav-thread-wrapper-1").prepend('<span class="sr">' + gettext("Current conversation") + '</span>') @$(".forum-nav-thread[data-id='#{thread_id}'] .forum-nav-thread-link").addClass("is-active").find(".forum-nav-thread-wrapper-1").prepend('<span class="sr">' + gettext("Current conversation") + '</span>')
...@@ -254,15 +258,13 @@ if Backbone? ...@@ -254,15 +258,13 @@ if Backbone?
$("input.email-setting").bind "click", @updateEmailNotifications $("input.email-setting").bind "click", @updateEmailNotifications
url = DiscussionUtil.urlFor("notifications_status",window.user.get("id")) url = DiscussionUtil.urlFor("notifications_status",window.user.get("id"))
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
url: url url: url
type: "GET" type: "GET"
success: (response, textStatus) => success: (response, textStatus) =>
if response.status if response.status
$('input.email-setting').attr('checked','checked') $('input.email-setting').attr('checked','checked')
else else
$('input.email-setting').removeAttr('checked') $('input.email-setting').removeAttr('checked')
thread_id = null
@trigger("thread:removed")
#select all threads #select all threads
isBrowseMenuVisible: => isBrowseMenuVisible: =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment