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-02-22 12:31:28 -07:00
|
|
|
function showConfirmInternal(options, paperdialoghelper, resolve, reject) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
dialogOptions.exitAnimationDuration = 200;
|
|
|
|
dialogOptions.autoFocus = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dlg = paperdialoghelper.createDialog(dialogOptions);
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
if (options.title) {
|
|
|
|
html += '<h2>' + options.title + '</h2>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.text) {
|
|
|
|
html += '<div>' + options.text + '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
html += '<div class="buttons">';
|
|
|
|
|
|
|
|
html += '<paper-button class="btnConfirm" dialog-confirm autofocus>' + dialogText.get('Ok') + '</paper-button>';
|
|
|
|
|
|
|
|
html += '<paper-button dialog-dismiss>' + dialogText.get('Cancel') + '</paper-button>';
|
|
|
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
document.body.appendChild(dlg);
|
|
|
|
|
|
|
|
paperdialoghelper.open(dlg).then(function () {
|
|
|
|
|
|
|
|
var confirmed = dlg.closingReason.confirmed;
|
|
|
|
|
|
|
|
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-02-22 12:31:28 -07:00
|
|
|
require(['paperdialoghelper', 'paper-button'], function (paperdialoghelper) {
|
|
|
|
showConfirmInternal(options, paperdialoghelper, resolve, reject);
|
|
|
|
});
|
|
|
|
});
|
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);
|
|
|
|
};
|
|
|
|
});
|