jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/dialog/dialog.js

117 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-09-08 13:32:30 -07: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-07-19 23:23:18 -07:00
function showTvDialog(options) {
return new Promise(function (resolve, reject) {
require(['actionsheet'], function (actionSheet) {
actionSheet.show({
title: options.text,
2016-08-11 13:28:49 -07:00
items: options.buttons,
timeout: options.timeout
2016-07-19 23:23:18 -07:00
}).then(resolve, reject);
});
});
}
2016-09-08 13:32:30 -07:00
function showDialog(options, template) {
2016-07-19 23:23:18 -07:00
var dialogOptions = {
2016-09-08 13:32:30 -07:00
removeOnClose: true,
scrollY: false
2016-07-19 23:23:18 -07:00
};
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
} else {
2016-09-08 13:32:30 -07:00
//dialogOptions.size = 'mini';
2016-07-19 23:23:18 -07:00
}
var dlg = dialogHelper.createDialog(dialogOptions);
2016-08-06 23:15:03 -07:00
2016-09-08 13:32:30 -07:00
dlg.classList.add('formDialog');
2016-07-19 23:23:18 -07:00
2016-09-08 13:32:30 -07:00
dlg.innerHTML = globalize.translateHtml(template, 'sharedcomponents');
2016-08-06 23:15:03 -07:00
2016-09-08 13:32:30 -07:00
if (layoutManager.tv) {
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
} else {
dlg.querySelector('.dialogContentInner').classList.add('dialogContentInner-mini');
2016-08-11 13:28:49 -07:00
}
2016-07-19 23:23:18 -07:00
2016-09-08 13:32:30 -07:00
//dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
// dialogHelper.close(dlg);
//});
2016-07-19 23:23:18 -07:00
2016-09-08 13:32:30 -07:00
dlg.querySelector('.formDialogHeaderTitle').innerHTML = options.title || '';
2016-07-19 23:23:18 -07:00
2016-09-08 13:32:30 -07:00
dlg.querySelector('.text').innerHTML = options.html || options.text || '';
2016-07-19 23:23:18 -07:00
var i, length;
2016-09-08 13:32:30 -07:00
var html = '';
2016-07-19 23:23:18 -07:00
for (i = 0, length = options.buttons.length; i < length; i++) {
var item = options.buttons[i];
var autoFocus = i == 0 ? ' autofocus' : '';
2016-09-08 23:59:23 -07:00
var buttonClass = 'btnOption raised block formDialogFooterItem';
if (item.type) {
buttonClass += ' button-' + item.type;
}
html += '<button is="emby-button" type="button" class="' + buttonClass + '" data-id="' + item.id + '"' + autoFocus + '>' + item.name + '</button>';
2016-07-19 23:23:18 -07:00
}
2016-09-08 13:32:30 -07:00
dlg.querySelector('.formDialogFooter').innerHTML = html;
2016-07-19 23:23:18 -07:00
var dialogResult;
function onButtonClick() {
dialogResult = this.getAttribute('data-id');
dialogHelper.close(dlg);
}
var buttons = dlg.querySelectorAll('.btnOption');
2016-09-08 13:32:30 -07:00
for (i = 0, length = buttons.length; i < length; i++) {
2016-07-19 23:23:18 -07:00
buttons[i].addEventListener('click', onButtonClick);
}
2016-09-08 13:32:30 -07:00
return dialogHelper.open(dlg).then(function () {
if (layoutManager.tv) {
scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false);
}
2016-07-19 23:23:18 -07:00
if (dialogResult) {
2016-09-08 13:32:30 -07:00
return dialogResult;
2016-07-19 23:23:18 -07:00
} else {
2016-09-08 13:32:30 -07:00
return Promise.reject();
2016-07-19 23:23:18 -07:00
}
});
}
return function (text, title) {
var options;
if (typeof text === 'string') {
options = {
title: title,
text: text
};
} else {
options = text;
}
if (layoutManager.tv) {
return showTvDialog(options);
}
2016-09-08 13:32:30 -07:00
return new Promise(function (resolve, reject) {
require(['text!./dialog.template.html'], function (template) {
showDialog(options, template).then(resolve, reject);
});
});
2016-07-19 23:23:18 -07:00
};
});