From 5d41e2a952bc15cb12894ad8f0b9e06dfbe51e7e Mon Sep 17 00:00:00 2001 From: cahrens <christina@edx.org> Date: Thu, 30 May 2013 12:26:01 -0400 Subject: [PATCH] Updates from code review. --- cms/static/js/views/metadata_editor_view.js | 23 +++++++++-------------- cms/templates/js/metadata-editor.underscore | 2 +- cms/templates/widgets/metadata-edit.html | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cms/static/js/views/metadata_editor_view.js b/cms/static/js/views/metadata_editor_view.js index 8f2fced..8994cff 100644 --- a/cms/static/js/views/metadata_editor_view.js +++ b/cms/static/js/views/metadata_editor_view.js @@ -10,7 +10,7 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({ } this.template = _.template(tpl); - this.$el.html(this.template({metadata_entries: this.model.attributes})); + this.$el.html(this.template({numEntries: this.model.keys().length})); var counter = 0; // Sort entries by display name. @@ -79,10 +79,11 @@ CMS.Views.Metadata.AbstractEditor = Backbone.View.extend({ // Model is CMS.Models.Metadata. initialize : function() { var self = this; - var templateName = this.getTemplateName(); + var templateName = _.result(this, 'templateName'); + // Backbone model cid is only unique within the collection. this.uniqueId = _.uniqueId(templateName + "_"); - var tpl = $("#"+templateName).text(); + var tpl = document.getElementById(templateName).text; if(!tpl) { console.error("Couldn't load template: " + templateName); } @@ -92,9 +93,9 @@ CMS.Views.Metadata.AbstractEditor = Backbone.View.extend({ }, /** - * Returns the ID/name of the template. Subclasses should implement this method. + * The ID/name of the template. Subclasses must override this. */ - getTemplateName : function () {}, + templateName: '', /** * Returns the value currently displayed in the editor/view. Subclasses should implement this method. @@ -170,9 +171,7 @@ CMS.Views.Metadata.String = CMS.Views.Metadata.AbstractEditor.extend({ "click .setting-clear" : "clear" }, - getTemplateName : function () { - return "metadata-string-entry"; - }, + templateName: "metadata-string-entry", getValueFromEditor : function () { return this.$el.find('#' + this.uniqueId).val(); @@ -232,9 +231,7 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({ } }, - getTemplateName : function () { - return "metadata-number-entry"; - }, + templateName: "metadata-number-entry", getValueFromEditor : function () { return this.$el.find('#' + this.uniqueId).val(); @@ -288,9 +285,7 @@ CMS.Views.Metadata.Option = CMS.Views.Metadata.AbstractEditor.extend({ "click .setting-clear" : "clear" }, - getTemplateName : function () { - return "metadata-option-entry"; - }, + templateName: "metadata-option-entry", getValueFromEditor : function () { var selectedText = this.$el.find('#' + this.uniqueId).find(":selected").text(); diff --git a/cms/templates/js/metadata-editor.underscore b/cms/templates/js/metadata-editor.underscore index 9c9ae24..03fdd28 100644 --- a/cms/templates/js/metadata-editor.underscore +++ b/cms/templates/js/metadata-editor.underscore @@ -1,5 +1,5 @@ <ul class="list-input settings-list"> - <% _.each(metadata_entries, function(entry) { %> + <% _.each(_.range(numEntries), function() { %> <li class="field comp-setting-entry metadata_entry" id="settings-listing"> </li> <% }) %> diff --git a/cms/templates/widgets/metadata-edit.html b/cms/templates/widgets/metadata-edit.html index f610b1b..db50a1d 100644 --- a/cms/templates/widgets/metadata-edit.html +++ b/cms/templates/widgets/metadata-edit.html @@ -26,7 +26,7 @@ </script> <% showHighLevelSource='source_code' in editable_metadata_fields and editable_metadata_fields['source_code']['explicitly_set'] %> -<% metadata_field_copy = copy.deepcopy(editable_metadata_fields) %> +<% metadata_field_copy = copy.copy(editable_metadata_fields) %> ## Delete 'source_code' field (if it exists) so metadata editor view does not attempt to render it. % if 'source_code' in editable_metadata_fields: ## source-edit.html needs access to the 'source_code' value, so delete from a copy. -- libgit2 0.26.0