jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/metadataeditor/personeditor.js

77 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-07-24 14:28:47 -07:00
define(['dialogHelper', 'layoutManager', 'scrollHelper', 'globalize', 'require', 'paper-icon-button-light', 'emby-input', 'emby-select', 'css!./../formdialog'], function (dialogHelper, layoutManager, scrollHelper, globalize, require) {
2016-07-24 11:25:32 -07:00
function show(person) {
return new Promise(function (resolve, reject) {
require(['text!./personeditor.template.html'], function (template) {
2016-07-24 14:28:47 -07:00
var dialogOptions = {
removeOnClose: true
};
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
} else {
dialogOptions.size = 'medium';
}
var dlg = dialogHelper.createDialog(dialogOptions);
2016-07-24 11:25:32 -07:00
dlg.classList.add('ui-body-b');
dlg.classList.add('background-theme-b');
dlg.classList.add('formDialog');
var html = '';
var submitted = false;
html += globalize.translateDocument(template);
dlg.innerHTML = html;
document.body.appendChild(dlg);
dlg.querySelector('.txtPersonName', dlg).value = person.Name || '';
dlg.querySelector('.selectPersonType', dlg).value = person.Type || '';
dlg.querySelector('.txtPersonRole', dlg).value = person.Role || '';
2016-07-24 14:28:47 -07:00
if (layoutManager.tv) {
scrollHelper.centerFocus.on(dlg.querySelector('.dialogContent'), false);
}
2016-07-24 11:25:32 -07:00
dialogHelper.open(dlg);
dlg.addEventListener('close', function () {
if (submitted) {
resolve(person);
} else {
reject();
}
});
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
dialogHelper.close(dlg);
});
dlg.querySelector('form').addEventListener('submit', function (e) {
submitted = true;
person.Name = dlg.querySelector('.txtPersonName', dlg).value;
person.Type = dlg.querySelector('.selectPersonType', dlg).value;
person.Role = dlg.querySelector('.txtPersonRole', dlg).value || null;
dialogHelper.close(dlg);
e.preventDefault();
return false;
});
});
});
}
return {
show: show
};
});