custom alert, prompt, confirm based on modal dialog
This commit is contained in:
parent
f2d862df1e
commit
317aec919b
6 changed files with 163 additions and 48 deletions
|
|
@ -289,9 +289,9 @@
|
||||||
API.help.show();
|
API.help.show();
|
||||||
break;
|
break;
|
||||||
case cca('Z'): // reset stored state
|
case cca('Z'): // reset stored state
|
||||||
if (confirm('clear all settings?')) {
|
UC.confirm('clear all settings and preferences?').then(yes => {
|
||||||
SDB.clear();
|
if (yes) SDB.clear();
|
||||||
}
|
});
|
||||||
break;
|
break;
|
||||||
case cca('C'): // refresh catalog
|
case cca('C'): // refresh catalog
|
||||||
CATALOG.refresh();
|
CATALOG.refresh();
|
||||||
|
|
@ -303,7 +303,9 @@
|
||||||
storeSettingsToServer(true);
|
storeSettingsToServer(true);
|
||||||
break;
|
break;
|
||||||
case cca('u'): // full settings url
|
case cca('u'): // full settings url
|
||||||
loadSettingsFromServer(prompt("settings id to load"));
|
UC.prompt("settings id to load", "").then(id => {
|
||||||
|
if (id) loadSettingsFromServer(id);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case cca('s'): // complete slice
|
case cca('s'): // complete slice
|
||||||
API.function.slice();
|
API.function.slice();
|
||||||
|
|
@ -460,7 +462,9 @@
|
||||||
let res = JSON.parse(reply);
|
let res = JSON.parse(reply);
|
||||||
if (res && res.ver) {
|
if (res && res.ver) {
|
||||||
LOC.hash = res.space + "/" + res.ver;
|
LOC.hash = res.space + "/" + res.ver;
|
||||||
if (display) alert("unique settings id is: " + res.space + "/" + res.ver);
|
if (display) {
|
||||||
|
UC.alert(`unique settings id is: <b>${res.space}/${res.ver}</b>`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updateSpaceState();
|
updateSpaceState();
|
||||||
|
|
@ -469,13 +473,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function profileExport() {
|
function profileExport() {
|
||||||
let name = WIN.prompt("Export Profile Filename", "kiriconf");
|
UC.prompt("Export Profile Filename", "kiriconf").then(name => {
|
||||||
if (!name) return;
|
if (name) {
|
||||||
let json = API.conf.export(),
|
let json = API.conf.export(),
|
||||||
blob = new Blob([json], {type: "octet/stream"}),
|
blob = new Blob([json], {type: "octet/stream"}),
|
||||||
url = WIN.URL.createObjectURL(blob);
|
url = WIN.URL.createObjectURL(blob);
|
||||||
$('mod-any').innerHTML = `<a id="sexport" href="${url}" download="${name}.b64">x</a>`;
|
$('mod-any').innerHTML = `<a id="sexport" href="${url}" download="${name}.b64">x</a>`;
|
||||||
$('sexport').click();
|
$('sexport').click();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function settingsSave(ev) {
|
function settingsSave(ev) {
|
||||||
|
|
@ -483,25 +489,27 @@
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
API.dialog.hide();
|
API.dialog.hide();
|
||||||
let mode = API.mode.get(),
|
let mode = API.mode.get(),
|
||||||
s = settings(),
|
s = settings(),
|
||||||
def = "default",
|
def = "default",
|
||||||
cp = s.process,
|
cp = s.process,
|
||||||
pl = s.sproc[mode],
|
pl = s.sproc[mode];
|
||||||
// pt = sf[mode.toLowerCase()].p, // process field mask
|
|
||||||
name = WIN.prompt("Save Settings As", cp ? cp.processName || def : def);
|
UC.prompt("Save Settings As", cp ? cp.processName || def : def).then(name => {
|
||||||
if (!name) return;
|
if (name) {
|
||||||
let np = pl[name] = {};
|
let np = pl[name] = {};
|
||||||
cp.processName = name;
|
cp.processName = name;
|
||||||
for (let k in cp) {
|
for (let k in cp) {
|
||||||
if (!cp.hasOwnProperty(k)) continue;
|
if (!cp.hasOwnProperty(k)) continue;
|
||||||
// if (!pt.hasOwnProperty(k)) continue; // mask out invalid fields
|
np[k] = cp[k];
|
||||||
np[k] = cp[k];
|
}
|
||||||
}
|
s.cproc[API.mode.get()] = name;
|
||||||
s.cproc[API.mode.get()] = name;
|
API.conf.save();
|
||||||
API.conf.save();
|
API.event.settings();
|
||||||
API.event.settings();
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function settingsLoad() {
|
function settingsLoad() {
|
||||||
|
|
@ -996,11 +1004,25 @@
|
||||||
|
|
||||||
SPACE.platform.setColor(platformColor);
|
SPACE.platform.setColor(platformColor);
|
||||||
|
|
||||||
let files = evt.dataTransfer.files,
|
let files = evt.dataTransfer.files;
|
||||||
plate = files.length < 5 || confirm(`add ${files.length} objects to workspace?`),
|
|
||||||
group = files.length < 2 ? undefined : confirm('group files?') ? [] : undefined;
|
|
||||||
|
|
||||||
if (plate) API.platform.load_files(files,group);
|
function ck_group() {
|
||||||
|
if (files.length === 1) {
|
||||||
|
API.platform.load_files(files);
|
||||||
|
} else {
|
||||||
|
UC.confirm(`group ${files.length} files?`).then(yes => {
|
||||||
|
API.platform.load_files(files, yes ? [] : undefined);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.length > 5) {
|
||||||
|
UC.confirm(`add ${files.length} objects to workspace?`).then(yes => {
|
||||||
|
if (yes) ck_group();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ck_group();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadCatalogFile(e) {
|
function loadCatalogFile(e) {
|
||||||
|
|
@ -1504,7 +1526,7 @@
|
||||||
API.var.layer_hi = Math.round((1 - start) * API.var.layer_max);
|
API.var.layer_hi = Math.round((1 - start) * API.var.layer_max);
|
||||||
API.var.layer_lo = Math.round((1 - end) * API.var.layer_max);
|
API.var.layer_lo = Math.round((1 - end) * API.var.layer_max);
|
||||||
API.show.layer();
|
API.show.layer();
|
||||||
SPACE.mouse.active();
|
SPACE.scene.active();
|
||||||
}
|
}
|
||||||
|
|
||||||
function dragit(el, delta) {
|
function dragit(el, delta) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@
|
||||||
|
|
||||||
let shift = Math.tan(hA - Math.PI * .5);
|
let shift = Math.tan(hA - Math.PI * .5);
|
||||||
let shiftMatrix = new THREE.Matrix4().set(
|
let shiftMatrix = new THREE.Matrix4().set(
|
||||||
1, 0, 0, 0, -shift, 1, 0, 0,
|
1, 0, 0, 0,
|
||||||
|
-shift, 1, 0, 0,
|
||||||
0, 0, 1, 0,
|
0, 0, 1, 0,
|
||||||
0, 0, 0, 1
|
0, 0, 0, 1
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -683,7 +683,9 @@
|
||||||
clearPrint();
|
clearPrint();
|
||||||
API.conf.save();
|
API.conf.save();
|
||||||
|
|
||||||
if (MODE === MODES.CAM) {
|
let isCam = MODE === MODES.CAM;
|
||||||
|
|
||||||
|
if (isCam) {
|
||||||
setOpacity(color.cam_preview_opacity);
|
setOpacity(color.cam_preview_opacity);
|
||||||
forAllWidgets(function(widget) {
|
forAllWidgets(function(widget) {
|
||||||
widget.setColor(color.cam_preview);
|
widget.setColor(color.cam_preview);
|
||||||
|
|
@ -701,7 +703,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
setOpacity(0);
|
if (!isCam) setOpacity(0);
|
||||||
|
|
||||||
currentPrint.render();
|
currentPrint.render();
|
||||||
|
|
||||||
|
|
@ -778,6 +780,7 @@
|
||||||
preserveLayer = API.var.layer_hi,
|
preserveLayer = API.var.layer_hi,
|
||||||
totalProgress,
|
totalProgress,
|
||||||
track = {},
|
track = {},
|
||||||
|
mode = settings.mode,
|
||||||
now = UTIL.time();
|
now = UTIL.time();
|
||||||
|
|
||||||
// require topo be sent back from worker for local printing
|
// require topo be sent back from worker for local printing
|
||||||
|
|
@ -791,7 +794,8 @@
|
||||||
segNumber = 0,
|
segNumber = 0,
|
||||||
errored = false,
|
errored = false,
|
||||||
startTime,
|
startTime,
|
||||||
lastMsg;
|
lastMsg,
|
||||||
|
camOrLaser = mode === 'CAM' || mode === 'LASER';
|
||||||
|
|
||||||
widget.stats.progress = 0;
|
widget.stats.progress = 0;
|
||||||
widget.setColor(color.slicing);
|
widget.setColor(color.slicing);
|
||||||
|
|
@ -801,7 +805,7 @@
|
||||||
widget.render();
|
widget.render();
|
||||||
// clear wireframe
|
// clear wireframe
|
||||||
widget.setWireframe(false, color.wireframe, color.wireframe_opacity);
|
widget.setWireframe(false, color.wireframe, color.wireframe_opacity);
|
||||||
widget.setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
|
widget.setOpacity(camOrLaser ? color.cam_sliced_opacity : color.sliced_opacity);
|
||||||
widget.setColor(color.deselected);
|
widget.setColor(color.deselected);
|
||||||
// update UI info
|
// update UI info
|
||||||
if (sliced) {
|
if (sliced) {
|
||||||
|
|
@ -820,7 +824,7 @@
|
||||||
if (--countdown === 0 || error || errored) {
|
if (--countdown === 0 || error || errored) {
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
showSlices(preserveLayer);
|
showSlices(preserveLayer);
|
||||||
setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
|
SPACE.scene.active();
|
||||||
if (callback && typeof callback === 'function') {
|
if (callback && typeof callback === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
@ -1483,22 +1487,28 @@
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(atob(data));
|
data = JSON.parse(atob(data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('invalid settings format');
|
UC.alert('invalid settings format');
|
||||||
console.log('data',data);
|
console.log('data',data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(data.settings && data.version && data.time)) {
|
if (!(data.settings && data.version && data.time)) {
|
||||||
alert('invalid settings format');
|
UC.alert('invalid settings format');
|
||||||
console.log('data',data);
|
console.log('data',data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ask && !confirm(`Import settings made on ${new Date(data.time)} from Kiri:Moto version ${data.version}?`)) {
|
function doit() {
|
||||||
return;
|
settings = CONF.normalize(data.settings);
|
||||||
|
API.conf.save();
|
||||||
|
API.space.reload();
|
||||||
|
}
|
||||||
|
if (ask) {
|
||||||
|
UC.confirm(`Import settings made in Kiri:Moto version ${data.version} on<br>${new Date(data.time)}?`).then((yes) => {
|
||||||
|
if (yes) doit();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
doit();
|
||||||
}
|
}
|
||||||
settings = CONF.normalize(data.settings);
|
|
||||||
API.conf.save();
|
|
||||||
API.space.reload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function settingsExport() {
|
function settingsExport() {
|
||||||
|
|
@ -1732,7 +1742,7 @@
|
||||||
}
|
}
|
||||||
API.conf.save();
|
API.conf.save();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('malformed settings object');
|
UC.alert('malformed settings object');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,73 @@
|
||||||
newGroup: newGroup,
|
newGroup: newGroup,
|
||||||
setGroup: setGroup,
|
setGroup: setGroup,
|
||||||
hidePoppers: hidePoppers,
|
hidePoppers: hidePoppers,
|
||||||
|
confirm: confirm,
|
||||||
|
prompt: prompt,
|
||||||
|
alert: alert,
|
||||||
checkpoint,
|
checkpoint,
|
||||||
restore
|
restore
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function alert(message) {
|
||||||
|
return confirm(message, {ok:true});
|
||||||
|
}
|
||||||
|
|
||||||
|
function prompt(message, value) {
|
||||||
|
return confirm(message, {ok:true, cancel:false}, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirm(message, buttons, input) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let btns = buttons || {
|
||||||
|
"yes": true,
|
||||||
|
"no": false
|
||||||
|
};
|
||||||
|
let rnd = Date.now().toString(36);
|
||||||
|
let any = $('mod-any');
|
||||||
|
let html = [
|
||||||
|
`<div class="confirm col a-stretch">`,
|
||||||
|
`<label>${message}</label>`,
|
||||||
|
];
|
||||||
|
let iid;
|
||||||
|
if (input !== undefined) {
|
||||||
|
iid = `confirm-input-${rnd}`;
|
||||||
|
html.append(`<div><input class="grow" type="text" spellcheck="false" value="${input}" id="${iid}"/></div>`);
|
||||||
|
}
|
||||||
|
html.append(`<div class="row j-end">`);
|
||||||
|
Object.entries(btns).forEach((row,i) => {
|
||||||
|
html.append(`<button id="confirm-${i}-${rnd}">${row[0]}</button>`);
|
||||||
|
});
|
||||||
|
$('mod-any').innerHTML = html.append(`</div></div>`).join('');
|
||||||
|
function done(value) {
|
||||||
|
KIRI.api.modal.hide();
|
||||||
|
setTimeout(() => { resolve(value) }, 150);
|
||||||
|
}
|
||||||
|
if (iid) {
|
||||||
|
iid = $(iid);
|
||||||
|
iid.onkeypress = (ev) => {
|
||||||
|
if (ev.key === 'Enter' || ev.charCode === 13) {
|
||||||
|
done(ev.target.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Object.entries(btns).forEach((row,i) => {
|
||||||
|
$(`confirm-${i}-${rnd}`).onclick = (ev) => {
|
||||||
|
let value = iid && row[1] ? iid.value : row[1];
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
done(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
KIRI.api.modal.show('any');
|
||||||
|
if (iid) {
|
||||||
|
iid.focus();
|
||||||
|
iid.selectionStart = iid.value.length;
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function setMode(mode) {
|
function setMode(mode) {
|
||||||
Object.keys(groupShow).forEach(group => {
|
Object.keys(groupShow).forEach(group => {
|
||||||
updateGroupShow(group);
|
updateGroupShow(group);
|
||||||
|
|
|
||||||
|
|
@ -595,7 +595,8 @@
|
||||||
let fz = freeze;
|
let fz = freeze;
|
||||||
freeze = b;
|
freeze = b;
|
||||||
return fz;
|
return fz;
|
||||||
}
|
},
|
||||||
|
active: updateLastAction
|
||||||
},
|
},
|
||||||
|
|
||||||
platform: {
|
platform: {
|
||||||
|
|
@ -663,8 +664,7 @@
|
||||||
downSelect: function(f) { mouseDownSelect = f },
|
downSelect: function(f) { mouseDownSelect = f },
|
||||||
upSelect: function(f) { mouseUpSelect = f },
|
upSelect: function(f) { mouseUpSelect = f },
|
||||||
onDrag: function(f) { mouseDrag = f },
|
onDrag: function(f) { mouseDrag = f },
|
||||||
onHover: function(f) { mouseHover = f },
|
onHover: function(f) { mouseHover = f }
|
||||||
active: updateLastAction
|
|
||||||
},
|
},
|
||||||
|
|
||||||
useDefaultKeys: function(b) {
|
useDefaultKeys: function(b) {
|
||||||
|
|
|
||||||
|
|
@ -678,6 +678,25 @@ and (orientation : landscape) {
|
||||||
#help-right {
|
#help-right {
|
||||||
padding-left: 3px;
|
padding-left: 3px;
|
||||||
}
|
}
|
||||||
|
.confirm {
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
|
.confirm > div {
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
.confirm label {
|
||||||
|
text-align: center;
|
||||||
|
line-height: 1.5em;
|
||||||
|
padding: 0 10px 0 10px;
|
||||||
|
}
|
||||||
|
.confirm button {
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
.confirm input {
|
||||||
|
padding: 3px;
|
||||||
|
margin: 0 10px 0 10px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
.dev-type {
|
.dev-type {
|
||||||
font-family: 'Russo One', sans-serif;
|
font-family: 'Russo One', sans-serif;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue