jellyfin-web/dashboard-ui/components/metadataeditor/personeditor.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-05-07 12:25:09 -07:00
define(['dialogHelper', 'jQuery', 'paper-icon-button-light'], function (dialogHelper, $) {
2016-02-08 12:34:44 -07:00
return {
show: function (person) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'components/metadataeditor/personeditor.template.html', true);
xhr.onload = function (e) {
var template = this.response;
2016-03-23 12:03:17 -07:00
var dlg = dialogHelper.createDialog({
2016-02-08 12:34:44 -07:00
removeOnClose: true,
2016-02-09 10:13:50 -07:00
size: 'medium'
2016-02-08 12:34:44 -07:00
});
dlg.classList.add('ui-body-b');
dlg.classList.add('background-theme-b');
dlg.classList.add('formDialog');
var html = '';
var submitted = false;
2016-03-05 12:07:58 -07:00
html += Globalize.translateDocument(template);
2016-02-08 12:34:44 -07:00
dlg.innerHTML = html;
document.body.appendChild(dlg);
2016-02-09 10:13:50 -07:00
$('.txtPersonName', dlg).val(person.Name || '');
$('.selectPersonType', dlg).val(person.Type || '');
$('.txtPersonRole', dlg).val(person.Role || '');
2016-02-08 12:34:44 -07:00
2016-03-23 12:03:17 -07:00
dialogHelper.open(dlg);
2016-02-08 12:34:44 -07:00
2016-03-22 10:46:57 -07:00
dlg.addEventListener('close', function () {
2016-02-08 12:34:44 -07:00
if (submitted) {
resolve(person);
} else {
reject();
}
});
2016-02-08 13:05:55 -07:00
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
2016-03-23 12:03:17 -07:00
dialogHelper.close(dlg);
2016-02-08 13:05:55 -07:00
});
2016-02-08 12:34:44 -07:00
dlg.querySelector('form').addEventListener('submit', function (e) {
submitted = true;
2016-02-09 10:13:50 -07:00
person.Name = $('.txtPersonName', dlg).val();
person.Type = $('.selectPersonType', dlg).val();
person.Role = $('.txtPersonRole', dlg).val() || null;
2016-02-08 12:34:44 -07:00
2016-03-23 12:03:17 -07:00
dialogHelper.close(dlg);
2016-02-08 12:34:44 -07:00
e.preventDefault();
return false;
});
}
xhr.send();
});
}
};
});