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

101 lines
3.1 KiB
JavaScript
Raw Normal View History

2016-02-05 23:33:34 -07:00
define(['paperdialoghelper', 'layoutManager', 'globalize', 'dialogText', 'html!./icons.html', 'css!./style.css', 'paper-button', 'paper-input'], function (paperdialoghelper, layoutManager, globalize, dialogText) {
2016-02-04 13:51:13 -07:00
function show(options, resolve, reject) {
var dialogOptions = {
removeOnClose: true
};
2016-02-04 20:44:29 -07:00
var backButton = false;
var raisedButtons = false;
2016-02-04 13:51:13 -07:00
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
2016-02-04 20:44:29 -07:00
backButton = true;
raisedButtons = true;
2016-02-04 21:56:19 -07:00
} else {
dialogOptions.modal = false;
dialogOptions.entryAnimationDuration = 160;
dialogOptions.exitAnimationDuration = 200;
2016-02-04 13:51:13 -07:00
}
var dlg = paperdialoghelper.createDialog(dialogOptions);
dlg.classList.add('promptDialog');
var html = '';
var submitValue = '';
2016-02-04 20:44:29 -07:00
html += '<div class="promptDialogContent">';
if (backButton) {
html += '<paper-icon-button tabindex="-1" icon="dialog:arrow-back" class="btnPromptExit"></paper-icon-button>';
2016-02-04 13:51:13 -07:00
}
html += '<paper-input autoFocus class="txtPromptValue"></paper-input>';
// TODO: An actual form element should probably be added
html += '<br/>';
2016-02-04 20:44:29 -07:00
if (raisedButtons) {
2016-02-05 23:33:34 -07:00
html += '<paper-button raised class="btnSubmit"><iron-icon icon="dialog:check"></iron-icon><span>' + globalize.translate(dialogText.buttonOk) + '</span></paper-button>';
2016-02-04 20:44:29 -07:00
} else {
2016-02-05 23:33:34 -07:00
html += '<div style="text-align:right;">';
html += '<paper-button class="btnSubmit">' + globalize.translate(dialogText.buttonOk) + '</paper-button>';
html += '<paper-button class="btnPromptExit">' + globalize.translate(dialogText.buttonCancel) + '</paper-button>';
html += '</div>';
2016-02-04 20:44:29 -07:00
}
2016-02-04 13:51:13 -07:00
html += '</div>';
dlg.innerHTML = html;
if (options.text) {
dlg.querySelector('.txtPromptValue').value = options.text;
}
2016-02-04 20:44:29 -07:00
if (options.title) {
dlg.querySelector('.txtPromptValue').label = options.title;
}
2016-02-04 13:51:13 -07:00
document.body.appendChild(dlg);
2016-02-04 20:44:29 -07:00
dlg.querySelector('.btnSubmit').addEventListener('click', function (e) {
2016-02-04 13:51:13 -07:00
submitValue = dlg.querySelector('.txtPromptValue').value;
paperdialoghelper.close(dlg);
});
dlg.querySelector('.btnPromptExit').addEventListener('click', function (e) {
paperdialoghelper.close(dlg);
});
dlg.addEventListener('iron-overlay-closed', function () {
var value = submitValue;
if (value) {
resolve(value);
} else {
reject();
}
});
paperdialoghelper.open(dlg);
}
return function (options) {
return new Promise(function (resolve, reject) {
if (typeof options === 'string') {
options = {
title: '',
text: options
};
}
show(options, resolve, reject);
});
};
});