//delayed promise to prevent dialog "glitch" animation (show hide animations at the same time) function delayedPromise(p, delay = 300) { return new Promise((resolve, reject) => { setTimeout(() => { p(resolve, reject) }, delay) }) } async function prompt(title, question, value, useTextArea) { if (value === undefined) { let tmp = question question = title value = tmp title = translate('dialogs.prompt') } return delayedPromise((resolve, reject) => { let a = data.gdialog a.title = title a.text = question a.value = value a.showInput = true a.useTextArea = useTextArea a.showOK = true a.showCancel = true a.showSelect = false a.close = (ok) => { a.show = false resolve(ok ? a.value : null) } a.show = true setTimeout(() => { app.$refs.alert_inputbox.focus(); }, 300) }) } async function alert(title, text) { return delayedPromise((resolve, reject) => { let a = data.gdialog a.title = text ? title : null a.text = text || title a.showOK = true a.showCancel = false a.showInput = false a.showSelect = false a.close = () => { a.show = false resolve() } a.show = true _focusOkButton() }) } async function toast(text, error) { let newlist = [] for (let snap of data.snackbars) { if (snap.show) newlist.push(snap) } newlist.splice(0, 0, { text, color: error ? 'error': 'primary', show: true, //timeout: 1000000 }) data.snackbars = newlist } let _lastTimeout async function loaderShow(text, delayed, withPercentage) { data.loaderCounter ++ data.loaderWithPercentage = withPercentage data.loaderPercentage = 0 data.loaderText = text || 'Processing...' if (delayed) { if (_lastTimeout) clearTimeout(_lastTimeout) _lastTimeout = 0 _lastTimeout = setTimeout(() => { _lastTimeout = 0 if (data.loaderCounter > 0) data.loader = true }, 800) } else { data.loader = true } } function loaderSetPercentage(percentage) { data.loaderPercentage = percentage } async function loaderHide() { data.loaderCounter -- if (data.loaderCounter < 1) { data.loaderCounter = 0 data.loader = false } //data.gdialog.show = false } function _focusOkButton() { Vue.nextTick(() => { setTimeout(() => document.getElementById('gd-btn-ok').focus(), 300) }) } async function confirm(question) { return delayedPromise((resolve, reject) => { let a = data.gdialog a.text = question a.title = null a.showOK = true a.showCancel = true a.showInput = false a.showSelect = false a.close = (ok) => { a.show = false resolve(ok) } a.show = true _focusOkButton() }) } async function select(list, text, defaultValue = null, wantMultiple = false) { return delayedPromise((resolve, reject) => { let a = data.gdialog a.title = translate('dialogs.option_title') a.text = text || translate("dialogs.option_text") a.value = defaultValue a.list = list a.showInput = false a.showOK = true a.multiple = wantMultiple a.showCancel = false a.showSelect = true a.close = (ok) => { a.show = false if (typeof list[0] == 'object' || wantMultiple) { resolve(ok ? a.value : null) } else { let index = list.indexOf(a.value) resolve(ok ? index : -1) } } a.show = true setTimeout(() => { let input = app.$refs.alert_select.$el.querySelector('input') input.focus(); app.$refs.alert_select.focus() //app.$refs.alert_select.activateMenu() }, 300) }) }