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}}";
function DiscussionCourseBlock(runtime, element) {
var el = $(element).find('section.discussion'),
pushState = true;
var el = $(element).find('section.discussion');
var testUrl = runtime.handlerUrl(element, 'test');
if (testUrl.match(/^(http|https):\/\//)) {
var hostname = testUrl.match(/^(.*:\/\/[a-z\-.]+)\//)[1];
var hostname = testUrl.match(/^(.*:\/\/[a-z0-9:\-.]+)\//)[1];
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) {
if (testUrl.match(/^(http|https):\/\//)) {
var hostname = testUrl.match(/^(.*:\/\/[a-z0-9:\-.]+)\//)[1];
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 });
......
......@@ -16,7 +16,6 @@ JS_URLS = [
'js/vendor/jquery.leanModal.min.js',
'js/vendor/jquery.timeago.js',
'js/vendor/underscore-min.js',
'js/vendor/backbone-min.js',
'js/vendor/mustache.js',
'js/vendor/mathjax-MathJax-c9db6ac/MathJax.js?config=TeX-MML-AM_HTMLorMML-full',
......
if Backbone?
class @DiscussionRouter extends Backbone.Router
routes:
"": "allThreads"
":forum_name/threads/:thread_id" : "showThread"
initialize: (options) ->
@route("#{DiscussionUtil.route_prefix}", "allThreads")
@route("#{DiscussionUtil.route_prefix}:forum_name/threads/:thread_id", "showThread")
@discussion = options['discussion']
@course_settings = options['course_settings']
......@@ -14,7 +13,7 @@ if Backbone?
courseSettings: @course_settings
)
@nav.on "thread:selected", @navigateToThread
@nav.on "thread:removed", @navigateToAllThreads
@nav.on "thread:deselected", @navigateToAllThreads
@nav.on "threads:rendered", @setActiveThread
@nav.on "thread:created", @navigateToThread
@nav.render()
......@@ -59,6 +58,7 @@ if Backbone?
@main = new DiscussionThreadView(
el: $(".forum-content"),
model: @thread,
mode: "tab",
course_settings: @course_settings,
......@@ -70,10 +70,10 @@ if Backbone?
navigateToThread: (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: =>
@navigate("", trigger: true)
@navigate("#{DiscussionUtil.route_prefix}", trigger: true)
showNewPost: (event) =>
$('.forum-content').fadeOut(
......
if Backbone?
@DiscussionApp =
start: (elem, pushState = true)->
start: (elem)->
# TODO: Perhaps eliminate usage of global variables when possible
DiscussionUtil.loadRolesFromContainer()
element = $(elem)
......@@ -17,7 +17,10 @@ if Backbone?
discussion = new Discussion(threads, {pages: thread_pages, sort: sort_preference})
course_settings = new DiscussionCourseSettings(element.data("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 =
start: (elem) ->
# Roles are not included in user profile page, but they are not used for anything
......
......@@ -19,6 +19,7 @@ class @DiscussionUtil
@localUrls: []
@force_async = false
@route_prefix = ''
@getTemplate: (id) ->
$("script##{id}").html()
......
......@@ -15,6 +15,7 @@ if Backbone?
"change .forum-nav-filter-cohort-control": "chooseCohort"
initialize: (options) ->
@active_thread_id = null
@courseSettings = options.courseSettings
@displayedCollection = new Discussion(@collection.models, pages: @collection.pages)
@collection.on "change", @reloadDisplayedCollection
......@@ -29,8 +30,9 @@ if Backbone?
# if target.length > 0
# @filterTopic($.Event("filter", {'target': target[0]}))
@collection.on "add", @addAndSelectThread
@collection.on "thread:remove", @threadRemoved
@sidebar_padding = 10
@boardName
@boardName = null
@template = _.template($("#thread-list-template").html())
@current_search = ""
@mode = 'all'
......@@ -239,11 +241,13 @@ if Backbone?
@trigger("thread:selected", thread_id) # This triggers a callback in the DiscussionRouter which calls the line above...
false
threadRemoved: (thread_id) =>
@trigger("thread:removed", thread_id)
threadRemoved: (thread) =>
if @active_thread_id == thread.id
@trigger("thread:deselected", thread.id)
setActiveThread: (thread_id) ->
@$(".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").addClass("is-active").find(".forum-nav-thread-wrapper-1").prepend('<span class="sr">' + gettext("Current conversation") + '</span>')
......@@ -254,15 +258,13 @@ if Backbone?
$("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")
url: url
type: "GET"
success: (response, textStatus) =>
if response.status
$('input.email-setting').attr('checked','checked')
else
$('input.email-setting').removeAttr('checked')
#select all threads
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