Commit bb6cd7dc by jmclaus

Merge pull request #5554 from edx/jmclaus/fix-errors-discussion-xmodule

Fixed errors in discussion XModule
parents b6013a23 4f3240e4
...@@ -29,10 +29,7 @@ ...@@ -29,10 +29,7 @@
testUpdate = function(view, thread) { testUpdate = function(view, thread) {
spyOn($, 'ajax').andCallFake(function(params) { spyOn($, 'ajax').andCallFake(function(params) {
expect(params.url.path()).toEqual(DiscussionUtil.urlFor('update_thread', 'dummy_id')); expect(params.url.path()).toEqual(DiscussionUtil.urlFor('update_thread', 'dummy_id'));
if (view.isTabMode()) { expect(params.data.thread_type).toBe('discussion');
// TODO remove the tabMode condition, depends on #5554 / TNL-606
expect(params.data.thread_type).toBe('discussion');
}
expect(params.data.commentable_id).toBe('other_topic'); expect(params.data.commentable_id).toBe('other_topic');
expect(params.data.title).toBe('changed thread title'); expect(params.data.title).toBe('changed thread title');
params.success(); params.success();
...@@ -45,15 +42,12 @@ ...@@ -45,15 +42,12 @@
expect($.ajax).toHaveBeenCalled(); expect($.ajax).toHaveBeenCalled();
expect(thread.get('title')).toBe('changed thread title'); expect(thread.get('title')).toBe('changed thread title');
if (view.isTabMode()) { expect(thread.get('thread_type')).toBe('discussion');
// TODO remove the tabMode condition, depends on #5554 / TNL-606
expect(thread.get('thread_type')).toBe('discussion');
}
expect(thread.get('commentable_id')).toBe('other_topic'); expect(thread.get('commentable_id')).toBe('other_topic');
expect(thread.get('courseware_title')).toBe('Other Topic'); expect(thread.get('courseware_title')).toBe('Other Topic');
expect(view.$('.edit-post-title')).toHaveValue(''); expect(view.$('.edit-post-title')).toHaveValue('');
expect(view.$('.wmd-preview p')).toHaveText(''); expect(view.$('.wmd-preview p')).toHaveText('');
} };
it('can save new data correctly in tab mode', function() { it('can save new data correctly in tab mode', function() {
this.createEditView(); this.createEditView();
......
...@@ -127,9 +127,8 @@ describe "NewPostView", -> ...@@ -127,9 +127,8 @@ describe "NewPostView", ->
view.$(".cancel").click() view.$(".cancel").click()
expect(eventSpy).toHaveBeenCalled() expect(eventSpy).toHaveBeenCalled()
expect(view.$(".post-errors").html()).toEqual(""); expect(view.$(".post-errors").html()).toEqual("");
if mode == "tab" expect($("input[id$='post-type-question']")).toBeChecked()
expect($("input[id$='post-type-question']")).toBeChecked() expect($("input[id$='post-type-discussion']")).not.toBeChecked()
expect($("input[id$='post-type-discussion']")).not.toBeChecked()
expect(view.$(".js-post-title").val()).toEqual(""); expect(view.$(".js-post-title").val()).toEqual("");
expect(view.$(".js-post-body textarea").val()).toEqual(""); expect(view.$(".js-post-body textarea").val()).toEqual("");
expect(view.$(".js-follow")).toBeChecked() expect(view.$(".js-follow")).toBeChecked()
......
...@@ -99,13 +99,17 @@ if Backbone? ...@@ -99,13 +99,17 @@ if Backbone?
@newPostForm = $('.new-post-article') @newPostForm = $('.new-post-article')
@threadviews = @discussion.map (thread) => @threadviews = @discussion.map (thread) =>
new DiscussionThreadView( view = new DiscussionThreadView(
el: @$("article#thread_#{thread.id}"), el: @$("article#thread_#{thread.id}"),
model: thread, model: thread,
mode: "inline", mode: "inline",
course_settings: @course_settings, course_settings: @course_settings,
topicId: discussionId topicId: discussionId
) )
thread.on "thread:thread_type_updated", ->
view.rerender()
view.expand()
return view
_.each @threadviews, (dtv) -> dtv.render() _.each @threadviews, (dtv) -> dtv.render()
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info) DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
@newPostView = new NewPostView( @newPostView = new NewPostView(
......
...@@ -28,11 +28,9 @@ ...@@ -28,11 +28,9 @@
this.template = _.template($('#thread-edit-template').html()); this.template = _.template($('#thread-edit-template').html());
this.$el.html(this.template(this.model.toJSON())).appendTo(this.container); this.$el.html(this.template(this.model.toJSON())).appendTo(this.container);
this.submitBtn = this.$('.post-update'); this.submitBtn = this.$('.post-update');
if (this.isTabMode()) { threadTypeTemplate = _.template($("#thread-type-template").html());
threadTypeTemplate = _.template($("#thread-type-template").html()); this.addField(threadTypeTemplate({form_id: formId}));
this.addField(threadTypeTemplate({form_id: formId})); this.$("#" + formId + "-post-type-" + this.threadType).attr('checked', true);
this.$("#" + formId + "-post-type-" + this.threadType).attr('checked', true);
}
this.topicView = new DiscussionTopicMenuView({ this.topicView = new DiscussionTopicMenuView({
topicId: this.topicId, topicId: this.topicId,
course_settings: this.course_settings course_settings: this.course_settings
...@@ -55,7 +53,13 @@ ...@@ -55,7 +53,13 @@
var title = this.$('.edit-post-title').val(), var title = this.$('.edit-post-title').val(),
threadType = this.$(".post-type-input:checked").val(), threadType = this.$(".post-type-input:checked").val(),
body = this.$('.edit-post-body textarea').val(), body = this.$('.edit-post-body textarea').val(),
commentableId = this.topicView.getCurrentTopicId(); commentableId = this.topicView.getCurrentTopicId(),
postData = {
title: title,
thread_type: threadType,
body: body,
commentable_id: commentableId
};
return DiscussionUtil.safeAjax({ return DiscussionUtil.safeAjax({
$elem: this.submitBtn, $elem: this.submitBtn,
...@@ -64,28 +68,18 @@ ...@@ -64,28 +68,18 @@
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
async: false, // @TODO when the rest of the stuff below is made to work properly.. async: false, // @TODO when the rest of the stuff below is made to work properly..
data: { data: postData,
title: title,
thread_type: threadType,
body: body,
commentable_id: commentableId
},
error: DiscussionUtil.formErrorHandler(this.$('.post-errors')), error: DiscussionUtil.formErrorHandler(this.$('.post-errors')),
success: function() { success: function() {
var newAttrs = {
title: title,
body: body,
thread_type: threadType,
commentable_id: commentableId,
courseware_title: this.topicView.getFullTopicName()
};
// @TODO: Move this out of the callback, this makes it feel sluggish // @TODO: Move this out of the callback, this makes it feel sluggish
this.$('.edit-post-title').val('').attr('prev-text', ''); this.$('.edit-post-title').val('').attr('prev-text', '');
this.$('.edit-post-body textarea').val('').attr('prev-text', ''); this.$('.edit-post-body textarea').val('').attr('prev-text', '');
this.$('.wmd-preview p').html(''); this.$('.wmd-preview p').html('');
this.model.set(newAttrs).unset('abbreviatedBody'); postData.courseware_title = this.topicView.getFullTopicName();
this.model.set(postData).unset('abbreviatedBody');
this.trigger('thread:updated'); this.trigger('thread:updated');
if (this.threadType !== threadType) { if (this.threadType !== threadType) {
this.model.set("thread_type", threadType)
this.model.trigger('thread:thread_type_updated'); this.model.trigger('thread:thread_type_updated');
this.trigger('comment:endorse'); this.trigger('comment:endorse');
} }
......
...@@ -34,6 +34,20 @@ if Backbone? ...@@ -34,6 +34,20 @@ if Backbone?
if @isQuestion() if @isQuestion()
@markedAnswers = new Comments() @markedAnswers = new Comments()
rerender: () ->
if @showView?
@showView.undelegateEvents()
@undelegateEvents()
@$el.empty()
@initialize(
mode: @mode
model: @model
el: @el
course_settings: @course_settings
topicId: @topicId
)
@render()
renderTemplate: -> renderTemplate: ->
@template = _.template($("#thread-template").html()) @template = _.template($("#thread-template").html())
@template(@model.toJSON()) @template(@model.toJSON())
......
...@@ -16,9 +16,9 @@ if Backbone? ...@@ -16,9 +16,9 @@ if Backbone?
form_id: @mode + (if @topicId then "-" + @topicId else "") form_id: @mode + (if @topicId then "-" + @topicId else "")
}) })
@$el.html(_.template($("#new-post-template").html(), context)) @$el.html(_.template($("#new-post-template").html(), context))
threadTypeTemplate = _.template($("#thread-type-template").html());
@addField(threadTypeTemplate({form_id: _.uniqueId("form-")}));
if @isTabMode() if @isTabMode()
threadTypeTemplate = _.template($("#thread-type-template").html());
@addField(threadTypeTemplate({form_id: _.uniqueId("form-")}));
@topicView = new DiscussionTopicMenuView { @topicView = new DiscussionTopicMenuView {
topicId: @topicId topicId: @topicId
course_settings: @course_settings course_settings: @course_settings
......
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