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

133 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-02-22 11:25:45 -07:00
define(['layoutManager', 'dialogText'], function (layoutManager, dialogText) {
function showTvConfirm(options) {
return new Promise(function (resolve, reject) {
require(['actionsheet'], function (actionSheet) {
var items = [];
items.push({
name: dialogText.get('Ok'),
id: 'ok'
});
items.push({
name: dialogText.get('Cancel'),
id: 'cancel'
});
2016-02-22 12:31:28 -07:00
actionSheet.show({
2016-02-22 11:25:45 -07:00
2016-02-22 12:31:28 -07:00
title: options.text,
2016-02-22 11:25:45 -07:00
items: items
}).then(function (id) {
switch (id) {
2016-02-22 12:31:28 -07:00
2016-02-22 11:25:45 -07:00
case 'ok':
resolve();
break;
default:
reject();
break;
}
}, reject);
});
});
}
2016-03-23 12:03:17 -07:00
function showConfirmInternal(options, dialogHelper, resolve, reject) {
2016-02-22 12:31:28 -07:00
var dialogOptions = {
removeOnClose: true
};
var backButton = false;
if (layoutManager.tv) {
dialogOptions.size = 'fullscreen';
backButton = true;
dialogOptions.autoFocus = true;
} else {
dialogOptions.modal = false;
dialogOptions.entryAnimationDuration = 160;
2016-03-22 10:46:57 -07:00
dialogOptions.exitAnimationDuration = 160;
2016-02-22 12:31:28 -07:00
dialogOptions.autoFocus = false;
}
2016-03-23 12:03:17 -07:00
var dlg = dialogHelper.createDialog(dialogOptions);
2016-02-22 12:31:28 -07:00
var html = '';
if (options.title) {
html += '<h2>' + options.title + '</h2>';
}
2016-04-09 19:27:09 -07:00
var text = options.html || options.text;
if (text) {
html += '<div>' + text + '</div>';
2016-02-22 12:31:28 -07:00
}
html += '<div class="buttons">';
2016-03-22 10:46:57 -07:00
html += '<paper-button class="btnConfirm" autofocus>' + dialogText.get('Ok') + '</paper-button>';
2016-02-22 12:31:28 -07:00
2016-03-22 10:46:57 -07:00
html += '<paper-button class="btnCancel">' + dialogText.get('Cancel') + '</paper-button>';
2016-02-22 12:31:28 -07:00
html += '</div>';
dlg.innerHTML = html;
document.body.appendChild(dlg);
2016-03-22 10:46:57 -07:00
var confirmed = false;
dlg.querySelector('.btnConfirm').addEventListener('click', function () {
confirmed = true;
2016-03-23 12:03:17 -07:00
dialogHelper.close(dlg);
2016-03-22 10:46:57 -07:00
});
dlg.querySelector('.btnCancel').addEventListener('click', function () {
confirmed = false;
2016-03-23 12:03:17 -07:00
dialogHelper.close(dlg);
2016-03-22 10:46:57 -07:00
});
2016-02-22 12:31:28 -07:00
2016-03-23 12:03:17 -07:00
dialogHelper.open(dlg).then(function () {
2016-02-22 12:31:28 -07:00
if (confirmed) {
resolve();
} else {
reject();
}
});
}
2016-02-22 11:25:45 -07:00
function showConfirm(options) {
2016-02-22 12:31:28 -07:00
return new Promise(function (resolve, reject) {
2016-02-22 11:25:45 -07:00
2016-03-23 12:03:17 -07:00
require(['dialogHelper', 'paper-button'], function (dialogHelper) {
showConfirmInternal(options, dialogHelper, resolve, reject);
2016-02-22 12:31:28 -07:00
});
});
2016-02-22 11:25:45 -07:00
}
2016-02-22 12:31:28 -07:00
return function (text, title) {
2016-02-22 11:25:45 -07:00
2016-02-22 12:31:28 -07:00
var options;
if (typeof text === 'string') {
2016-02-22 11:25:45 -07:00
options = {
2016-02-22 12:31:28 -07:00
title: title,
text: text
2016-02-22 11:25:45 -07:00
};
2016-02-22 12:31:28 -07:00
} else {
options = text;
2016-02-22 11:25:45 -07:00
}
if (layoutManager.tv) {
return showTvConfirm(options);
}
return showConfirm(options);
};
});