Commit c36046be by marco

Merge branch 'feature/christina/metadata-ui' of github.com:edx/mitx into…

Merge branch 'feature/christina/metadata-ui' of github.com:edx/mitx into feature/christina/metadata-ui
parents 2360a111 f4b06b2e
<ul class="list-input settings-list"> <ul class="list-input settings-list">
<% _.each(metadata_entries, function(entry) { %> <% _.each(metadata_entries, function(entry) { %>
<li class="field comp-setting-entry"> <li class="field comp-setting-entry metadata_entry">
<div class='metadata_entry' />
</li> </li>
<% }) %> <% }) %>
</ul> </ul>
\ No newline at end of file
<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"> <div class="wrapper-comp-setting">
<label class="label setting-label" for="setting-discussion_category"><%= model.get('display_name') %></label> <label class="label setting-label" for="<%= uniqueId %>"><%= model.get('display_name') %></label>
<input class="input setting-input" type="text" id="setting-discussion_category" value='<%= model.get("value") %>'/> <input class="input setting-input" type="text" id="<%= uniqueId %>" value='<%= model.get("value") %>'/>
<!--button clickable if is-set -->
<button class="action setting-clear inactive" type="button" name="setting-clear" value="Clear" data-tooltip="Clear"> <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> <i class="ss-icon ss-symbolicons-block undo">&#x21A9;</i>
</button> </button>
</div> </div>
<span class="tip setting-help"><%= model.get('help') %></span> <span class="tip setting-help"><%= model.get('help') %></span>
\ No newline at end of file
...@@ -19,12 +19,19 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({ ...@@ -19,12 +19,19 @@ CMS.Views.Metadata.Editor = Backbone.View.extend({
var counter = 0; var counter = 0;
_.each(self.model.attributes, _.each(self.model.attributes,
function(item, key) { function(item, key) {
self.views[key] = new CMS.Views.Metadata.Generic({ var data = {
el: self.$el.find('.metadata_entry')[counter], el: self.$el.find('.metadata_entry')[counter++],
model: new CMS.Models.Metadata(item) model: new CMS.Models.Metadata(item)
} };
); if (item.options.length > 0) {
counter+=1; // Right now, all our option types only hold strings. Should really support
// any type though.
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.Number = CMS.Views.Metadata.String.extend({
getValue: function() {
var stringVal = this.$el.find('#' + this.uniqueId).val();
if (this.isInteger) {
return parseInt(stringVal)
}
else {
return parseFloat(stringVal)
}
}
});
\ No newline at end of file
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);
if (self.model.get('explicitly_set')) {
self.$el.addClass('is-set');
self.$el.find('#'+self.uniqueId + " .setting-clear").addClass('active');
}
}
);
},
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 = {}; if (!CMS.Views['Metadata']) CMS.Views.Metadata = {};
CMS.Views.Metadata.Generic = Backbone.View.extend({ CMS.Views.Metadata.String = Backbone.View.extend({
// Model class ... // Model class ...
events : { events : {
...@@ -8,12 +8,17 @@ CMS.Views.Metadata.Generic = Backbone.View.extend({ ...@@ -8,12 +8,17 @@ CMS.Views.Metadata.Generic = Backbone.View.extend({
initialize : function() { initialize : function() {
var self = this; var self = this;
this.uniqueId = _.uniqueId('metadata_string_entry_');
// instantiates an editor template for each update in the collection // 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", "/static/client_templates/metadata_string_entry.html",
function (raw_template) { function (raw_template) {
self.template = _.template(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}));
if (self.model.get('explicitly_set')) {
self.$el.addClass('is-set');
self.$el.find('#'+self.uniqueId + " .setting-clear").addClass('active');
}
} }
); );
}, },
...@@ -23,6 +28,6 @@ CMS.Views.Metadata.Generic = Backbone.View.extend({ ...@@ -23,6 +28,6 @@ CMS.Views.Metadata.Generic = Backbone.View.extend({
}, },
getValue: function() { getValue: function() {
return this.$el.find('.editor').val(); return this.$el.find('#' + this.uniqueId).val();
} }
}); });
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
<!--TODO: not the right place--> <!--TODO: not the right place-->
<script type="text/javascript" src="${static.url('js/models/metadata_model.js')}"></script> <script type="text/javascript" src="${static.url('js/models/metadata_model.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/metadata_string_view.js')}"></script> <script type="text/javascript" src="${static.url('js/views/metadata_string_view.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/metadata_number_view.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/metadata_option_view.js')}"></script> <script type="text/javascript" src="${static.url('js/views/metadata_option_view.js')}"></script>
<script type="text/javascript" src="${static.url('js/models/metadata_editor.js')}"></script> <script type="text/javascript" src="${static.url('js/models/metadata_editor.js')}"></script>
<script type="text/javascript" src="${static.url('js/views/metadata_editor_view.js')}"></script> <script type="text/javascript" src="${static.url('js/views/metadata_editor_view.js')}"></script>
......
...@@ -68,7 +68,8 @@ class CapaFields(object): ...@@ -68,7 +68,8 @@ class CapaFields(object):
showanswer = String(help="When to show the problem answer to the student", scope=Scope.settings, default="closed", showanswer = String(help="When to show the problem answer to the student", scope=Scope.settings, default="closed",
values=["answered", "always", "attempted", "closed", "never"]) 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) 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) 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={}) 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) 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): ...@@ -648,8 +648,13 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
'inheritable': inheritable, 'inheritable': inheritable,
'explicitly_set': explicitly_set} '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), simple_metadata[field.name] = {'value': field.to_json(value),
'display_name' : field.display_name, 'display_name' : field.display_name,
'options' : values,
'default_value': field.to_json(default_value), 'default_value': field.to_json(default_value),
'inheritable': inheritable, 'inheritable': inheritable,
'explicitly_set': explicitly_set, '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