This commit implements STUD-1490, allowing creation of components on the container page. It also enables the delete and duplicate buttons now that new content can be created that would benefit. Note that it also creates shared functionality for adding components, and refactors the unit page to use it too.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
/**
|
|
* Simple model for adding a component of a given type (for example, "video" or "html").
|
|
*/
|
|
define(["backbone"], function (Backbone) {
|
|
return Backbone.Model.extend({
|
|
defaults: {
|
|
type: "",
|
|
// Each entry in the template array is an Object with the following keys:
|
|
// display_name
|
|
// category (may or may not match "type")
|
|
// boilerplate_name (may be null)
|
|
// is_common (only used for problems)
|
|
templates: []
|
|
},
|
|
parse: function (response) {
|
|
this.type = response.type;
|
|
this.templates = response.templates;
|
|
|
|
// Sort the templates.
|
|
this.templates.sort(function (a, b) {
|
|
// The entry without a boilerplate always goes first
|
|
if (!a.boilerplate_name || (a.display_name < b.display_name)) {
|
|
return -1;
|
|
}
|
|
else {
|
|
return (a.display_name > b.display_name) ? 1 : 0;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|