jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/alert/alert.js

95 lines
2.9 KiB
JavaScript
Raw Normal View History

2016-06-04 17:17:35 -07:00
define(['dialogHelper', 'layoutManager', 'globalize', 'html!./../icons/nav.html', 'css!./../prompt/style.css', 'emby-button', 'paper-icon-button-light'], function (dialogHelper, layoutManager, globalize) {
2016-05-06 10:49:58 -07:00
function getIcon(icon, cssClass, canFocus, autoFocus) {
var tabIndex = canFocus ? '' : ' tabindex="-1"';
autoFocus = autoFocus ? ' autofocus' : '';
return '<button is="paper-icon-button-light" class="' + cssClass + '"' + tabIndex + autoFocus + '><iron-icon icon="' + icon + '"></iron-icon></button>';
}
2016-02-26 13:29:27 -07:00
return function (options) {
if (typeof options === 'string') {
options = {
title: '',
text: options
};
}
var dialogOptions = {
removeOnClose: true
};
var backButton = false;
var raisedButtons = false;
2016-04-19 19:28:51 -07:00
var isFullscreen = false;
2016-02-26 13:29:27 -07:00
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
backButton = true;
raisedButtons = true;
2016-04-19 19:28:51 -07:00
isFullscreen = true;
2016-02-26 13:29:27 -07:00
} else {
dialogOptions.modal = false;
dialogOptions.entryAnimationDuration = 160;
dialogOptions.exitAnimationDuration = 200;
}
2016-03-23 12:03:17 -07:00
var dlg = dialogHelper.createDialog(dialogOptions);
2016-02-26 13:29:27 -07:00
dlg.classList.add('promptDialog');
var html = '';
html += '<div class="promptDialogContent">';
if (backButton) {
2016-05-06 10:49:58 -07:00
html += getIcon('dialog:arrow-back', 'btnPromptExit', false);
2016-02-26 13:29:27 -07:00
}
if (options.title) {
html += '<h2>';
html += options.title;
html += '</h2>';
2016-04-19 19:28:51 -07:00
} else if (!isFullscreen) {
// Add a little space so it's not hugging the border
html += '<br/>';
2016-02-26 13:29:27 -07:00
}
2016-04-09 19:27:09 -07:00
var text = options.html || options.text;
if (text) {
2016-02-26 13:29:27 -07:00
if (options.title) {
html += '<p style="margin-top:2em;">';
} else {
html += '<p>';
}
2016-04-09 19:27:09 -07:00
html += text;
2016-02-26 13:29:27 -07:00
html += '</p>';
}
2016-05-12 12:21:43 -07:00
var buttonText = options.type == 'error' ? 'sharedcomponents#ButtonOk' : 'sharedcomponents#ButtonGotIt';
2016-02-26 13:29:27 -07:00
if (raisedButtons) {
2016-06-04 17:17:35 -07:00
html += '<button is="emby-button" type="button" class="raised btnSubmit"><iron-icon icon="nav:check"></iron-icon><span>' + globalize.translate(buttonText) + '</span></button>';
2016-02-26 13:29:27 -07:00
} else {
2016-04-17 22:58:08 -07:00
html += '<div class="buttons" style="text-align:right;">';
2016-06-04 17:17:35 -07:00
html += '<button is="emby-button" type="button" class="btnSubmit">' + globalize.translate(buttonText) + '</button>';
2016-02-26 13:29:27 -07:00
html += '</div>';
}
html += '</div>';
dlg.innerHTML = html;
document.body.appendChild(dlg);
dlg.querySelector('.btnSubmit').addEventListener('click', function (e) {
2016-03-23 12:03:17 -07:00
dialogHelper.close(dlg);
2016-02-26 13:29:27 -07:00
});
2016-03-23 12:03:17 -07:00
return dialogHelper.open(dlg);
2016-02-26 13:29:27 -07:00
};
});