#seConfirmDialog alert change to elix alert dialog

This commit is contained in:
Agriya Dev5
2020-12-28 20:10:06 +05:30
parent dc0e7f5fc8
commit 4104372a37
10 changed files with 81 additions and 23 deletions

View File

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

View File

@@ -0,0 +1,59 @@
// eslint-disable-next-line node/no-unpublished-import
import AlertDialog from 'elix/define/AlertDialog.js';
/**
* @class SeAlertDialog
*/
export class SeAlertDialog extends HTMLElement {
/**
* @function constructor
*/
constructor () {
super();
// create the shadowDom and insert the template
this._shadowRoot = this.attachShadow({mode: 'open'});
this.dialog = new AlertDialog();
}
/**
* @function observedAttributes
* @returns {any} observed
*/
static get observedAttributes () {
return ['title'];
}
/**
* @function attributeChangedCallback
* @param {string} name
* @param {string} oldValue
* @param {string} newValue
* @returns {void}
*/
attributeChangedCallback (name, oldValue, newValue) {
switch (name) {
case 'title':
this.dialog.textContent = newValue;
this.dialog.open();
break;
default:
super.attributeChangedCallback(name, oldValue, newValue);
break;
}
}
/**
* @function get
* @returns {any}
*/
get title () {
return this.getAttribute('title');
}
/**
* @function set
* @returns {void}
*/
set title (value) {
this.setAttribute('title', value);
}
}
// Register
customElements.define('se-alert-dialog', SeAlertDialog);

View File

@@ -32,8 +32,7 @@ $('a').click(function () {
data = canvas.toDataURL(); data = canvas.toDataURL();
} catch (err) { } catch (err) {
// This fails in Firefox with `file:///` URLs :( // This fails in Firefox with `file:///` URLs :(
// Todo: This could use a generic alert library instead document.getElementById('se-alert-dialog').title = 'Data URL conversion failed: ' + err;
alert('Data URL conversion failed: ' + err); // eslint-disable-line no-alert
data = ''; data = '';
} }
post({href, data}); post({href, data});

View File

@@ -39,8 +39,7 @@ async function processResults (url) {
// console.log('json', json); // console.log('json', json);
if (!json || json.msg !== 'success') { if (!json || json.msg !== 'success') {
// Todo: This could use a generic alert library instead document.getElementById('se-alert-dialog').title = 'There was a problem downloading the results';
alert('There was a problem downloading the results'); // eslint-disable-line no-alert
return; return;
} }
const {payload, info: { const {payload, info: {

View File

@@ -202,8 +202,8 @@ export default {
}); });
} catch (e) { } catch (e) {
console.log('Failed loading MathJax.'); // eslint-disable-line no-console console.log('Failed loading MathJax.'); // eslint-disable-line no-console
// eslint-disable-next-line no-alert // eslint-disable-next-line max-len
alert('Failed loading MathJax. You will not be able to change the mathematics.'); document.getElementById('se-alert-dialog').title = 'Failed loading MathJax. You will not be able to change the mathematics.';
} }
} }
} }

View File

@@ -64,8 +64,7 @@ export default {
<input type="hidden" name="contenttype" value="application/x-svgdraw"> <input type="hidden" name="contenttype" value="application/x-svgdraw">
`).appendTo('body') `).appendTo('body')
.submit().remove(); .submit().remove();
// eslint-disable-next-line no-alert document.getElementById('se-alert-dialog').title = strings.saved;
alert(strings.saved);
top.window.location = '/' + name; top.window.location = '/' + name;
} }
}); });

View File

@@ -63,8 +63,7 @@ export default {
} */ } */
break; break;
case 'save-end': case 'save-end':
// eslint-disable-next-line no-alert document.getElementById('se-alert-dialog').title = `save complete for pathID ${pathID}!`;
alert(`save complete for pathID ${pathID}!`);
break; break;
default: default:
throw new Error('Unexpected WebAppFind event type'); throw new Error('Unexpected WebAppFind event type');

View File

