Create a dedicated CMS.Models.Course Backbone model
Initialize on every page that has a context_course set
This commit is contained in:
@@ -244,6 +244,7 @@ PIPELINE_JS = {
|
||||
rooted_glob(COMMON_ROOT / 'static/', 'coffee/src/**/*.js') +
|
||||
rooted_glob(PROJECT_ROOT / 'static/', 'coffee/src/**/*.js')
|
||||
) + ['js/hesitate.js', 'js/base.js', 'js/views/feedback.js',
|
||||
'js/models/course.js',
|
||||
'js/models/section.js', 'js/views/section.js',
|
||||
'js/models/metadata_model.js', 'js/views/metadata_editor_view.js',
|
||||
'js/models/textbook.js', 'js/views/textbook.js',
|
||||
|
||||
9
cms/static/coffee/spec/models/course_spec.coffee
Normal file
9
cms/static/coffee/spec/models/course_spec.coffee
Normal file
@@ -0,0 +1,9 @@
|
||||
describe "CMS.Models.Course", ->
|
||||
describe "basic", ->
|
||||
beforeEach ->
|
||||
@model = new CMS.Models.Course({
|
||||
name: "Greek Hero"
|
||||
})
|
||||
|
||||
it "should take a name argument", ->
|
||||
expect(@model.get("name")).toEqual("Greek Hero")
|
||||
10
cms/static/js/models/course.js
Normal file
10
cms/static/js/models/course.js
Normal file
@@ -0,0 +1,10 @@
|
||||
CMS.Models.Course = Backbone.Model.extend({
|
||||
defaults: {
|
||||
"name": ""
|
||||
},
|
||||
validate: function(attrs, options) {
|
||||
if (!attrs.name) {
|
||||
return gettext("You must specify a name");
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -58,6 +58,18 @@
|
||||
<script type="text/javascript" src="//www.youtube.com/player_api"></script>
|
||||
|
||||
<script src="${static.url('js/views/feedback.js')}"></script>
|
||||
% if context_course:
|
||||
<script type="text/javascript">
|
||||
window.course = new CMS.Models.Course({
|
||||
id: "${context_course.id}",
|
||||
name: "${context_course.display_name_with_default | h}",
|
||||
url_name: "${context_course.location.name | h}",
|
||||
org: "${context_course.location.org | h}",
|
||||
num: "${context_course.location.course | h}",
|
||||
revision: "${context_course.location.revision | h}"
|
||||
});
|
||||
</script>
|
||||
% endif
|
||||
|
||||
<!-- view -->
|
||||
<div class="wrapper wrapper-view">
|
||||
|
||||
@@ -162,14 +162,6 @@
|
||||
|
||||
<%block name="jsextra">
|
||||
<script type="text/javascript">
|
||||
window.section = new CMS.Models.Section({
|
||||
id: "${context_course.id}",
|
||||
name: "${context_course.display_name_with_default | h}",
|
||||
url_name: "${context_course.location.name | h}",
|
||||
org: "${context_course.location.org | h}",
|
||||
num: "${context_course.location.course | h}",
|
||||
revision: "${context_course.location.revision | h}"
|
||||
});
|
||||
var staffEmails = ${json.dumps([user.email for user in staff])};
|
||||
var tplUserURL = "${reverse('course_team_user', kwargs=dict(
|
||||
org=context_course.location.org,
|
||||
@@ -204,7 +196,7 @@
|
||||
if(_.contains(staffEmails, email)) {
|
||||
var msg = new CMS.Views.Prompt.Warning({
|
||||
title: gettext("Already a course team member"),
|
||||
message: _.template(gettext("{email} is already on the {course} team. If you're trying to add a new member, please double-check the email address you provided."), {email: email, course: section.get('name')}, {interpolate: /\{(.+?)\}/g}),
|
||||
message: _.template(gettext("{email} is already on the {course} team. If you're trying to add a new member, please double-check the email address you provided."), {email: email, course: course.escape('name')}, {interpolate: /\{(.+?)\}/g}),
|
||||
actions: {
|
||||
primary: {
|
||||
text: gettext("Return to team listing"),
|
||||
@@ -281,7 +273,7 @@
|
||||
var email = $(this).data('id');
|
||||
var msg = new CMS.Views.Prompt.Warning({
|
||||
title: gettext("Are you sure?"),
|
||||
message: _.template(gettext("Are you sure you want to delete {email} from the course team for {course}?"), {email: email, course: section.get('name')}, {interpolate: /\{(.+?)\}/g}),
|
||||
message: _.template(gettext("Are you sure you want to delete {email} from the course team for {course}?"), {email: email, course: course.get('name')}, {interpolate: /\{(.+?)\}/g}),
|
||||
actions: {
|
||||
primary: {
|
||||
text: gettext("Delete"),
|
||||
|
||||
Reference in New Issue
Block a user