1 |
efrain |
1 |
/* global H5PDisableHubData */
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Global data for disable hub functionality
|
|
|
5 |
*
|
|
|
6 |
* @typedef {object} H5PDisableHubData Data passed in from the backend
|
|
|
7 |
*
|
|
|
8 |
* @property {string} selector Selector for the disable hub check-button
|
|
|
9 |
* @property {string} overlaySelector Selector for the element that the confirmation dialog will mask
|
|
|
10 |
* @property {Array} errors Errors found with the current server setup
|
|
|
11 |
*
|
|
|
12 |
* @property {string} header Header of the confirmation dialog
|
|
|
13 |
* @property {string} confirmationDialogMsg Body of the confirmation dialog
|
|
|
14 |
* @property {string} cancelLabel Cancel label of the confirmation dialog
|
|
|
15 |
* @property {string} confirmLabel Confirm button label of the confirmation dialog
|
|
|
16 |
*
|
|
|
17 |
*/
|
|
|
18 |
/**
|
|
|
19 |
* Utility that makes it possible to force the user to confirm that he really
|
|
|
20 |
* wants to use the H5P hub without proper server settings.
|
|
|
21 |
*/
|
|
|
22 |
(function ($) {
|
|
|
23 |
|
|
|
24 |
$(document).on('ready', function () {
|
|
|
25 |
|
|
|
26 |
// No data found
|
|
|
27 |
if (!H5PDisableHubData) {
|
|
|
28 |
return;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
// No errors found, no need for confirmation dialog
|
|
|
32 |
if (!H5PDisableHubData.errors || !H5PDisableHubData.errors.length) {
|
|
|
33 |
return;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
H5PDisableHubData.selector = H5PDisableHubData.selector ||
|
|
|
37 |
'.h5p-settings-disable-hub-checkbox';
|
|
|
38 |
H5PDisableHubData.overlaySelector = H5PDisableHubData.overlaySelector ||
|
|
|
39 |
'.h5p-settings-container';
|
|
|
40 |
|
|
|
41 |
var dialogHtml = '<div>' +
|
|
|
42 |
'<p>' + H5PDisableHubData.errors.join('</p><p>') + '</p>' +
|
|
|
43 |
'<p>' + H5PDisableHubData.confirmationDialogMsg + '</p>';
|
|
|
44 |
|
|
|
45 |
// Create confirmation dialog, make sure to include translations
|
|
|
46 |
var confirmationDialog = new H5P.ConfirmationDialog({
|
|
|
47 |
headerText: H5PDisableHubData.header,
|
|
|
48 |
dialogText: dialogHtml,
|
|
|
49 |
cancelText: H5PDisableHubData.cancelLabel,
|
|
|
50 |
confirmText: H5PDisableHubData.confirmLabel
|
|
|
51 |
}).appendTo($(H5PDisableHubData.overlaySelector).get(0));
|
|
|
52 |
|
|
|
53 |
confirmationDialog.on('confirmed', function () {
|
|
|
54 |
enableButton.get(0).checked = true;
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
confirmationDialog.on('canceled', function () {
|
|
|
58 |
enableButton.get(0).checked = false;
|
|
|
59 |
});
|
|
|
60 |
|
|
|
61 |
var enableButton = $(H5PDisableHubData.selector);
|
|
|
62 |
enableButton.change(function () {
|
|
|
63 |
if ($(this).is(':checked')) {
|
|
|
64 |
confirmationDialog.show(enableButton.offset().top);
|
|
|
65 |
}
|
|
|
66 |
});
|
|
|
67 |
});
|
|
|
68 |
})(H5P.jQuery);
|