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();
|
||||
break;
|
||||
case cca('Z'): // reset stored state
|
||||
if (confirm('clear all settings?')) {
|
||||
SDB.clear();
|
||||
}
|
||||
UC.confirm('clear all settings and preferences?').then(yes => {
|
||||
if (yes) SDB.clear();
|
||||
});
|
||||
break;
|
||||
case cca('C'): // refresh catalog
|
||||
CATALOG.refresh();
|
||||
|
|
@ -303,7 +303,9 @@
|
|||
storeSettingsToServer(true);
|
||||
break;
|
||||
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;
|
||||
case cca('s'): // complete slice
|
||||
API.function.slice();
|
||||
|
|
@ -460,7 +462,9 @@
|
|||
let res = JSON.parse(reply);
|
||||
if (res && 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 {
|
||||
updateSpaceState();
|
||||
|
|
@ -469,13 +473,15 @@
|
|||
}
|
||||
|
||||
function profileExport() {
|
||||
let name = WIN.prompt("Export Profile Filename", "kiriconf");
|
||||
if (!name) return;
|
||||
let json = API.conf.export(),
|
||||
blob = new Blob([json], {type: "octet/stream"}),
|
||||
url = WIN.URL.createObjectURL(blob);
|
||||
$('mod-any').innerHTML = `<a id="sexport" href="${url}" download="${name}.b64">x</a>`;
|
||||
$('sexport').click();
|
||||
UC.prompt("Export Profile Filename", "kiriconf").then(name => {
|
||||
if (name) {
|
||||
let json = API.conf.export(),
|
||||
blob = new Blob([json], {type: "octet/stream"}),
|
||||
url = WIN.URL.createObjectURL(blob);
|
||||
$('mod-any').innerHTML = `<a id="sexport" href="${url}" download="${name}.b64">x</a>`;
|
||||
$('sexport').click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function settingsSave(ev) {
|
||||
|
|
@ -483,25 +489,27 @@
|
|||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
API.dialog.hide();
|
||||
let mode = API.mode.get(),
|
||||
s = settings(),
|
||||
def = "default",
|
||||
cp = s.process,
|
||||
pl = s.sproc[mode],
|
||||
// pt = sf[mode.toLowerCase()].p, // process field mask
|
||||
name = WIN.prompt("Save Settings As", cp ? cp.processName || def : def);
|
||||
if (!name) return;
|
||||
let np = pl[name] = {};
|
||||
cp.processName = name;
|
||||
for (let k in cp) {
|
||||
if (!cp.hasOwnProperty(k)) continue;
|
||||
// if (!pt.hasOwnProperty(k)) continue; // mask out invalid fields
|
||||
np[k] = cp[k];
|
||||
}
|
||||
s.cproc[API.mode.get()] = name;
|
||||
API.conf.save();
|
||||
API.event.settings();
|
||||
pl = s.sproc[mode];
|
||||
|
||||
UC.prompt("Save Settings As", cp ? cp.processName || def : def).then(name => {
|
||||
if (name) {
|
||||
let np = pl[name] = {};
|
||||
cp.processName = name;
|
||||
for (let k in cp) {
|
||||
if (!cp.hasOwnProperty(k)) continue;
|
||||
np[k] = cp[k];
|
||||
}
|
||||
s.cproc[API.mode.get()] = name;
|
||||
API.conf.save();
|
||||
API.event.settings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function settingsLoad() {
|
||||
|
|
@ -996,11 +1004,25 @@
|
|||
|
||||
SPACE.platform.setColor(platformColor);
|
||||
|
||||
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;
|
||||
let files = evt.dataTransfer.files;
|
||||
|
||||
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) {
|
||||
|
|
@ -1504,7 +1526,7 @@
|
|||
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.show.layer();
|
||||
SPACE.mouse.active();
|
||||
SPACE.scene.active();
|
||||
}
|
||||
|
||||
function dragit(el, delta) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@
|
|||
|
||||
let shift = Math.tan(hA - Math.PI * .5);
|
||||
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, 0, 1
|
||||
);
|
||||
|
|
|
|||
|
|
@ -683,7 +683,9 @@
|
|||
clearPrint();
|
||||
API.conf.save();
|
||||
|
||||
if (MODE === MODES.CAM) {
|
||||
let isCam = MODE === MODES.CAM;
|
||||
|
||||
if (isCam) {
|
||||
setOpacity(color.cam_preview_opacity);
|
||||
forAllWidgets(function(widget) {
|
||||
widget.setColor(color.cam_preview);
|
||||
|
|
@ -701,7 +703,7 @@
|
|||
}
|
||||
|
||||
setProgress(0);
|
||||
setOpacity(0);
|
||||
if (!isCam) setOpacity(0);
|
||||
|
||||
currentPrint.render();
|
||||
|
||||
|
|
@ -778,6 +780,7 @@
|
|||
preserveLayer = API.var.layer_hi,
|
||||
totalProgress,
|
||||
track = {},
|
||||
mode = settings.mode,
|
||||
now = UTIL.time();
|
||||
|
||||
// require topo be sent back from worker for local printing
|
||||
|
|
@ -791,7 +794,8 @@
|
|||
segNumber = 0,
|
||||
errored = false,
|
||||
startTime,
|
||||
lastMsg;
|
||||
lastMsg,
|
||||
camOrLaser = mode === 'CAM' || mode === 'LASER';
|
||||
|
||||
widget.stats.progress = 0;
|
||||
widget.setColor(color.slicing);
|
||||
|
|
@ -801,7 +805,7 @@
|
|||
widget.render();
|
||||
// clear wireframe
|
||||
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);
|
||||
// update UI info
|
||||
if (sliced) {
|
||||
|
|
@ -820,7 +824,7 @@
|
|||
if (--countdown === 0 || error || errored) {
|
||||
setProgress(0);
|
||||
showSlices(preserveLayer);
|
||||
setOpacity(settings.mode === 'CAM' ? color.cam_sliced_opacity : color.sliced_opacity);
|
||||
SPACE.scene.active();
|
||||
if (callback && typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
|
|
@ -1483,22 +1487,28 @@
|
|||
try {
|
||||
data = JSON.parse(atob(data));
|
||||
} catch (e) {
|
||||
alert('invalid settings format');
|
||||
UC.alert('invalid settings format');
|
||||
console.log('data',data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!(data.settings && data.version && data.time)) {
|
||||
alert('invalid settings format');
|
||||
UC.alert('invalid settings format');
|
||||
console.log('data',data);
|
||||
return;
|
||||
}
|
||||
if (ask && !confirm(`Import settings made on ${new Date(data.time)} from Kiri:Moto version ${data.version}?`)) {
|
||||
return;
|
||||
function doit() {
|
||||
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() {
|
||||
|
|
@ -1732,7 +1742,7 @@
|
|||
}
|
||||
API.conf.save();
|
||||
} catch (e) {
|
||||
alert('malformed settings object');
|
||||
UC.alert('malformed settings object');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,10 +54,73 @@
|
|||
newGroup: newGroup,
|
||||
setGroup: setGroup,
|
||||
hidePoppers: hidePoppers,
|
||||
confirm: confirm,
|
||||
prompt: prompt,
|
||||
alert: alert,
|
||||
checkpoint,
|
||||
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) {
|
||||
Object.keys(groupShow).forEach(group => {
|
||||
updateGroupShow(group);
|
||||
|
|
|
|||
|
|
@ -595,7 +595,8 @@
|
|||
let fz = freeze;
|
||||
freeze = b;
|
||||
return fz;
|
||||
}
|
||||
},
|
||||
active: updateLastAction
|
||||
},
|
||||
|
||||
platform: {
|
||||
|
|
@ -663,8 +664,7 @@
|
|||
downSelect: function(f) { mouseDownSelect = f },
|
||||
upSelect: function(f) { mouseUpSelect = f },
|
||||
onDrag: function(f) { mouseDrag = f },
|
||||
onHover: function(f) { mouseHover = f },
|
||||
active: updateLastAction
|
||||
onHover: function(f) { mouseHover = f }
|
||||
},
|
||||
|
||||
useDefaultKeys: function(b) {
|
||||
|
|
|
|||
|
|
@ -678,6 +678,25 @@ and (orientation : landscape) {
|
|||
#help-right {
|
||||
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 {
|
||||
font-family: 'Russo One', sans-serif;
|
||||
|
|
|
|||
Loading…
Reference in a new issue