2014-03-26 08:43:29 +01:00
|
|
|
var H5PLibraryList= H5PLibraryList || {};
|
|
|
|
|
|
|
|
(function ($) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializing
|
|
|
|
*/
|
|
|
|
H5PLibraryList.init = function () {
|
|
|
|
var $adminContainer = H5PIntegration.getAdminContainer();
|
|
|
|
|
2014-05-28 13:18:24 +02:00
|
|
|
var libraryList = H5PIntegration.getLibraryList();
|
|
|
|
if (libraryList.notCached) {
|
|
|
|
$adminContainer.append(H5PUtils.getRebuildCache(libraryList.notCached));
|
|
|
|
}
|
|
|
|
|
2014-03-26 08:43:29 +01:00
|
|
|
// Create library list
|
|
|
|
$adminContainer.append(H5PLibraryList.createLibraryList(H5PIntegration.getLibraryList()));
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the library list
|
|
|
|
*
|
|
|
|
* @param {object} libraries List of libraries and headers
|
|
|
|
*/
|
|
|
|
H5PLibraryList.createLibraryList = function (libraries) {
|
|
|
|
|
|
|
|
if(libraries.listData === undefined || libraries.listData.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create table
|
|
|
|
var $table = H5PUtils.createTable(libraries.listHeaders);
|
|
|
|
$table.addClass('libraries');
|
|
|
|
|
|
|
|
// Add libraries
|
2014-06-03 16:07:50 +02:00
|
|
|
var t = H5PIntegration.i18n.H5P;
|
2014-03-26 08:43:29 +01:00
|
|
|
$.each (libraries.listData, function (index, library) {
|
|
|
|
var $libraryRow = H5PUtils.createTableRow([
|
2014-06-03 16:07:50 +02:00
|
|
|
library.title,
|
|
|
|
library.numContent,
|
2014-08-22 11:39:45 +02:00
|
|
|
library.numContentDependencies,
|
2014-06-03 16:07:50 +02:00
|
|
|
library.numLibraryDependencies,
|
|
|
|
'<div class="h5p-admin-buttons-wrapper">\
|
|
|
|
<button class="h5p-admin-upgrade-library"></button>\
|
|
|
|
<button class="h5p-admin-view-library" title="' + t.viewLibrary + '"></button>\
|
|
|
|
<button class="h5p-admin-delete-library"></button>\
|
|
|
|
</div>'
|
2014-03-26 08:43:29 +01:00
|
|
|
]);
|
|
|
|
|
2014-08-22 12:00:06 +02:00
|
|
|
if (library.upgradeUrl === null) {
|
|
|
|
$('.h5p-admin-upgrade-library', $libraryRow).remove();
|
|
|
|
}
|
|
|
|
else if (library.upgradeUrl === false || library.numContent === 0) {
|
|
|
|
$('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true);
|
|
|
|
}
|
|
|
|
else {
|
2014-06-03 16:07:50 +02:00
|
|
|
$('.h5p-admin-upgrade-library', $libraryRow).attr('title', t.upgradeLibrary).click(function () {
|
|
|
|
window.location.href = library.upgradeUrl;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-26 08:43:29 +01:00
|
|
|
// Open details view when clicked
|
|
|
|
$('.h5p-admin-view-library', $libraryRow).on('click', function () {
|
|
|
|
window.location.href = library.detailsUrl;
|
|
|
|
});
|
|
|
|
|
|
|
|
var $deleteButton = $('.h5p-admin-delete-library', $libraryRow);
|
2014-08-22 11:39:45 +02:00
|
|
|
if (library.numContent !== '0' || library.numContentDependencies !== '' || library.numLibraryDependencies !== '') {
|
2014-03-26 08:43:29 +01:00
|
|
|
// Disabled delete if content.
|
2014-08-22 12:00:06 +02:00
|
|
|
$deleteButton.attr('disabled', true);
|
2014-03-26 08:43:29 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Go to delete page om click.
|
2014-08-22 12:00:06 +02:00
|
|
|
$deleteButton.attr('title', t.deleteLibrary).on('click', function () {
|
2014-03-26 08:43:29 +01:00
|
|
|
window.location.href = library.deleteUrl;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$table.append($libraryRow);
|
|
|
|
});
|
|
|
|
|
|
|
|
return $table;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize me:
|
|
|
|
$(document).ready(function () {
|
|
|
|
if (!H5PLibraryList.initialized) {
|
|
|
|
H5PLibraryList.initialized = true;
|
|
|
|
H5PLibraryList.init();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})(H5P.jQuery);
|