From eac14615cd63a9ad24442ac5a74a1851a60cdd07 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Wed, 24 Jul 2013 16:15:30 -0400 Subject: [PATCH 1/5] Load advanced_entry template on page, rather than via AJAX --- cms/static/js/views/settings/advanced_view.js | 16 ++++------------ cms/templates/js/advanced_entry.underscore | 11 +++++++++++ cms/templates/settings_advanced.html | 14 ++++++++------ 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 cms/templates/js/advanced_entry.underscore diff --git a/cms/static/js/views/settings/advanced_view.js b/cms/static/js/views/settings/advanced_view.js index 90e84adf2b..5ae0c19570 100644 --- a/cms/static/js/views/settings/advanced_view.js +++ b/cms/static/js/views/settings/advanced_view.js @@ -11,16 +11,9 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ // TODO enable/disable save based on validation (currently enabled whenever there are changes) }, initialize : function() { - var self = this; - // instantiates an editor template for each update in the collection - window.templateLoader.loadRemoteTemplate("advanced_entry", - "/static/client_templates/advanced_entry.html", - function (raw_template) { - self.template = _.template(raw_template); - self.render(); - } - ); + this.template = _.template($("#advanced_entry-tpl").text()); this.listenTo(this.model, 'invalid', this.handleValidationError); + this.render(); }, render: function() { // catch potential outside call before template loaded @@ -56,7 +49,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ CodeMirror.fromTextArea(textarea, { mode: "application/json", lineNumbers: false, lineWrapping: false, onChange: function(instance, changeobj) { - instance.save() + instance.save(); // this event's being called even when there's no change :-( if (instance.getValue() !== oldValue) { var message = gettext("Your changes will not take effect until you save your progress. Take care with key and value formatting, as validation is not implemented."); @@ -105,8 +98,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ // call validateKey on each to ensure proper format // check for dupes var self = this; - this.model.save({}, - { + this.model.save({}, { success : function() { self.render(); var title = gettext("Your policy changes have been saved."); diff --git a/cms/templates/js/advanced_entry.underscore b/cms/templates/js/advanced_entry.underscore new file mode 100644 index 0000000000..26b1a386f6 --- /dev/null +++ b/cms/templates/js/advanced_entry.underscore @@ -0,0 +1,11 @@ +
  • +
    + + +
    + +
    + + +
    +
  • diff --git a/cms/templates/settings_advanced.html b/cms/templates/settings_advanced.html index e1b1913c87..0409b1a9e4 100644 --- a/cms/templates/settings_advanced.html +++ b/cms/templates/settings_advanced.html @@ -1,15 +1,17 @@ -<%! from django.utils.translation import ugettext as _ %> <%inherit file="base.html" /> +<%namespace name='static' file='static_content.html'/> <%! from django.core.urlresolvers import reverse %> +<%! from django.utils.translation import ugettext as _ %> +<%! from contentstore import utils %> <%block name="title">${_("Advanced Settings")} <%block name="bodyclass">is-signedin course advanced settings -<%namespace name='static' file='static_content.html'/> -<%! -from contentstore import utils -%> - <%block name="jsextra"> +% for template_name in ["advanced_entry"]: + +% endfor From 97fb08ab0829b6d15fcbf31fcacb65e19ed1097d Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 25 Jul 2013 12:56:37 -0400 Subject: [PATCH 2/5] Make mitxmako.render_to_response not require a dictionary argument --- common/djangoapps/mitxmako/shortcuts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/mitxmako/shortcuts.py b/common/djangoapps/mitxmako/shortcuts.py index 7f7c3f9ebe..3c68fa85be 100644 --- a/common/djangoapps/mitxmako/shortcuts.py +++ b/common/djangoapps/mitxmako/shortcuts.py @@ -92,9 +92,10 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'): return template.render_unicode(**context_dictionary) -def render_to_response(template_name, dictionary, context_instance=None, namespace='main', **kwargs): +def render_to_response(template_name, dictionary=None, context_instance=None, namespace='main', **kwargs): """ Returns a HttpResponse whose content is filled with the result of calling lookup.get_template(args[0]).render with the passed arguments. """ + dictionary = dictionary or {} return HttpResponse(render_to_string(template_name, dictionary, context_instance, namespace), **kwargs) From 5b9e2835529278b1164d70b5b464eca9a6f2ec7c Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 25 Jul 2013 17:02:50 -0400 Subject: [PATCH 3/5] Load course info update template on page instead of via AJAX --- cms/static/js/views/course_info_edit.js | 11 +---------- cms/templates/course_info.html | 7 +++++++ .../js/course_info_update.underscore} | 0 3 files changed, 8 insertions(+), 10 deletions(-) rename cms/{static/client_templates/course_info_update.html => templates/js/course_info_update.underscore} (100%) diff --git a/cms/static/js/views/course_info_edit.js b/cms/static/js/views/course_info_edit.js index ecd9ebe78d..ae0a66d45b 100644 --- a/cms/static/js/views/course_info_edit.js +++ b/cms/static/js/views/course_info_edit.js @@ -34,16 +34,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ }, initialize: function() { - var self = this; - // instantiates an editor template for each update in the collection - window.templateLoader.loadRemoteTemplate("course_info_update", - // TODO Where should the template reside? how to use the static.url to create the path? - "/static/client_templates/course_info_update.html", - function (raw_template) { - self.template = _.template(raw_template); - self.render(); - } - ); + this.template = _.template($("#course_info_update-tpl").text()); // when the client refetches the updates as a whole, re-render them this.listenTo(this.collection, 'reset', this.render); }, diff --git a/cms/templates/course_info.html b/cms/templates/course_info.html index dcfffd1d5a..eca3628b50 100644 --- a/cms/templates/course_info.html +++ b/cms/templates/course_info.html @@ -6,6 +6,13 @@ <%block name="title">${_("Course Updates")} <%block name="bodyclass">is-signedin course course-info updates +<%block name="header_extras"> +% for template_name in ["course_info_update"]: + +% endfor + <%block name="jsextra"> diff --git a/cms/static/client_templates/course_info_update.html b/cms/templates/js/course_info_update.underscore similarity index 100% rename from cms/static/client_templates/course_info_update.html rename to cms/templates/js/course_info_update.underscore From 372992244c8f68c37964fc7b3716bbb22739167f Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 25 Jul 2013 17:26:52 -0400 Subject: [PATCH 4/5] Removed course_info_handouts AJAX load --- cms/static/js/views/course_info_edit.js | 9 ++------- cms/templates/course_info.html | 3 +-- .../js/course_info_handouts.underscore} | 0 3 files changed, 3 insertions(+), 9 deletions(-) rename cms/{static/client_templates/course_info_handouts.html => templates/js/course_info_handouts.underscore} (100%) diff --git a/cms/static/js/views/course_info_edit.js b/cms/static/js/views/course_info_edit.js index ae0a66d45b..cb91422143 100644 --- a/cms/static/js/views/course_info_edit.js +++ b/cms/static/js/views/course_info_edit.js @@ -232,16 +232,11 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({ }, initialize: function() { + this.template = _.template($("#course_info_handouts-tpl").text()); var self = this; this.model.fetch({ complete: function() { - window.templateLoader.loadRemoteTemplate("course_info_handouts", - "/static/client_templates/course_info_handouts.html", - function (raw_template) { - self.template = _.template(raw_template); - self.render(); - } - ); + self.render(); }, reset: true }); diff --git a/cms/templates/course_info.html b/cms/templates/course_info.html index eca3628b50..03f4c35d14 100644 --- a/cms/templates/course_info.html +++ b/cms/templates/course_info.html @@ -7,7 +7,7 @@ <%block name="bodyclass">is-signedin course course-info updates <%block name="header_extras"> -% for template_name in ["course_info_update"]: +% for template_name in ["course_info_update", "course_info_handouts"]: @@ -15,7 +15,6 @@ <%block name="jsextra"> - diff --git a/cms/static/client_templates/course_info_handouts.html b/cms/templates/js/course_info_handouts.underscore similarity index 100% rename from cms/static/client_templates/course_info_handouts.html rename to cms/templates/js/course_info_handouts.underscore From 4f5c2cce7560c3952e521aed098480944bfa64f9 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 30 Jul 2013 11:22:13 -0400 Subject: [PATCH 5/5] Re-added missing render() call --- cms/static/js/views/course_info_edit.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cms/static/js/views/course_info_edit.js b/cms/static/js/views/course_info_edit.js index cb91422143..38d2c78576 100644 --- a/cms/static/js/views/course_info_edit.js +++ b/cms/static/js/views/course_info_edit.js @@ -35,6 +35,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ initialize: function() { this.template = _.template($("#course_info_update-tpl").text()); + this.render(); // when the client refetches the updates as a whole, re-render them this.listenTo(this.collection, 'reset', this.render); },