2016-09-09 19:21:00 -07:00
|
|
|
define(['dialogHelper', 'dom', 'layoutManager', 'scrollHelper', 'globalize', 'require', 'material-icons', 'emby-button', 'paper-icon-button-light', 'emby-input', 'formDialogStyle'], function (dialogHelper, dom, layoutManager, scrollHelper, globalize, require) {
|
2016-07-19 23:23:18 -07:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-09-17 22:52:10 -07:00
|
|
|
var enableTvLayout = layoutManager.tv;
|
|
|
|
|
|
|
|
if (enableTvLayout) {
|
2016-07-19 23:23:18 -07:00
|
|
|
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-17 22:52:10 -07:00
|
|
|
if (enableTvLayout) {
|
|
|
|
dlg.style['align-items'] = 'center';
|
|
|
|
dlg.style['justify-content'] = 'center';
|
|
|
|
var formDialogContent = dlg.querySelector('.formDialogContent');
|
|
|
|
formDialogContent.style['flex-grow'] = 'initial';
|
|
|
|
formDialogContent.style['max-width'] = '50%';
|
|
|
|
formDialogContent.style['max-height'] = '60%';
|
|
|
|
scrollHelper.centerFocus.on(formDialogContent, false);
|
2016-09-08 13:32:30 -07:00
|
|
|
} else {
|
2016-09-17 22:52:10 -07:00
|
|
|
var minWidth = (Math.min(options.buttons.length * 150, dom.getWindowSize().innerWidth - 50));
|
|
|
|
dlg.style.maxWidth = (minWidth + 200) + 'px';
|
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
|
|
|
|
2016-09-17 22:52:10 -07:00
|
|
|
var buttonClass = 'btnOption raised formDialogFooterItem formDialogFooterItem-autosize';
|
2016-09-08 23:59:23 -07:00
|
|
|
|
|
|
|
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 () {
|
|
|
|
|
2016-09-17 22:52:10 -07:00
|
|
|
if (enableTvLayout) {
|
2016-09-08 13:32:30 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
});
|