#seConfirmDialog confirm change to elix alertdialog

master
Agriya Dev5 2020-12-28 18:29:07 +05:30
parent 22212f3096
commit dc0e7f5fc8
3 changed files with 26 additions and 12 deletions

View File

@ -4,3 +4,4 @@ import './svgSourceDialog.js';
import './cmenuDialog.js'; import './cmenuDialog.js';
import './cmenuLayersDialog.js'; import './cmenuLayersDialog.js';
import './seSelectDialog.js'; import './seSelectDialog.js';
import './seConfirmDialog.js';

View File

@ -0,0 +1,13 @@
// eslint-disable-next-line node/no-unpublished-import
import AlertDialog from 'elix/define/AlertDialog.js';
const dialog = new AlertDialog();
const seConfirm = async (text, choices) => {
dialog.textContent = text;
dialog.choices = (choices === undefined) ? ['Ok', 'Cancel'] : choices;
dialog.open();
const response = await dialog.whenClosed();
return response.choice;
};
window.seConfirm = seConfirm;

View File

@ -1289,7 +1289,7 @@ editor.init = () => {
// fired when user wants to move elements to another layer // fired when user wants to move elements to another layer
let promptMoveLayerOnce = false; let promptMoveLayerOnce = false;
$('#selLayerNames').change((evt) => { $('#selLayerNames').change( async(evt) => {
const destLayer = evt.currentTarget.options[evt.currentTarget.selectedIndex].value; const destLayer = evt.currentTarget.options[evt.currentTarget.selectedIndex].value;
const confirmStr = uiStrings.notification.QmoveElemsToLayer.replace('%s', destLayer); const confirmStr = uiStrings.notification.QmoveElemsToLayer.replace('%s', destLayer);
/** /**
@ -1307,8 +1307,8 @@ editor.init = () => {
if (promptMoveLayerOnce) { if (promptMoveLayerOnce) {
moveToLayer(true); moveToLayer(true);
} else { } else {
const ok = confirm(confirmStr); const ok = await seConfirm(confirmStr, [uiStrings.common.ok, uiStrings.common.cancel]);
if (!ok) { if (ok === uiStrings.common.cancel) {
return; return;
} }
moveToLayer(true); moveToLayer(true);
@ -1666,10 +1666,10 @@ editor.init = () => {
* @fires module:svgcanvas.SvgCanvas#event:ext_onNewDocument * @fires module:svgcanvas.SvgCanvas#event:ext_onNewDocument
* @returns {void} * @returns {void}
*/ */
const clickClear = () => { const clickClear = async() => {
const [x, y] = editor.configObj.curConfig.dimensions; const [x, y] = editor.configObj.curConfig.dimensions;
const ok = confirm(uiStrings.notification.QwantToClear); const cancel = await seConfirm(uiStrings.notification.QwantToClear, [uiStrings.common.ok, uiStrings.common.cancel]);
if (!ok) { if (cancel === uiStrings.common.cancel) {
return; return;
} }
editor.leftPanelHandlers.clickSelect(); editor.leftPanelHandlers.clickSelect();
@ -1846,7 +1846,7 @@ editor.init = () => {
* @param {Event} e * @param {Event} e
* @returns {void} Resolves to `undefined` * @returns {void} Resolves to `undefined`
*/ */
const saveSourceEditor = (e) => { const saveSourceEditor = async (e) => {
const $editorDialog = document.getElementById('se-svg-editor-dialog'); const $editorDialog = document.getElementById('se-svg-editor-dialog');
if ($editorDialog.getAttribute('dialog') !== 'open') return; if ($editorDialog.getAttribute('dialog') !== 'open') return;
const saveChanges = () => { const saveChanges = () => {
@ -1858,8 +1858,8 @@ editor.init = () => {
}; };
if (!svgCanvas.setSvgString(e.detail.value)) { if (!svgCanvas.setSvgString(e.detail.value)) {
const ok = confirm(uiStrings.notification.QerrorsRevertToSource); const resp = await seConfirm(uiStrings.notification.QerrorsRevertToSource, [uiStrings.common.ok, uiStrings.common.cancel]);
if (!ok) { if (resp === uiStrings.common.cancel) {
return; return;
} }
saveChanges(); saveChanges();
@ -1955,7 +1955,7 @@ editor.init = () => {
* @param {Event} e * @param {Event} e
* @returns {void} Resolves to `undefined` * @returns {void} Resolves to `undefined`
*/ */
const cancelOverlays = (e) => { const cancelOverlays = async (e) => {
$('#dialog_box').hide(); $('#dialog_box').hide();
const $editorDialog = document.getElementById('se-svg-editor-dialog'); const $editorDialog = document.getElementById('se-svg-editor-dialog');
const editingsource = $editorDialog.getAttribute('dialog') === 'open'; const editingsource = $editorDialog.getAttribute('dialog') === 'open';
@ -1969,8 +1969,8 @@ editor.init = () => {
if (editingsource) { if (editingsource) {
const origSource = svgCanvas.getSvgString(); const origSource = svgCanvas.getSvgString();
if (origSource !== e.detail.value) { if (origSource !== e.detail.value) {
const ok = confirm(uiStrings.notification.QignoreSourceChanges); const resp = await seConfirm(uiStrings.notification.QignoreSourceChanges, [uiStrings.common.ok, uiStrings.common.cancel]);
if (ok) { if (resp === uiStrings.common.ok) {
hideSourceEditor(); hideSourceEditor();
} }
} else { } else {