Adde support for restricted h5p content types.

namespaces
Frode Petterson 2014-08-29 16:30:44 +02:00
parent 67da268c44
commit 79223e6a0d
1 changed files with 31 additions and 0 deletions

View File

@ -37,6 +37,7 @@ var H5PLibraryList= H5PLibraryList || {};
$.each (libraries.listData, function (index, library) { $.each (libraries.listData, function (index, library) {
var $libraryRow = H5PUtils.createTableRow([ var $libraryRow = H5PUtils.createTableRow([
library.title, library.title,
'<input class="h5p-admin-restricted" type="checkbox"/>',
library.numContent, library.numContent,
library.numContentDependencies, library.numContentDependencies,
library.numLibraryDependencies, library.numLibraryDependencies,
@ -47,6 +48,8 @@ var H5PLibraryList= H5PLibraryList || {};
</div>' </div>'
]); ]);
H5PLibraryList.addRestricted($('.h5p-admin-restricted', $libraryRow), library.restrictedUrl, library.restricted);
if (library.upgradeUrl === null) { if (library.upgradeUrl === null) {
$('.h5p-admin-upgrade-library', $libraryRow).remove(); $('.h5p-admin-upgrade-library', $libraryRow).remove();
} }
@ -82,6 +85,34 @@ var H5PLibraryList= H5PLibraryList || {};
return $table; return $table;
}; };
H5PLibraryList.addRestricted = function ($checkbox, url, selected) {
if (selected === null) {
$checkbox.remove();
}
else {
$checkbox.change(function () {
$checkbox.attr('disabled', true);
$.ajax({
dataType: 'json',
url: url,
cache: false
}).fail(function () {
$checkbox.attr('disabled', false);
// Reset
$checkbox.attr('checked', !$checkbox.is(':checked'));
}).done(function (result) {
url = result.url;
$checkbox.attr('disabled', false);
});
});
if (selected) {
$checkbox.attr('checked', true);
}
}
};
// Initialize me: // Initialize me:
$(document).ready(function () { $(document).ready(function () {