Commit 404c36b8 by David Baumgold

PDF textbooks: namespace JS variables for URLs

parent 696a795c
......@@ -460,7 +460,7 @@ def textbook_index(request, org, course, name):
return HttpResponse('', content_type="application/json", status=204)
else:
upload_asset_callback_url = reverse('upload_asset', kwargs={
upload_asset_url = reverse('upload_asset', kwargs={
'org': org,
'course': course,
'coursename': name,
......@@ -473,6 +473,6 @@ def textbook_index(request, org, course, name):
return render_to_response('textbooks.html', {
'context_course': course_module,
'course': course_module,
'upload_asset_callback_url': upload_asset_callback_url,
'upload_asset_url': upload_asset_url,
'textbook_url': textbook_url,
})
......@@ -71,14 +71,14 @@ describe "CMS.Models.Textbook input/output", ->
describe "CMS.Collections.TextbookSet", ->
beforeEach ->
window.TEXTBOOK_URL = "/textbooks"
CMS.URL.TEXTBOOK = "/textbooks"
@collection = new CMS.Collections.TextbookSet()
afterEach ->
delete window.TEXTBOOK_URL
delete CMS.URL.TEXTBOOK
it "should have a url set", ->
expect(_.result(@collection, "url"), window.TEXTBOOK_URL)
expect(_.result(@collection, "url"), "/textbooks")
it "can call save", ->
spyOn(@collection, "sync")
......
......@@ -225,11 +225,11 @@ describe "CMS.Views.EditChapter", ->
@collection.add(@model)
@view = new CMS.Views.EditChapter({model: @model})
spyOn(@view, "remove").andCallThrough()
window.UPLOAD_ASSET_CALLBACK_URL = "/upload"
CMS.URL.UPLOAD_ASSET = "/upload"
window.section = new CMS.Models.Section({name: "abcde"})
afterEach ->
delete window.UPLOAD_ASSET_CALLBACK_URL
delete CMS.URL.UPLOAD_ASSET
delete window.section
it "can render", ->
......@@ -267,7 +267,7 @@ describe "CMS.Views.UploadDialog", ->
beforeEach ->
setFixtures($("<script>", {id: "upload-dialog-tpl", type: "text/template"}).text(tpl))
appendSetFixtures($("<script>", {id: "system-feedback-tpl", type: "text/template"}).text(feedbackTpl))
window.UPLOAD_ASSET_CALLBACK_URL = "/upload"
CMS.URL.UPLOAD_ASSET = "/upload"
@model = new CMS.Models.FileUpload()
@chapter = new CMS.Models.Chapter()
......@@ -288,7 +288,7 @@ describe "CMS.Views.UploadDialog", ->
realMethod.apply(this, arguments)
afterEach ->
delete window.UPLOAD_ASSET_CALLBACK_URL
delete CMS.URL.UPLOAD_ASSET
describe "Basic", ->
it "should be shown by default", ->
......@@ -346,7 +346,7 @@ describe "CMS.Views.UploadDialog", ->
expect(@model.get("uploading")).toBeTruthy()
expect(@requests.length).toEqual(1)
request = @requests[0]
expect(request.url).toEqual(UPLOAD_ASSET_CALLBACK_URL)
expect(request.url).toEqual("/upload")
expect(request.method).toEqual("POST")
request.respond(200, {"Content-Type": "application/json"},
......
......@@ -4,6 +4,7 @@ AjaxPrefix.addAjaxPrefix(jQuery, -> CMS.prefix)
Models: {}
Views: {}
Collections: {}
URL: {}
prefix: $("meta[name='path_prefix']").attr('content')
......
......@@ -39,7 +39,7 @@ CMS.Models.Textbook = Backbone.AssociatedModel.extend({
});
CMS.Collections.TextbookSet = Backbone.Collection.extend({
model: CMS.Models.Textbook,
url: function() { return window.TEXTBOOK_URL; },
url: function() { return CMS.URL.TEXTBOOK; },
initialize: function() {
this.listenTo(this, "editOne", this.editOne);
},
......
......@@ -259,7 +259,7 @@ CMS.Views.UploadDialog = Backbone.View.extend({
var oldInput = this.$("input[type=file]").get(0);
this.$el.html(this.template({
shown: this.options.shown,
url: UPLOAD_ASSET_CALLBACK_URL,
url: CMS.URL.UPLOAD_ASSET,
title: this.model.escape('title'),
message: this.model.escape('message'),
selectedFile: selectedFile,
......
......@@ -16,8 +16,8 @@
<%block name="jsextra">
<script type="text/javascript">
window.UPLOAD_ASSET_CALLBACK_URL = "${upload_asset_callback_url}"
window.TEXTBOOK_URL = "${textbook_url}"
CMS.URL.UPLOAD_ASSET = "${upload_asset_url}"
CMS.URL.TEXTBOOK = "${textbook_url}"
window.section = new CMS.Models.Section({
id: "${course.id}",
name: "${course.display_name_with_default | h}"
......
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