2016-09-08 16:32:30 -04:00
|
|
|
define(['dialogHelper', 'layoutManager', 'scrollHelper', 'globalize', 'require', 'material-icons', 'emby-button', 'paper-icon-button-light', 'emby-input', 'formDialogStyle'], function (dialogHelper, layoutManager, scrollHelper, globalize, require) {
|
2016-05-06 13:49:58 -04:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
function setInputProperties(dlg, options) {
|
|
|
|
var txtInput = dlg.querySelector('#txtInput');
|
|
|
|
txtInput.value = options.value || '';
|
|
|
|
txtInput.label(options.label || '');
|
2016-05-06 13:49:58 -04:00
|
|
|
}
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 16:32:30 -04:00
|
|
|
function showDialog(options, template) {
|
2016-02-04 15:51:13 -05:00
|
|
|
|
|
|
|
var dialogOptions = {
|
2016-09-08 02:15:44 -04:00
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
2016-02-04 15:51:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
dialogOptions.size = 'fullscreen';
|
2016-02-04 23:56:19 -05:00
|
|
|
} else {
|
2016-09-08 16:32:30 -04:00
|
|
|
//dialogOptions.size = 'mini';
|
2016-02-04 15:51:13 -05:00
|
|
|
}
|
|
|
|
|
2016-03-23 15:03:17 -04:00
|
|
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
dlg.classList.add('formDialog');
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
dlg.innerHTML = globalize.translateHtml(template, 'sharedcomponents');
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
|
2016-09-08 16:32:30 -04:00
|
|
|
} else {
|
|
|
|
dlg.querySelector('.dialogContentInner').classList.add('dialogContentInner-mini');
|
2016-02-04 15:51:13 -05:00
|
|
|
}
|
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
|
|
|
|
2016-09-08 02:41:49 -04:00
|
|
|
dlg.querySelector('.dialogContentTitle').innerHTML = options.title || '';
|
2016-02-15 09:41:07 -05:00
|
|
|
|
|
|
|
if (options.description) {
|
2016-09-08 02:15:44 -04:00
|
|
|
dlg.querySelector('.fieldDescription').innerHTML = options.description;
|
2016-02-04 22:44:29 -05:00
|
|
|
} else {
|
2016-09-08 02:15:44 -04:00
|
|
|
dlg.querySelector('.fieldDescription').classList.add('hide');
|
2016-02-04 22:44:29 -05:00
|
|
|
}
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
setInputProperties(dlg, options);
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
var submitValue;
|
|
|
|
|
2016-02-21 15:39:14 -05:00
|
|
|
dlg.querySelector('form').addEventListener('submit', function (e) {
|
2016-02-04 15:51:13 -05:00
|
|
|
|
2016-09-08 02:15:44 -04:00
|
|
|
submitValue = dlg.querySelector('#txtInput').value;
|
2016-02-21 15:39:14 -05:00
|
|
|
e.preventDefault();
|
2016-04-03 13:36:47 -04: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 15:39:14 -05:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-03-23 15:03:17 -04:00
|
|
|
return dialogHelper.open(dlg).then(function () {
|
2016-09-08 16:32:30 -04:00
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
|
|
|
|
}
|
|
|
|
|
2016-02-04 15:51:13 -05:00
|
|
|
var value = submitValue;
|
2016-04-03 13:36:47 -04:00
|
|
|
|
2016-02-04 15:51:13 -05:00
|
|
|
if (value) {
|
2016-02-22 13:25:45 -05:00
|
|
|
return value;
|
2016-02-04 15:51:13 -05:00
|
|
|
} else {
|
2016-02-22 13:25:45 -05:00
|
|
|
return Promise.reject();
|
2016-02-04 15:51:13 -05:00
|
|
|
}
|
|
|
|
});
|
2016-09-08 02:15:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return function (options) {
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['text!./prompt.template.html'], function (template) {
|
|
|
|
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
options = {
|
|
|
|
title: '',
|
|
|
|
text: options
|
|
|
|
};
|
|
|
|
}
|
2016-09-08 16:32:30 -04:00
|
|
|
showDialog(options, template).then(resolve, reject);
|
2016-09-08 02:15:44 -04:00
|
|
|
});
|
|
|
|
});
|
2016-02-04 15:51:13 -05:00
|
|
|
};
|
|
|
|
});
|