Made it possible to display the library list in a human readable form.

namespaces
Frode Petterson 2014-08-22 11:39:45 +02:00
parent be44d1fac9
commit 952b6e6368
3 changed files with 16 additions and 23 deletions

View File

@ -39,20 +39,6 @@ var H5PLibraryDetails= H5PLibraryDetails || {};
$libraryInfo.append(H5PUtils.createLabeledField(title, value)); $libraryInfo.append(H5PUtils.createLabeledField(title, value));
}); });
var count;
if (H5PLibraryDetails.library.notCached !== undefined) {
count = H5PIntegration.i18n.H5P.NA;
}
else if (H5PLibraryDetails.library.content === undefined) {
count = 0;
}
else {
count = H5PLibraryDetails.library.content.length;
}
// List counter:
$libraryInfo.append(H5PUtils.createLabeledField(H5PLibraryDetails.library.translations.contentCount, count));
return $libraryInfo; return $libraryInfo;
}; };

View File

@ -38,7 +38,7 @@ var H5PLibraryList= H5PLibraryList || {};
var $libraryRow = H5PUtils.createTableRow([ var $libraryRow = H5PUtils.createTableRow([
library.title, library.title,
library.numContent, library.numContent,
library.numContentDependencies === -1 ? t.NA : library.numContentDependencies, library.numContentDependencies,
library.numLibraryDependencies, library.numLibraryDependencies,
'<div class="h5p-admin-buttons-wrapper">\ '<div class="h5p-admin-buttons-wrapper">\
<button class="h5p-admin-upgrade-library"></button>\ <button class="h5p-admin-upgrade-library"></button>\
@ -62,7 +62,7 @@ var H5PLibraryList= H5PLibraryList || {};
}); });
var $deleteButton = $('.h5p-admin-delete-library', $libraryRow); var $deleteButton = $('.h5p-admin-delete-library', $libraryRow);
if (library.numContent !== 0 || library.numContentDependencies !== 0 || library.numLibraryDependencies !== 0) { if (library.numContent !== '0' || library.numContentDependencies !== '' || library.numLibraryDependencies !== '') {
// Disabled delete if content. // Disabled delete if content.
$deleteButton.attr('disabled', true).attr('title', t.deleteLibrary); $deleteButton.attr('disabled', true).attr('title', t.deleteLibrary);
} }

View File

@ -7,14 +7,20 @@ var H5PUtils = H5PUtils || {};
* @param {array} headers List of headers * @param {array} headers List of headers
*/ */
H5PUtils.createTable = function (headers) { H5PUtils.createTable = function (headers) {
var $table = $('<table class="h5p-admin-table"></table>'); var $table = $('<table class="h5p-admin-table' + (H5PIntegration.extraTableClasses !== undefined ? ' ' + H5PIntegration.extraTableClasses : '') + '"></table>');
if(headers) { if(headers) {
var $thead = $('<thead></thead>'); var $thead = $('<thead></thead>');
var $tr = $('<tr></tr>'); var $tr = $('<tr></tr>');
$.each(headers, function (index, value) { $.each(headers, function (index, value) {
$tr.append('<th>' + value + '</th>'); if (!(value instanceof Object)) {
value = {
text: value
};
}
$('<th/>', value).appendTo($tr);
}); });
$table.append($thead.append($tr)); $table.append($thead.append($tr));
@ -85,7 +91,7 @@ var H5PUtils = H5PUtils || {};
* @returns {$} * @returns {$}
*/ */
H5PUtils.getRebuildCache = function (notCached) { H5PUtils.getRebuildCache = function (notCached) {
var $container = $('<div class="h5p-admin-rebuild-cache"><p>' + notCached.message + '</p></div>'); var $container = $('<div class="h5p-admin-rebuild-cache"><p class="message">' + notCached.message + '</p><p class="progress">' + notCached.progress + '</p></div>');
var $button = $('<button>' + notCached.button + '</button>').appendTo($container).click(function () { var $button = $('<button>' + notCached.button + '</button>').appendTo($container).click(function () {
var $spinner = $('<div/>', {class: 'h5p-spinner'}).replaceAll($button); var $spinner = $('<div/>', {class: 'h5p-spinner'}).replaceAll($button);
var parts = ['|', '/', '-', '\\']; var parts = ['|', '/', '-', '\\'];
@ -96,7 +102,7 @@ var H5PUtils = H5PUtils || {};
if (current === parts.length) current = 0; if (current === parts.length) current = 0;
}, 100); }, 100);
var $counter = $container.find('.placeholder'); var $counter = $container.find('.progress');
var build = function () { var build = function () {
$.post(notCached.url, function (left) { $.post(notCached.url, function (left) {
if (left === '0') { if (left === '0') {
@ -105,8 +111,9 @@ var H5PUtils = H5PUtils || {};
location.reload(); location.reload();
} }
else { else {
var counter = $counter.text().split(' ', 2); var counter = $counter.text().split(' ');
$counter.text(left + ' ' + counter[1]); counter[0] = left;
$counter.text(counter.join(' '));
build(); build();
} }
}); });