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