2016-09-07 23:15:44 -07:00
|
|
|
define(['dialogHelper', 'layoutManager', 'scrollHelper', 'globalize', 'require', 'material-icons', 'emby-button', 'paper-icon-button-light', 'emby-input', 'emby-input', 'formDialogStyle'], function (dialogHelper, layoutManager, scrollHelper, globalize, require) {
|
2016-05-06 10:49:58 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
function setInputProperties(dlg, options) {
|
|
|
|
var txtInput = dlg.querySelector('#txtInput');
|
|
|
|
txtInput.value = options.value || '';
|
|
|
|
txtInput.label(options.label || '');
|
2016-05-06 10:49:58 -07:00
|
|
|
}
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
function showPrompt(options, template) {
|
2016-02-04 13:51:13 -07:00
|
|
|
|
|
|
|
var dialogOptions = {
|
2016-09-07 23:15:44 -07:00
|
|
|
removeOnClose: true,
|
|
|
|
scrollY: false
|
2016-02-04 13:51:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
dialogOptions.size = 'fullscreen';
|
2016-02-04 21:56:19 -07:00
|
|
|
} else {
|
2016-09-07 23:15:44 -07:00
|
|
|
dialogOptions.size = 'mini';
|
2016-02-04 13:51:13 -07:00
|
|
|
}
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
dlg.classList.add('formDialog');
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
dlg.innerHTML = globalize.translateHtml(template, 'sharedcomponents');
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false);
|
2016-02-04 13:51:13 -07:00
|
|
|
}
|
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function (e) {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
|
|
|
|
2016-09-07 23:41:49 -07:00
|
|
|
dlg.querySelector('.dialogContentTitle').innerHTML = options.title || '';
|
2016-02-15 07:41:07 -07:00
|
|
|
|
|
|
|
if (options.description) {
|
2016-09-07 23:15:44 -07:00
|
|
|
dlg.querySelector('.fieldDescription').innerHTML = options.description;
|
2016-02-04 20:44:29 -07:00
|
|
|
} else {
|
2016-09-07 23:15:44 -07:00
|
|
|
dlg.querySelector('.fieldDescription').classList.add('hide');
|
2016-02-04 20:44:29 -07:00
|
|
|
}
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
setInputProperties(dlg, options);
|
2016-02-04 13:51:13 -07:00
|
|
|
|
|
|
|
document.body.appendChild(dlg);
|
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
var submitValue;
|
|
|
|
|
2016-02-21 13:39:14 -07:00
|
|
|
dlg.querySelector('form').addEventListener('submit', function (e) {
|
2016-02-04 13:51:13 -07:00
|
|
|
|
2016-09-07 23:15:44 -07:00
|
|
|
submitValue = dlg.querySelector('#txtInput').value;
|
2016-02-21 13:39:14 -07:00
|
|
|
e.preventDefault();
|
2016-04-03 10:36:47 -07:00
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
// Important, don't close the dialog until after the form has completed submitting, or it will cause an error in Chrome
|
|
|
|
setTimeout(function () {
|
|
|
|
dialogHelper.close(dlg);
|
|
|
|
}, 300);
|
|
|
|
|
2016-02-21 13:39:14 -07:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2016-03-23 12:03:17 -07:00
|
|
|
return dialogHelper.open(dlg).then(function () {
|
2016-02-04 13:51:13 -07:00
|
|
|
var value = submitValue;
|
2016-04-03 10:36:47 -07:00
|
|
|
|
2016-02-04 13:51:13 -07:00
|
|
|
if (value) {
|
2016-02-22 11:25:45 -07:00
|
|
|
return value;
|
2016-02-04 13:51:13 -07:00
|
|
|
} else {
|
2016-02-22 11:25:45 -07:00
|
|
|
return Promise.reject();
|
2016-02-04 13:51:13 -07:00
|
|
|
}
|
|
|
|
});
|
2016-09-07 23:15:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return function (options) {
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
require(['text!./prompt.template.html'], function (template) {
|
|
|
|
|
|
|
|
if (typeof options === 'string') {
|
|
|
|
options = {
|
|
|
|
title: '',
|
|
|
|
text: options
|
|
|
|
};
|
|
|
|
}
|
|
|
|
showPrompt(options, template).then(resolve, reject);
|
|
|
|
});
|
|
|
|
});
|
2016-02-04 13:51:13 -07:00
|
|
|
};
|
|
|
|
});
|