2016-06-09 23:54:03 -07:00
|
|
|
define(['dialogHelper', 'layoutManager', 'globalize', 'material-icons', 'css!./style.css', 'emby-button', 'paper-icon-button-light', 'emby-input'], 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' : '';
|
2016-06-09 23:54:03 -07:00
|
|
|
return '<button is="paper-icon-button-light" class="autoSize ' + cssClass + '"' + tabIndex + autoFocus + '><i class="md-icon">' + icon + '</i></button>';
|
2016-05-06 10:49:58 -07:00
|
|
|
}
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-02-22 11:25:45 -07:00
|
|
|
return function (options) {
|
|
|
|
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
options = {
|
|
|
|
title: '',
|
|
|
|
text: options
|
|
|
|
};
|
|
|
|
}
|
2016-02-04 13:51:13 -07:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
2016-02-04 13:51:13 -07:00
|
|
|
|
|
|
|
dlg.classList.add('promptDialog');
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
var submitValue = '';
|
|
|
|
|
2016-02-04 20:44:29 -07:00
|
|
|
html += '<div class="promptDialogContent">';
|
|
|
|
if (backButton) {
|
2016-06-09 23:54:03 -07:00
|
|
|
html += getIcon('arrow_back', 'btnPromptExit', false);
|
2016-02-04 13:51:13 -07:00
|
|
|
}
|
|
|
|
|
2016-02-15 07:41:07 -07:00
|
|
|
if (options.title) {
|
|
|
|
html += '<h2>';
|
|
|
|
html += options.title;
|
|
|
|
html += '</h2>';
|
|
|
|
}
|
|
|
|
|
2016-02-21 13:39:14 -07:00
|
|
|
html += '<form>';
|
|
|
|
|
2016-05-28 11:03:38 -07:00
|
|
|
html += '<div class="inputContainer">';
|
|
|
|
html += '<input is="emby-input" type="text" autoFocus class="txtPromptValue" value="' + (options.value || '') + '" label="' + (options.label || '') + '"/>';
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-02-15 07:41:07 -07:00
|
|
|
if (options.description) {
|
|
|
|
html += '<div class="fieldDescription">';
|
|
|
|
html += options.description;
|
|
|
|
html += '</div>';
|
|
|
|
}
|
2016-05-28 11:03:38 -07:00
|
|
|
html += '</div>';
|
2016-02-15 07:41:07 -07:00
|
|
|
|
2016-02-04 13:51:13 -07:00
|
|
|
html += '<br/>';
|
2016-02-04 20:44:29 -07:00
|
|
|
if (raisedButtons) {
|
2016-06-09 23:54:03 -07:00
|
|
|
html += '<button is="emby-button" type="submit" class="raised btnSubmit"><i class="md-icon">check</i><span>' + globalize.translate('sharedcomponents#ButtonOk') + '</span></button>';
|
2016-02-04 20:44:29 -07:00
|
|
|
} else {
|
2016-04-03 10:36:47 -07:00
|
|
|
html += '<div class="buttons">';
|
2016-06-04 17:17:35 -07:00
|
|
|
html += '<button is="emby-button" type="submit" class="btnSubmit">' + globalize.translate('sharedcomponents#ButtonOk') + '</button>';
|
|
|
|
html += '<button is="emby-button" type="button" class="btnPromptExit">' + globalize.translate('sharedcomponents#ButtonCancel') + '</button>';
|
2016-02-05 23:33:34 -07:00
|
|
|
html += '</div>';
|
2016-02-04 20:44:29 -07:00
|
|
|
}
|
2016-02-21 13:39:14 -07:00
|
|
|
html += '</form>';
|
2016-02-04 13:51:13 -07:00
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
|
|
|
|
document.body.appendChild(dlg);
|
|
|
|
|
2016-02-21 13:39:14 -07:00
|
|
|
dlg.querySelector('form').addEventListener('submit', function (e) {
|
2016-02-04 13:51:13 -07:00
|
|
|
|
|
|
|
submitValue = dlg.querySelector('.txtPromptValue').value;
|
2016-02-21 13:39:14 -07:00
|
|
|
e.preventDefault();
|
2016-04-03 10:36:47 -07:00
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// Important, don't close the dialog until after the form has completed submitting, or it will cause an error in Chrome
|
|
|
|
setTimeout(function () {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
}, 300);
|
|
|
|
|
2016-02-21 13:39:14 -07:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-02-04 13:51:13 -07:00
|
|
|
dlg.querySelector('.btnPromptExit').addEventListener('click', function (e) {
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
dialogHelper.close(dlg);
|
2016-02-04 13:51:13 -07:00
|
|
|
});
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
return dialogHelper.open(dlg).then(function () {
|
2016-02-04 13:51:13 -07:00
|
|
|
var value = submitValue;
|
2016-04-03 10:36:47 -07:00
|
|
|
|
2016-02-04 13:51:13 -07:00
|
|
|
if (value) {
|
2016-02-22 11:25:45 -07:00
|
|
|
return value;
|
2016-02-04 13:51:13 -07:00
|
|
|
} else {
|
2016-02-22 11:25:45 -07:00
|
|
|
return Promise.reject();
|
2016-02-04 13:51:13 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|