Select Git revision
h5peditor-group.js
h5peditor-group.js 10.39 KiB
/* global ns */
/**
* Create a group of fields.
*
* @param {mixed} parent
* @param {object} field
* @param {mixed} params
* @param {function} setValue
* @returns {ns.Group}
*/
ns.Group = function (parent, field, params, setValue) {
// Support for events
H5P.EventDispatcher.call(this);
if (field.label === undefined) {
field.label = field.name;
}
else if (field.label === 0) {
field.label = '';
}
this.parent = parent;
this.passReadies = true;
this.params = params;
this.setValue = setValue;
this.library = parent.library + '/' + field.name;
if (field.deprecated !== undefined && field.deprecated) {
this.field = H5P.cloneObject(field, true);
var empties = 0;
for (var i = 0; i < this.field.fields.length; i++) {
var f = this.field.fields[i];
if (params !== undefined && params[f.name] === '') {
delete params[f.name];
}
if (params === undefined || params[f.name] === undefined) {
f.widget = 'none';
empties++;
}
}
if (i === empties) {
this.field.fields = [];
}
}
else {
this.field = field;
}
if (this.field.optional === true) {
// If this field is optional, make sure child fields are as well
for (var j = 0; j < this.field.fields.length; j++) {
this.field.fields[j].optional = true;
}
}
};
// Extends the event dispatcher
ns.Group.prototype = Object.create(H5P.EventDispatcher.prototype);
ns.Group.prototype.constructor = ns.Group;
/**
* Append group to its wrapper.
*
* @param {jQuery} $wrapper
* @returns {undefined}
*/
ns.Group.prototype.appendTo = function ($wrapper) {
var that = this;
if (this.field.fields.length === 0) {