Commit de68896f by E. Kolpakov

Global setting for asynchronous ajax calls - to overcome firefox's strictness…

Global setting for asynchronous ajax calls - to overcome firefox's strictness about using synchronous ajax with credentials
parent 6f38997e
...@@ -9,6 +9,7 @@ function DiscussionCourseBlock(runtime, element) { ...@@ -9,6 +9,7 @@ function DiscussionCourseBlock(runtime, element) {
var hostname = testUrl.match(/^(.*:\/\/[a-z\-.]+)\//)[1]; var hostname = testUrl.match(/^(.*:\/\/[a-z\-.]+)\//)[1];
DiscussionUtil.setBaseUrl(hostname); DiscussionUtil.setBaseUrl(hostname);
DiscussionUtil.localUrls.push('user_profile'); DiscussionUtil.localUrls.push('user_profile');
DiscussionUtil.force_async = true;
pushState = false pushState = false
} }
......
...@@ -7,10 +7,8 @@ function DiscussionInlineBlock(runtime, element) { ...@@ -7,10 +7,8 @@ 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;
} }
new DiscussionModuleView({ new DiscussionModuleView({ el: el });
el: el,
async_thread_views: true
});
} }
...@@ -99,7 +99,6 @@ if Backbone? ...@@ -99,7 +99,6 @@ if Backbone?
@$el.append($discussion) @$el.append($discussion)
@newPostForm = $('.new-post-article') @newPostForm = $('.new-post-article')
async = @options.async_thread_views
@threadviews = @discussion.map (thread) => @threadviews = @discussion.map (thread) =>
view = new DiscussionThreadView( view = new DiscussionThreadView(
el: @$("article#thread_#{thread.id}"), el: @$("article#thread_#{thread.id}"),
......
...@@ -18,6 +18,8 @@ class @DiscussionUtil ...@@ -18,6 +18,8 @@ class @DiscussionUtil
@localUrls: [] @localUrls: []
@force_async = false
@getTemplate: (id) -> @getTemplate: (id) ->
$("script##{id}").html() $("script##{id}").html()
...@@ -161,6 +163,9 @@ class @DiscussionUtil ...@@ -161,6 +163,9 @@ class @DiscussionUtil
else else
params["$loading"].loading(params["takeFocus"]) params["$loading"].loading(params["takeFocus"])
if @force_async
params["async"] = true
request = $.ajax(params).always -> request = $.ajax(params).always ->
if $elem if $elem
$elem.removeAttr("disabled") $elem.removeAttr("disabled")
......
...@@ -60,7 +60,9 @@ if Backbone? ...@@ -60,7 +60,9 @@ if Backbone?
url: DiscussionUtil.urlFor('update_thread', @model.id), url: DiscussionUtil.urlFor('update_thread', @model.id),
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
async: false, # @TODO when the rest of the stuff below is made to work properly.. # TODO when the rest of the stuff below is made to work properly.
# Note it can be forced to true on global basis via DiscussionUtils.force_async
async: false,
data: postData, data: postData,
error: DiscussionUtil.formErrorHandler(@$('.post-errors')), error: DiscussionUtil.formErrorHandler(@$('.post-errors')),
success: => success: =>
......
...@@ -22,8 +22,6 @@ if Backbone? ...@@ -22,8 +22,6 @@ if Backbone?
if @mode not in ["tab", "inline"] if @mode not in ["tab", "inline"]
throw new Error("invalid mode: " + @mode) throw new Error("invalid mode: " + @mode)
@async_thread_views = if options.async_thread_views? then options.async_thread_views else false
# Quick fix to have an actual model when we're receiving new models from # Quick fix to have an actual model when we're receiving new models from
# the server. # the server.
@model.collection.on "reset", (collection) => @model.collection.on "reset", (collection) =>
...@@ -225,7 +223,7 @@ if Backbone? ...@@ -225,7 +223,7 @@ if Backbone?
renderResponseToList: (response, listSelector, options) => renderResponseToList: (response, listSelector, options) =>
response.set('thread', @model) response.set('thread', @model)
view = new ThreadResponseView($.extend({model: response, async: @async_thread_views}, options)) view = new ThreadResponseView($.extend({model: response}, options))
view.on "comment:add", @addComment view.on "comment:add", @addComment
view.on "comment:endorse", @endorseThread view.on "comment:endorse", @endorseThread
view.render() view.render()
......
...@@ -81,7 +81,9 @@ if Backbone? ...@@ -81,7 +81,9 @@ if Backbone?
url: url url: url
type: "POST" type: "POST"
dataType: 'json' dataType: 'json'
async: false # TODO when the rest of the stuff below is made to work properly.. # TODO when the rest of the stuff below is made to work properly..
# Note it can be forced to true on global basis via DiscussionUtils.force_async
async: false
data: data:
thread_type: thread_type thread_type: thread_type
title: title title: title
......
...@@ -12,7 +12,6 @@ if Backbone? ...@@ -12,7 +12,6 @@ if Backbone?
initialize: (options) -> initialize: (options) ->
@collapseComments = options.collapseComments @collapseComments = options.collapseComments
@async = if options.async? then options.async else false;
@createShowView() @createShowView()
renderTemplate: -> renderTemplate: ->
...@@ -198,7 +197,9 @@ if Backbone? ...@@ -198,7 +197,9 @@ if Backbone?
url: url url: url
type: "POST" type: "POST"
dataType: 'json' dataType: 'json'
async: @async # TODO when the rest of the stuff below is made to work properly.. # TODO when the rest of the stuff below is made to work properly..
# Note it can be forced to true on global basis via DiscussionUtils.force_async
async: false
data: data:
body: newBody body: newBody
error: DiscussionUtil.formErrorHandler(@$(".edit-post-form-errors")) error: DiscussionUtil.formErrorHandler(@$(".edit-post-form-errors"))
......
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