Commit 3b76fe16 by Rocky Duan

make inline page working

parent 951fb063
......@@ -125,7 +125,11 @@ def inline_discussion(request, course_id, discussion_id):
threads, query_params = get_threads(request, course_id, discussion_id)
html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \
query_params=query_params)
return utils.HtmlResponse(html)
return utils.JsonResponse({
'html': html,
'discussionData': threads,
})
def render_search_bar(request, course_id, discussion_id=None, text=''):
if not discussion_id:
......@@ -142,8 +146,6 @@ def forum_form_discussion(request, course_id):
threads, query_params = get_threads(request, course_id)
content = render_forum_discussion(request, course_id, threads, discussion_id=_general_discussion_id(course_id), query_params=query_params)
if request.is_ajax():
return utils.JsonResponse({
'html': content,
......
......@@ -175,7 +175,7 @@ class @ContentView extends Backbone.View
data:
body: body
anonymous: anonymous
autowatch: autowatch
auto_subscribe: autowatch
error: DiscussionUtil.formErrorHandler @$(".discussion-errors")
success: (response, textStatus) =>
DiscussionUtil.clearFormErrors @$(".discussion-errors")
......
......@@ -15,8 +15,6 @@ class @Discussion extends Backbone.Collection
@add model
model
class @DiscussionModuleView extends Backbone.View
class @DiscussionView extends Backbone.View
$: (selector) ->
......@@ -39,11 +37,13 @@ class @DiscussionView extends Backbone.View
@newPost()
reload: ($elem, url) ->
console.log "here"
if not url then return
DiscussionUtil.get $elem, url, {}, (response, textStatus) =>
$discussion = $(response.html)
console.log response
$parent = @$el.parent()
@$el.replaceWith($discussion)
@$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)
......@@ -111,6 +111,8 @@ class @DiscussionView extends Backbone.View
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)
......@@ -121,6 +123,8 @@ class @DiscussionView extends Backbone.View
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"))
......
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) ->
console.log "toggle"
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 = DiscussionUtil.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
......@@ -7,7 +7,7 @@ $ ->
view = new DiscussionModuleView(el: elem)
$("section.discussion").each (index, elem) ->
discussionData = DiscussionUtil.getDiscussionData(elem)
discussionData = DiscussionUtil.getDiscussionData($(elem).attr("_id"))
discussion = new Discussion()
discussion.reset(discussionData, {silent: false})
view = new DiscussionView(el: elem, model: discussion)
......
......@@ -6,10 +6,6 @@ class @DiscussionUtil
$("script##{id}").html()
@getDiscussionData: (id) ->
if id instanceof $
id = id.attr("_id")
else if typeof id == "object"
id = $(id).attr("_id")
return $$discussion_data[id]
@addContent: (id, content) -> window.$$contents[id] = content
......
......@@ -5,7 +5,7 @@
<%block name="headextra">
<%static:css group='course'/>
<%include file="discussion/_js_head_dependencies.html" />
<%include file="../discussion/_js_head_dependencies.html" />
</%block>
<%block name="js_extra">
......@@ -23,7 +23,7 @@
<%static:js group='courseware'/>
<%include file="discussion/_js_body_dependencies.html" />
<%include file="../discussion/_js_body_dependencies.html" />
<!-- TODO: http://docs.jquery.com/Plugins/Validation -->
......
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