2014-10-01 10:05:04 +02:00
|
|
|
/*jshint -W083 */
|
2014-07-18 10:50:23 +02:00
|
|
|
var H5PUpgrades = H5PUpgrades || {};
|
|
|
|
|
2014-06-03 16:07:50 +02:00
|
|
|
(function ($) {
|
2014-08-28 09:40:02 +02:00
|
|
|
var info, $container, librariesCache = {};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Initialize
|
|
|
|
$(document).ready(function () {
|
|
|
|
// Get library info
|
|
|
|
info = H5PIntegration.getLibraryInfo();
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Get and reset container
|
|
|
|
$container = $('#h5p-admin-container').html('<p>' + info.message + '</p>');
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Make it possible to select version
|
|
|
|
var $version = $(getVersionSelect(info.versions)).appendTo($container);
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Add "go" button
|
|
|
|
$('<button/>', {
|
|
|
|
class: 'h5p-admin-upgrade-button',
|
|
|
|
text: info.buttonLabel,
|
|
|
|
click: function () {
|
|
|
|
// Start new content upgrade
|
|
|
|
new ContentUpgrade($version.val());
|
|
|
|
}
|
|
|
|
}).appendTo($container);
|
2014-10-01 10:05:04 +02:00
|
|
|
});
|
2014-06-03 16:07:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate html for version select.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-03 16:07:50 +02:00
|
|
|
* @param {Object} versions
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
var getVersionSelect = function (versions) {
|
|
|
|
var html = '';
|
|
|
|
for (var id in versions) {
|
|
|
|
html += '<option value="' + id + '">' + versions[id] + '</option>';
|
|
|
|
}
|
|
|
|
if (html !== '') {
|
|
|
|
html = '<select>' + html + '</select>';
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-03 16:07:50 +02:00
|
|
|
/**
|
2014-06-13 15:02:26 +02:00
|
|
|
* Private. Helps process each property on the given object asynchronously in serial order.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {Object} obj
|
|
|
|
* @param {Function} process
|
|
|
|
* @param {Function} finished
|
2014-06-03 16:07:50 +02:00
|
|
|
*/
|
2014-06-13 15:02:26 +02:00
|
|
|
var asyncSerial = function (obj, process, finished) {
|
|
|
|
var id, isArray = obj instanceof Array;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
|
|
|
// Keep track of each property that belongs to this object.
|
2014-06-13 15:02:26 +02:00
|
|
|
if (!isArray) {
|
|
|
|
var ids = [];
|
|
|
|
for (id in obj) {
|
|
|
|
if (obj.hasOwnProperty(id)) {
|
|
|
|
ids.push(id);
|
2014-06-03 16:07:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
var i = -1; // Keeps track of the current property
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Private. Process the next property
|
|
|
|
*/
|
|
|
|
var next = function () {
|
|
|
|
id = isArray ? i : ids[i];
|
|
|
|
process(id, obj[id], check);
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Private. Check if we're done or have an error.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} err
|
|
|
|
*/
|
|
|
|
var check = function (err) {
|
2014-08-28 09:40:02 +02:00
|
|
|
// We need to use a real async function in order for the stack to clear.
|
|
|
|
setTimeout(function () {
|
|
|
|
i++;
|
|
|
|
if (i === (isArray ? obj.length : ids.length) || (err !== undefined && err !== null)) {
|
|
|
|
finished(err);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}, 0);
|
2014-06-13 15:02:26 +02:00
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
check(); // Start
|
2014-06-03 16:07:50 +02:00
|
|
|
};
|
2014-06-13 15:02:26 +02:00
|
|
|
|
2014-10-01 10:05:04 +02:00
|
|
|
/**
|
2014-06-13 15:02:26 +02:00
|
|
|
* Make it easy to keep track of version details.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} version
|
|
|
|
* @param {Number} libraryId
|
|
|
|
* @returns {_L1.Version}
|
2014-06-03 16:07:50 +02:00
|
|
|
*/
|
2014-06-13 15:02:26 +02:00
|
|
|
function Version(version, libraryId) {
|
|
|
|
if (libraryId !== undefined) {
|
|
|
|
version = info.versions[libraryId];
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Public
|
|
|
|
this.libraryId = libraryId;
|
2014-06-03 16:07:50 +02:00
|
|
|
}
|
2014-06-13 15:02:26 +02:00
|
|
|
var versionSplit = version.split('.', 3);
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Public
|
|
|
|
this.major = versionSplit[0];
|
|
|
|
this.minor = versionSplit[1];
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Public. Custom string for this object.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
this.toString = function () {
|
|
|
|
return version;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a throbber in the status field.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} msg
|
|
|
|
* @returns {_L1.Throbber}
|
|
|
|
*/
|
|
|
|
function Throbber(msg) {
|
|
|
|
var $throbber = H5PUtils.throbber(msg);
|
|
|
|
$container.html('').append($throbber);
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Makes it possible to set the progress.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} progress
|
|
|
|
*/
|
|
|
|
this.setProgress = function (progress) {
|
|
|
|
$throbber.text(msg + ' ' + progress);
|
|
|
|
};
|
|
|
|
}
|
2014-06-03 16:07:50 +02:00
|
|
|
|
|
|
|
/**
|
2014-06-13 15:02:26 +02:00
|
|
|
* Start a new content upgrade.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {Number} libraryId
|
|
|
|
* @returns {_L1.ContentUpgrade}
|
2014-06-03 16:07:50 +02:00
|
|
|
*/
|
2014-06-13 15:02:26 +02:00
|
|
|
function ContentUpgrade(libraryId) {
|
|
|
|
var self = this;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Get selected version
|
|
|
|
self.version = new Version(null, libraryId);
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Create throbber with loading text and progress
|
2014-06-16 14:04:53 +02:00
|
|
|
self.throbber = new Throbber(info.inProgress.replace('%ver', self.version));
|
2014-06-18 11:05:09 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Get the next batch
|
|
|
|
self.nextBatch({
|
|
|
|
libraryId: libraryId,
|
|
|
|
token: info.token
|
|
|
|
});
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Get the next batch and start processing it.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {Object} outData
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.nextBatch = function (outData) {
|
|
|
|
var self = this;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-07-18 10:50:23 +02:00
|
|
|
$.post(info.infoUrl, outData, function (inData) {
|
2014-06-03 16:07:50 +02:00
|
|
|
if (!(inData instanceof Object)) {
|
|
|
|
// Print errors from backend
|
2014-06-13 15:02:26 +02:00
|
|
|
return self.setStatus(inData);
|
2014-10-01 10:05:04 +02:00
|
|
|
}
|
2014-06-13 15:02:26 +02:00
|
|
|
if (inData.left === 0) {
|
|
|
|
// Nothing left to process
|
|
|
|
return self.setStatus(info.done);
|
2014-06-03 16:07:50 +02:00
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
self.left = inData.left;
|
|
|
|
self.token = inData.token;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Start processing
|
|
|
|
self.processBatch(inData.params);
|
2014-06-03 16:07:50 +02:00
|
|
|
});
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Set current status message.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} msg
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.setStatus = function (msg) {
|
|
|
|
$container.html(msg);
|
|
|
|
};
|
2014-06-03 16:07:50 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Process the given parameters.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {Object} parameters
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.processBatch = function (parameters) {
|
|
|
|
var self = this;
|
|
|
|
var upgraded = {}; // Track upgraded params
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
var current = 0; // Track progress
|
|
|
|
asyncSerial(parameters, function (id, params, next) {
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Make params possible to work with
|
|
|
|
params = JSON.parse(params);
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Upgrade this content.
|
|
|
|
self.upgrade(info.library.name, new Version(info.library.version), self.version, params, function (err, params) {
|
2014-06-16 13:52:35 +02:00
|
|
|
if (!err) {
|
2014-06-13 15:02:26 +02:00
|
|
|
upgraded[id] = JSON.stringify(params);
|
|
|
|
|
|
|
|
current++;
|
|
|
|
self.throbber.setProgress(Math.round((info.total - self.left + current) / (info.total / 100)) + ' %');
|
|
|
|
}
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
}, function (err) {
|
|
|
|
// Finished with all parameters that came in
|
2014-06-16 13:52:35 +02:00
|
|
|
if (err) {
|
2014-06-16 14:04:53 +02:00
|
|
|
return self.setStatus('<p>' + info.error + '<br/>' + err + '</p>');
|
2014-06-13 15:02:26 +02:00
|
|
|
}
|
2014-06-18 11:05:09 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Save upgraded content and get next round of data to process
|
|
|
|
self.nextBatch({
|
|
|
|
libraryId: self.version.libraryId,
|
|
|
|
token: self.token,
|
|
|
|
params: JSON.stringify(upgraded)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Upgade the given content.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} name
|
|
|
|
* @param {Version} oldVersion
|
|
|
|
* @param {Version} newVersion
|
|
|
|
* @param {Object} params
|
|
|
|
* @param {Function} next
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.upgrade = function (name, oldVersion, newVersion, params, next) {
|
|
|
|
var self = this;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Load library details and upgrade routines
|
|
|
|
self.loadLibrary(name, newVersion, function (err, library) {
|
2014-06-16 13:52:35 +02:00
|
|
|
if (err) {
|
|
|
|
return next(err);
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Run upgrade routines on params
|
|
|
|
self.processParams(library, oldVersion, newVersion, params, function (err, params) {
|
2014-06-16 13:52:35 +02:00
|
|
|
if (err) {
|
|
|
|
return next(err);
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Check if any of the sub-libraries need upgrading
|
|
|
|
asyncSerial(library.semantics, function (index, field, next) {
|
2014-06-16 13:52:35 +02:00
|
|
|
self.processField(field, params[field.name], function (err, upgradedParams) {
|
|
|
|
if (upgradedParams) {
|
|
|
|
params[field.name] = upgradedParams;
|
|
|
|
}
|
2014-06-13 15:02:26 +02:00
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
}, function (err) {
|
|
|
|
next(err, params);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Load library data needed for content upgrade.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} name
|
|
|
|
* @param {Version} version
|
|
|
|
* @param {Function} next
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.loadLibrary = function (name, version, next) {
|
|
|
|
var self = this;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-08-28 09:40:02 +02:00
|
|
|
var key = name + '/' + version.major + '/' + version.minor;
|
|
|
|
if (librariesCache[key] !== undefined) {
|
|
|
|
// Library has been loaded before. Return cache.
|
|
|
|
next(null, librariesCache[key]);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
$.ajax({
|
|
|
|
dataType: 'json',
|
2014-08-28 09:40:02 +02:00
|
|
|
cache: true,
|
|
|
|
url: info.libraryBaseUrl + '/' + key
|
2014-06-13 15:02:26 +02:00
|
|
|
}).fail(function () {
|
2014-06-16 14:04:53 +02:00
|
|
|
next(info.errorData.replace('%lib', name + ' ' + version));
|
2014-06-13 15:02:26 +02:00
|
|
|
}).done(function (library) {
|
2014-08-28 09:40:02 +02:00
|
|
|
librariesCache[key] = library;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
if (library.upgradesScript) {
|
|
|
|
self.loadScript(library.upgradesScript, function (err) {
|
|
|
|
if (err) {
|
2014-06-16 14:04:53 +02:00
|
|
|
err = info.errorScript.replace('%lib', name + ' ' + version);
|
2014-06-13 15:02:26 +02:00
|
|
|
}
|
|
|
|
next(err, library);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next(null, library);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Load script with upgrade hooks.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {String} url
|
|
|
|
* @param {Function} next
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.loadScript = function (url, next) {
|
|
|
|
$.ajax({
|
|
|
|
dataType: 'script',
|
|
|
|
cache: true,
|
|
|
|
url: url
|
|
|
|
}).fail(function () {
|
2014-06-16 14:04:53 +02:00
|
|
|
next(true);
|
2014-06-13 15:02:26 +02:00
|
|
|
}).done(function () {
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Run upgrade hooks on params.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {Object} library
|
|
|
|
* @param {Version} oldVersion
|
|
|
|
* @param {Version} newVersion
|
|
|
|
* @param {Object} params
|
|
|
|
* @param {Function} next
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.processParams = function (library, oldVersion, newVersion, params, next) {
|
|
|
|
if (H5PUpgrades[library.name] === undefined) {
|
2014-06-16 15:21:40 +02:00
|
|
|
if (library.upgradesScript) {
|
|
|
|
// Upgrades script should be loaded so the upgrades should be here.
|
|
|
|
return next(info.errorScript.replace('%lib', library.name + ' ' + newVersion));
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-16 15:21:40 +02:00
|
|
|
// No upgrades script. Move on
|
2014-06-13 15:02:26 +02:00
|
|
|
return next(null, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run upgrade hooks. Start by going through major versions
|
|
|
|
asyncSerial(H5PUpgrades[library.name], function (major, minors, nextMajor) {
|
|
|
|
if (major < oldVersion.major || major > newVersion.major) {
|
2014-10-01 10:05:04 +02:00
|
|
|
// Older than the current version or newer than the selected
|
2014-06-13 15:02:26 +02:00
|
|
|
nextMajor();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Go through the minor versions for this major version
|
|
|
|
asyncSerial(minors, function (minor, upgrade, nextMinor) {
|
|
|
|
if (minor <= oldVersion.minor || minor > newVersion.minor) {
|
|
|
|
// Older than or equal to the current version or newer than the selected
|
|
|
|
nextMinor();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We found an upgrade hook, run it
|
2014-08-04 10:49:49 +02:00
|
|
|
if (upgrade.contentUpgrade !== undefined && typeof upgrade.contentUpgrade === 'function') {
|
|
|
|
upgrade.contentUpgrade(params, function (err, upgradedParams) {
|
|
|
|
params = upgradedParams;
|
|
|
|
nextMinor(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nextMinor(info.errorScript.replace('%lib', library.name + ' ' + newVersion));
|
|
|
|
}
|
2014-06-13 15:02:26 +02:00
|
|
|
}
|
|
|
|
}, nextMajor);
|
|
|
|
}
|
|
|
|
}, function (err) {
|
|
|
|
next(err, params);
|
|
|
|
});
|
|
|
|
};
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
/**
|
|
|
|
* Process parameter fields to find and upgrade sub-libraries.
|
2014-10-01 10:05:04 +02:00
|
|
|
*
|
2014-06-13 15:02:26 +02:00
|
|
|
* @param {Object} field
|
|
|
|
* @param {Object} params
|
|
|
|
* @param {Function} next
|
|
|
|
*/
|
|
|
|
ContentUpgrade.prototype.processField = function (field, params, next) {
|
|
|
|
var self = this;
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-16 13:52:35 +02:00
|
|
|
if (params === undefined) {
|
|
|
|
return next();
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
switch (field.type) {
|
|
|
|
case 'library':
|
|
|
|
if (params.library === undefined || params.params === undefined) {
|
|
|
|
return next();
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// Look for available upgrades
|
|
|
|
var usedLib = params.library.split(' ', 2);
|
|
|
|
for (var i = 0; i < field.options.length; i++) {
|
|
|
|
var availableLib = field.options[i].split(' ', 2);
|
|
|
|
if (availableLib[0] === usedLib[0]) {
|
|
|
|
if (availableLib[1] === usedLib[1]) {
|
|
|
|
return next(); // Same version
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-13 15:02:26 +02:00
|
|
|
// We have different versions
|
|
|
|
var usedVer = new Version(usedLib[1]);
|
|
|
|
var availableVer = new Version(availableLib[1]);
|
|
|
|
if (usedVer.major > availableVer.major || (usedVer.major === availableVer.major && usedVer.minor >= availableVer.minor)) {
|
|
|
|
return next(); // Larger or same version that's available
|
|
|
|
}
|
2014-10-01 10:05:04 +02:00
|
|
|
|
2014-06-16 13:52:35 +02:00
|
|
|
// A newer version is available, upgrade params
|
|
|
|
return self.upgrade(availableLib[0], usedVer, availableVer, params.params, function (err, upgraded) {
|
|
|
|
if (!err) {
|
|
|
|
params.library = availableLib[0] + ' ' + availableVer.major + '.' + availableVer.minor;
|
|
|
|
params.params = upgraded;
|
|
|
|
}
|
|
|
|
next(err, params);
|
|
|
|
});
|
2014-06-13 15:02:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'group':
|
|
|
|
if (field.fields.length === 1) {
|
2014-06-16 13:52:35 +02:00
|
|
|
// Single field to process, wrapper will be skipped
|
|
|
|
self.processField(field.fields[0], params, function (err, upgradedParams) {
|
|
|
|
if (upgradedParams) {
|
|
|
|
params = upgradedParams;
|
|
|
|
}
|
|
|
|
next(err, params);
|
|
|
|
});
|
2014-06-13 15:02:26 +02:00
|
|
|
}
|
2014-06-16 13:52:35 +02:00
|
|
|
else {
|
|
|
|
// Go through all fields in the group
|
|
|
|
asyncSerial(field.fields, function (index, subField, next) {
|
|
|
|
self.processField(subField, params[subField.name], function (err, upgradedParams) {
|
|
|
|
if (upgradedParams) {
|
|
|
|
params[subField.name] = upgradedParams;
|
|
|
|
}
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
}, function (err) {
|
|
|
|
next(err, params);
|
2014-06-13 15:02:26 +02:00
|
|
|
});
|
2014-06-16 13:52:35 +02:00
|
|
|
}
|
2014-06-13 15:02:26 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'list':
|
|
|
|
// Go trough all params in the list
|
2014-06-16 13:52:35 +02:00
|
|
|
asyncSerial(params, function (index, subParams, next) {
|
|
|
|
self.processField(field.field, subParams, function (err, upgradedParams) {
|
|
|
|
if (upgradedParams) {
|
|
|
|
params[index] = upgradedParams;
|
|
|
|
}
|
2014-06-13 15:02:26 +02:00
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
}, function (err) {
|
|
|
|
next(err, params);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-01 10:05:04 +02:00
|
|
|
})(H5P.jQuery);
|