@@ -156,7 +156,7 @@ class LayersPanel {
const newName = prompt(this.uiStrings.notification.enterUniqueLayerName, uniqName); const newName = prompt(this.uiStrings.notification.enterUniqueLayerName, uniqName);
if (!newName) { return; } if (!newName) { return; }
if (this.svgCanvas.getCurrentDrawing().hasLayer(newName)) { if (this.svgCanvas.getCurrentDrawing().hasLayer(newName)) {
alert(this.uiStrings.notification.dupeLayerName); document.getElementById('se-alert-dialog').title = this.uiStrings.notification.dupeLayerName;
return; return;
} }
this.svgCanvas.createLayer(newName); this.svgCanvas.createLayer(newName);
@@ -190,7 +190,7 @@ class LayersPanel {
const newName = prompt(this.uiStrings.notification.enterUniqueLayerName, name); const newName = prompt(this.uiStrings.notification.enterUniqueLayerName, name);
if (!newName) { return; } if (!newName) { return; }
if (this.svgCanvas.getCurrentDrawing().hasLayer(newName)) { if (this.svgCanvas.getCurrentDrawing().hasLayer(newName)) {
alert(this.uiStrings.notification.dupeLayerName); document.getElementById('se-alert-dialog').title = this.uiStrings.notification.dupeLayerName;
return; return;
} }
this.svgCanvas.cloneLayer(newName); this.svgCanvas.cloneLayer(newName);
@@ -235,7 +235,7 @@ class LayersPanel {
const newName = prompt(this.uiStrings.notification.enterNewLayerName, ''); const newName = prompt(this.uiStrings.notification.enterNewLayerName, '');
if (!newName) { return; } if (!newName) { return; }
if (oldName === newName || this.svgCanvas.getCurrentDrawing().hasLayer(newName)) { if (oldName === newName || this.svgCanvas.getCurrentDrawing().hasLayer(newName)) {
alert(this.uiStrings.notification.layerHasThatName); document.getElementById('se-alert-dialog').title = this.uiStrings.notification.layerHasThatName;
return; return;
} }
this.svgCanvas.renameCurrentLayer(newName); this.svgCanvas.renameCurrentLayer(newName);

View File

@@ -403,8 +403,7 @@ class TopPanelHandlers {
if (!valid) { if (!valid) {
e.target.value = this.selectedElement().getAttribute(attr); e.target.value = this.selectedElement().getAttribute(attr);
// eslint-disable-next-line no-alert document.getElementById('se-alert-dialog').title = this.uiStrings.notification.invalidAttrValGiven;
alert(this.uiStrings.notification.invalidAttrValGiven);
return false; return false;
} }

View File

@@ -222,6 +222,10 @@ editor.init = () => {
const dialogBox = document.createElement('se-cmenu_canvas-dialog'); const dialogBox = document.createElement('se-cmenu_canvas-dialog');
dialogBox.setAttribute('id', 'se-cmenu_canvas'); dialogBox.setAttribute('id', 'se-cmenu_canvas');
document.body.append(dialogBox); document.body.append(dialogBox);
// alertDialog added to DOM
const alertBox = document.createElement('se-alert-dialog');
alertBox.setAttribute('id', 'se-alert-dialog');
document.body.append(alertBox);
} catch (err) {} } catch (err) {}
editor.configObj.load(); editor.configObj.load();
@@ -436,7 +440,6 @@ editor.init = () => {
// Alert will only appear the first time saved OR the // Alert will only appear the first time saved OR the
// first time the bug is encountered // first time the bug is encountered
let done = editor.pref('save_notice_done'); let done = editor.pref('save_notice_done');
if (done !== 'all') { if (done !== 'all') {
let note = uiStrings.notification.saveFromBrowser.replace('%s', 'SVG'); let note = uiStrings.notification.saveFromBrowser.replace('%s', 'SVG');
// Check if FF and has <defs/> // Check if FF and has <defs/>
@@ -453,7 +456,7 @@ editor.init = () => {
editor.pref('save_notice_done', 'all'); editor.pref('save_notice_done', 'all');
} }
if (done !== 'part') { if (done !== 'part') {
alert(note); document.getElementById('se-alert-dialog').title = note;
} }
} }
}; };
@@ -470,7 +473,7 @@ editor.init = () => {
exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one exportWindow = window.open(blankPageObjectURL || '', exportWindowName); // A hack to get the window via JSON-able name without opening a new one
if (!exportWindow || exportWindow.closed) { if (!exportWindow || exportWindow.closed) {
alert(uiStrings.notification.popupWindowBlocked); document.getElementById('se-alert-dialog').title = uiStrings.notification.popupWindowBlocked;
return; return;
} }
@@ -1901,15 +1904,15 @@ editor.init = () => {
svgCanvas.setDocumentTitle(title); svgCanvas.setDocumentTitle(title);
if (w !== 'fit' && !isValidUnit('width', w)) { if (w !== 'fit' && !isValidUnit('width', w)) {
alert(uiStrings.notification.invalidAttrValGiven); document.getElementById('se-alert-dialog').title = uiStrings.notification.invalidAttrValGiven;
return false; return false;
} }
if (h !== 'fit' && !isValidUnit('height', h)) { if (h !== 'fit' && !isValidUnit('height', h)) {
alert(uiStrings.notification.invalidAttrValGiven); document.getElementById('se-alert-dialog').title = uiStrings.notification.invalidAttrValGiven;
return false; return false;
} }
if (!svgCanvas.setResolution(w, h)) { if (!svgCanvas.setResolution(w, h)) {
alert(uiStrings.notification.noContentToFitTo); document.getElementById('se-alert-dialog').title = uiStrings.notification.noContentToFitTo;
return false; return false;
} }
// Set image save option // Set image save option
@@ -2000,7 +2003,7 @@ editor.init = () => {
}); });
$('#url_notice').click(() => { $('#url_notice').click(() => {
alert(this.title); document.getElementById('se-alert-dialog').title = this.title;
}); });
$('#stroke_width').val(editor.configObj.curConfig.initStroke.width); $('#stroke_width').val(editor.configObj.curConfig.initStroke.width);
@@ -2702,7 +2705,7 @@ editor.loadFromURL = function (url, {cache, noAlert} = {}) {
reject(new Error('URLLoadFail')); reject(new Error('URLLoadFail'));
return; return;
} }
alert(uiStrings.notification.URLLoadFail + ': \n' + err); document.getElementById('se-alert-dialog').title = uiStrings.notification.URLLoadFail + ': \n' + err;
resolve(); resolve();
}, },
complete () { complete () {