From 79223e6a0d7a822fa61b59efca276a0393d5f94b Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 29 Aug 2014 16:30:44 +0200 Subject: [PATCH] Adde support for restricted h5p content types. --- js/h5p-library-list.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/js/h5p-library-list.js b/js/h5p-library-list.js index a18eb93..a11e477 100644 --- a/js/h5p-library-list.js +++ b/js/h5p-library-list.js @@ -37,6 +37,7 @@ var H5PLibraryList= H5PLibraryList || {}; $.each (libraries.listData, function (index, library) { var $libraryRow = H5PUtils.createTableRow([ library.title, + '', library.numContent, library.numContentDependencies, library.numLibraryDependencies, @@ -47,6 +48,8 @@ var H5PLibraryList= H5PLibraryList || {}; ' ]); + H5PLibraryList.addRestricted($('.h5p-admin-restricted', $libraryRow), library.restrictedUrl, library.restricted); + if (library.upgradeUrl === null) { $('.h5p-admin-upgrade-library', $libraryRow).remove(); } @@ -82,6 +85,34 @@ var H5PLibraryList= H5PLibraryList || {}; 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: $(document).ready(function () {