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

85 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-07-26 22:19:56 -07:00
define(['dialogHelper', 'layoutManager', 'globalize', 'require', 'paper-icon-button-light', 'emby-input', 'emby-select', 'css!./../formdialog'], function (dialogHelper, layoutManager, globalize, require) {
function centerFocus(elem, horiz, on) {
require(['scrollHelper'], function (scrollHelper) {
var fn = on ? 'on' : 'off';
scrollHelper.centerFocus[fn](elem, horiz);
});
}
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 = {
2016-07-26 22:19:56 -07:00
removeOnClose: true,
scrollY: false
2016-07-24 14:28:47 -07:00
};
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
} else {
2016-09-11 00:33:53 -07:00
dialogOptions.size = 'medium-tall';
2016-07-24 14:28:47 -07:00
}
var dlg = dialogHelper.createDialog(dialogOptions);
2016-07-24 11:25:32 -07:00
dlg.classList.add('formDialog');
var html = '';
var submitted = false;
2016-07-26 22:49:27 -07:00
html += globalize.translateDocument(template, 'sharedcomponents');
2016-07-24 11:25:32 -07:00
dlg.innerHTML = html;
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) {
2016-08-06 23:15:03 -07:00
centerFocus(dlg.querySelector('.formDialogContent'), false, true);
2016-07-24 14:28:47 -07:00
}
2016-07-24 11:25:32 -07:00
dialogHelper.open(dlg);
dlg.addEventListener('close', function () {
2016-07-26 22:19:56 -07:00
if (layoutManager.tv) {
2016-08-06 23:15:03 -07:00
centerFocus(dlg.querySelector('.formDialogContent'), false, false);
2016-07-26 22:19:56 -07:00
}
2016-07-24 11:25:32 -07:00
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 {
2016-07-26 22:49:27 -07:00
show: show
2016-07-24 11:25:32 -07:00
};
});