Commit fd52980a by cahrens

Option view, changes getting persisted.

parent 04bb7335
<div class="wrapper-comp-setting">
<label class="label setting-label" for="<%= uniqueId %>"><%= model.get('display_name') %></label>
<select class="input setting-input" id="<%= uniqueId %>" name="<%= model.get('display_name') %>">
<% _.each(model.get('options'), function(option) { %>
<option value="<%= option %>"><%= option %></option>
<% }) %>
</select>
<button class="action setting-clear inactive" type="button" name="setting-clear" value="Clear" data-tooltip="Clear">
<i class="ss-icon ss-symbolicons-block undo">&#x21A9;</i>
</button>
</div>
<span class="tip setting-help"><%= model.get('help') %></span>
<div class="wrapper-comp-setting">
<label class="label setting-label" for="setting-discussion_category"><%= model.get('display_name') %></label>
<input class="input setting-input" type="text" id="setting-discussion_category" value='<%= model.get("value") %>'/>
<!--button clickable if is-set -->
<label class="label setting-label" for="<%= uniqueId %>"><%= model.get('display_name') %></label>
<input class="input setting-input" type="text" id="<%= uniqueId %>" value='<%= model.get("value") %>'/>
<button class="action setting-clear inactive" type="button" name="setting-clear" value="Clear" data-tooltip="Clear">
<i class="ss-icon ss-symbolicons-block undo">&#x21A9;</i>
</button>
......
......@@ -19,12 +19,17 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
var counter = 0;
_.each(self.model.attributes,
function(item, key) {
self.views[key] = new CMS.Views.Metadata.Generic({
el: self.$el.find('.metadata_entry')[counter],
model: new CMS.Models.Metadata(item)
}
);
counter+=1;
var data = {
el: self.$el.find('.metadata_entry')[counter++],
model: new CMS.Models.Metadata(item)
};
if (item.options.length > 0) {
self.views[key] = new CMS.Views.Metadata.Option(data);
}
else {
self.views[key] = new CMS.Views.Metadata.String(data);
}
});
}
);
......
if (!CMS.Views['Metadata']) CMS.Views.Metadata = {};
CMS.Views.Metadata.Option = Backbone.View.extend({
// Model class ...
events : {
},
initialize : function() {
var self = this;
this.uniqueId = _.uniqueId('metadata_option_entry_');
// instantiates an editor template for each update in the collection
window.templateLoader.loadRemoteTemplate("metadata_option_entry",
"/static/client_templates/metadata_option_entry.html",
function (raw_template) {
self.template = _.template(raw_template);
self.$el.append(self.template({model: self.model, uniqueId: self.uniqueId}));
$('#' + self.uniqueId + " option").filter(function() {
return $(this).text() === self.model.get('value');
}).prop('selected', true);
}
);
},
modified: function () {
return this.getValue() !== this.model.getOriginalValue();
},
getValue: function() {
return this.$el.find('#' + this.uniqueId).find(":selected").text();
}
});
if (!CMS.Views['Metadata']) CMS.Views.Metadata = {};
CMS.Views.Metadata.Generic = Backbone.View.extend({
CMS.Views.Metadata.String = Backbone.View.extend({
// Model class ...
events : {
......@@ -8,12 +8,13 @@ CMS.Views.Metadata.Generic = Backbone.View.extend({
initialize : function() {
var self = this;
this.uniqueId = _.uniqueId('metadata_string_entry_');
// instantiates an editor template for each update in the collection
window.templateLoader.loadRemoteTemplate("metadata_entry",
window.templateLoader.loadRemoteTemplate("metadata_string_entry",
"/static/client_templates/metadata_string_entry.html",
function (raw_template) {
self.template = _.template(raw_template);
self.$el.append(self.template({model: self.model}));
self.$el.append(self.template({model: self.model, uniqueId: self.uniqueId}));
}
);
},
......@@ -23,6 +24,6 @@ CMS.Views.Metadata.Generic = Backbone.View.extend({
},
getValue: function() {
return this.$el.find('.editor').val();
return this.$el.find('#' + this.uniqueId).val();
}
});
......@@ -68,7 +68,8 @@ class CapaFields(object):
showanswer = String(help="When to show the problem answer to the student", scope=Scope.settings, default="closed",
values=["answered", "always", "attempted", "closed", "never"])
force_save_button = Boolean(help="Whether to force the save button to appear on the page", scope=Scope.settings, default=False)
rerandomize = Randomization(help="When to rerandomize the problem", default="always", scope=Scope.settings)
rerandomize = Randomization(help="When to rerandomize the problem", default="always", scope=Scope.settings,
values=["always", "onreset", "never", "per_student"])
data = String(help="XML data for the problem", scope=Scope.content)
correct_map = Object(help="Dictionary with the correctness of current student answers", scope=Scope.user_state, default={})
input_state = Object(help="Dictionary for maintaining the state of inputtypes", scope=Scope.user_state)
......
......@@ -648,8 +648,13 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
'inheritable': inheritable,
'explicitly_set': explicitly_set}
values = [] if field.values is None else field.values
for index, choice in enumerate(values):
values[index] = field.to_json(choice)
simple_metadata[field.name] = {'value': field.to_json(value),
'display_name' : field.display_name,
'options' : values,
'default_value': field.to_json(default_value),
'inheritable': inheritable,
'explicitly_set': explicitly_set,
......
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