2020-05-04 12:44:12 +02:00
|
|
|
define(['browser', 'dialogHelper', 'layoutManager', 'scrollHelper', 'globalize', 'dom', 'require', 'material-icons', 'emby-button', 'paper-icon-button-light', 'emby-input', 'formDialogStyle'], function(browser, dialogHelper, layoutManager, scrollHelper, globalize, dom, require) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-03-21 18:14:08 +01:00
|
|
|
function replaceAll(str, find, replace) {
|
|
|
|
return str.split(find).join(replace);
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function setInputProperties(dlg, options) {
|
2019-01-10 15:39:37 +03:00
|
|
|
var txtInput = dlg.querySelector('#txtInput');
|
|
|
|
|
|
|
|
if (txtInput.label) {
|
|
|
|
txtInput.label(options.label || '');
|
|
|
|
} else {
|
|
|
|
txtInput.setAttribute('label', options.label || '');
|
|
|
|
}
|
|
|
|
txtInput.value = options.value || '';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showDialog(options, template) {
|
|
|
|
var dialogOptions = {
|
2019-01-10 15:39:37 +03:00
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
dialogOptions.size = 'fullscreen';
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
dlg.classList.add('formDialog');
|
|
|
|
|
2019-02-08 07:50:23 +01:00
|
|
|
dlg.innerHTML = globalize.translateHtml(template, 'core');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
|
|
|
|
} else {
|
|
|
|
dlg.querySelector('.dialogContentInner').classList.add('dialogContentInner-mini');
|
|
|
|
dlg.classList.add('dialog-fullscreen-lowres');
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
|
|
|
|
|
|
|
dlg.querySelector('.formDialogHeaderTitle').innerHTML = options.title || '';
|
|
|
|
|
|
|
|
if (options.description) {
|
|
|
|
dlg.querySelector('.fieldDescription').innerHTML = options.description;
|
|
|
|
} else {
|
|
|
|
dlg.querySelector('.fieldDescription').classList.add('hide');
|
|
|
|
}
|
|
|
|
|
|
|
|
setInputProperties(dlg, options);
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var submitValue;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
dlg.querySelector('form').addEventListener('submit', function (e) {
|
|
|
|
|
|
|
|
submitValue = dlg.querySelector('#txtInput').value;
|
|
|
|
e.preventDefault();
|
|
|
|
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);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2019-02-03 02:41:16 +09:00
|
|
|
dlg.querySelector('.submitText').innerHTML = options.confirmText || globalize.translate('ButtonOk');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
dlg.style.minWidth = (Math.min(400, dom.getWindowSize().innerWidth - 50)) + 'px';
|
|
|
|
|
|
|
|
return dialogHelper.open(dlg).then(function () {
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
|
|
|
|
}
|
|
|
|
|
2020-03-21 18:27:30 +01:00
|
|
|
if (submitValue) {
|
|
|
|
return submitValue;
|
2019-01-10 15:39:37 +03:00
|
|
|
} else {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-21 18:14:08 +01:00
|
|
|
if ((browser.tv || browser.xboxOne) && window.confirm) {
|
|
|
|
return function (options) {
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
options = {
|
|
|
|
label: '',
|
|
|
|
text: options
|
|
|
|
};
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-21 18:14:08 +01:00
|
|
|
var label = replaceAll(options.label || '', '<br/>', '\n');
|
|
|
|
var result = prompt(label, options.text || '');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-03-21 18:14:08 +01:00
|
|
|
if (result) {
|
|
|
|
return Promise.resolve(result);
|
|
|
|
} else {
|
|
|
|
return Promise.reject(result);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return function (options) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['text!./prompt.template.html'], function (template) {
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
options = {
|
|
|
|
title: '',
|
|
|
|
text: options
|
|
|
|
};
|
|
|
|
}
|
|
|
|
showDialog(options, template).then(resolve, reject);
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-03-21 18:14:08 +01:00
|
|
|
};
|
|
|
|
}
|
2020-02-22 11:47:03 -05:00
|
|
|
});
|