1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/confirm/confirm.js

133 lines
3.5 KiB
JavaScript
Raw Normal View History

2016-05-12 15:21:43 -04:00
define(['layoutManager', 'globalize'], function (layoutManager, globalize) {
2016-02-22 13:25:45 -05:00
function showTvConfirm(options) {
return new Promise(function (resolve, reject) {
require(['actionsheet'], function (actionSheet) {
var items = [];
items.push({
2016-05-12 15:21:43 -04:00
name: globalize.translate('sharedcomponents#ButtonOk'),
2016-02-22 13:25:45 -05:00
id: 'ok'
});
items.push({
2016-05-12 15:21:43 -04:00
name: globalize.translate('sharedcomponents#ButtonCancel'),
2016-02-22 13:25:45 -05:00
id: 'cancel'
});
2016-02-22 14:31:28 -05:00
actionSheet.show({
2016-02-22 13:25:45 -05:00
2016-02-22 14:31:28 -05:00
title: options.text,
2016-02-22 13:25:45 -05:00
items: items
}).then(function (id) {
switch (id) {
2016-02-22 14:31:28 -05:00
2016-02-22 13:25:45 -05:00
case 'ok':
resolve();
break;
default:
reject();
break;
}
}, reject);
});
});
}
2016-03-23 15:03:17 -04:00
function showConfirmInternal(options, dialogHelper, resolve, reject) {
2016-02-22 14:31:28 -05: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 13:46:57 -04:00
dialogOptions.exitAnimationDuration = 160;
2016-02-22 14:31:28 -05:00
dialogOptions.autoFocus = false;
}
2016-03-23 15:03:17 -04:00
var dlg = dialogHelper.createDialog(dialogOptions);
2016-02-22 14:31:28 -05:00
var html = '';
if (options.title) {
html += '<h2>' + options.title + '</h2>';
}
2016-04-09 22:27:09 -04:00
var text = options.html || options.text;
if (text) {
html += '<div>' + text + '</div>';
2016-02-22 14:31:28 -05:00
}
html += '<div class="buttons">';
2016-06-04 20:17:35 -04:00
html += '<button is="emby-button" type="button" class="btnConfirm" autofocus>' + globalize.translate('sharedcomponents#ButtonOk') + '</button>';
2016-02-22 14:31:28 -05:00
2016-06-04 20:17:35 -04:00
html += '<button is="emby-button" type="button" class="btnCancel">' + globalize.translate('sharedcomponents#ButtonCancel') + '</button>';
2016-02-22 14:31:28 -05:00
html += '</div>';
dlg.innerHTML = html;
document.body.appendChild(dlg);
2016-03-22 13:46:57 -04:00
var confirmed = false;
dlg.querySelector('.btnConfirm').addEventListener('click', function () {
confirmed = true;
2016-03-23 15:03:17 -04:00
dialogHelper.close(dlg);
2016-03-22 13:46:57 -04:00
});
dlg.querySelector('.btnCancel').addEventListener('click', function () {
confirmed = false;
2016-03-23 15:03:17 -04:00
dialogHelper.close(dlg);
2016-03-22 13:46:57 -04:00
});
2016-02-22 14:31:28 -05:00
2016-03-23 15:03:17 -04:00
dialogHelper.open(dlg).then(function () {
2016-02-22 14:31:28 -05:00
if (confirmed) {
resolve();
} else {
reject();
}
});
}
2016-02-22 13:25:45 -05:00
function showConfirm(options) {
2016-02-22 14:31:28 -05:00
return new Promise(function (resolve, reject) {
2016-02-22 13:25:45 -05:00
2016-06-04 20:17:35 -04:00
require(['dialogHelper', 'emby-button'], function (dialogHelper) {
2016-03-23 15:03:17 -04:00
showConfirmInternal(options, dialogHelper, resolve, reject);
2016-02-22 14:31:28 -05:00
});
});
2016-02-22 13:25:45 -05:00
}
2016-02-22 14:31:28 -05:00
return function (text, title) {
2016-02-22 13:25:45 -05:00
2016-02-22 14:31:28 -05:00
var options;
if (typeof text === 'string') {
2016-02-22 13:25:45 -05:00
options = {
2016-02-22 14:31:28 -05:00
title: title,
text: text
2016-02-22 13:25:45 -05:00
};
2016-02-22 14:31:28 -05:00
} else {
options = text;
2016-02-22 13:25:45 -05:00
}
if (layoutManager.tv) {
return showTvConfirm(options);
}
return showConfirm(options);
};
});