From 17750a7d6d60d59d8600cf83ffc4b747e810e2f2 Mon Sep 17 00:00:00 2001 From: cahrens Date: Tue, 14 May 2013 14:20:10 -0400 Subject: [PATCH] Use min, max, and step values from server. --- .../metadata_number_entry.html | 2 +- cms/static/js/models/metadata_model.js | 7 ++++- cms/static/js/views/metadata_editor_view.js | 27 +++++++++++++++++++ common/lib/xmodule/xmodule/capa_module.py | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cms/static/client_templates/metadata_number_entry.html b/cms/static/client_templates/metadata_number_entry.html index 040488cb39..981db06bd4 100644 --- a/cms/static/client_templates/metadata_number_entry.html +++ b/cms/static/client_templates/metadata_number_entry.html @@ -1,6 +1,6 @@
- + diff --git a/cms/static/js/models/metadata_model.js b/cms/static/js/models/metadata_model.js index d2e3e52f66..90476431d4 100644 --- a/cms/static/js/models/metadata_model.js +++ b/cms/static/js/models/metadata_model.js @@ -8,7 +8,8 @@ CMS.Models.Metadata = Backbone.Model.extend({ "value" : null, "explicitly_set": null, "default_value" : null, - "options" : null + "options" : null, + "type" : null }, initialize: function() { @@ -55,6 +56,10 @@ CMS.Models.Metadata = Backbone.Model.extend({ return this.get('options'); }, + getType: function() { + return this.get('type'); + }, + clear: function() { this.set('explicitly_set', false); this.set('value', this.get('default_value')); diff --git a/cms/static/js/views/metadata_editor_view.js b/cms/static/js/views/metadata_editor_view.js index 9a1c324732..b4378bbbc7 100644 --- a/cms/static/js/views/metadata_editor_view.js +++ b/cms/static/js/views/metadata_editor_view.js @@ -159,6 +159,33 @@ CMS.Views.Metadata.Number = CMS.Views.Metadata.AbstractEditor.extend({ "click .setting-clear" : "clear" }, + render: function () { + CMS.Views.Metadata.AbstractEditor.prototype.render.apply(this); + if (!this.inputAttributesSet) { + var min = "min"; + var max = "max"; + var step = "step"; + var options = this.model.getOptions(); + if (options.hasOwnProperty(min)) { + this.$el.find('input').attr(min, options[min].toString()); + } + if (options.hasOwnProperty(max)) { + this.$el.find('input').attr(max, options[max].toString()); + } + var stepValue = undefined; + if (options.hasOwnProperty(step)) { + stepValue = options[step].toString(); + } + else if (this.model.getType() === 'Integer') { + stepValue = "1"; + } + if (stepValue !== undefined) { + this.$el.find('input').attr(step, stepValue); + } + this.inputAttributesSet = true; + } + }, + getTemplateName : function () { return "metadata_number_entry"; }, diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index b33cf5fb8c..3433e6c88b 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -89,7 +89,7 @@ class CapaFields(object): seed = StringyInteger(help="Random seed for this student", scope=Scope.user_state) weight = StringyFloat(display_name="Problem Weight", help="Specifies the number of points the problem is worth. If unset, each response field in the problem is worth one point.", - values = {"min" : 0 }, + values = {"min" : 0 , "step": ".1"}, scope=Scope.settings) markdown = String(help="Markdown source of this module", scope=Scope.settings) source_code = String(help="Source code for LaTeX and Word problems. This feature is not well-supported.",