Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/app.js
Show First 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | methods: { | ||||
isLoading() { | isLoading() { | ||||
return isLoading > 0 | return isLoading > 0 | ||||
}, | }, | ||||
errorPage(code, msg, hint) { | errorPage(code, msg, hint) { | ||||
// Until https://github.com/vuejs/vue-router/issues/977 is implemented | // Until https://github.com/vuejs/vue-router/issues/977 is implemented | ||||
// we can't really use router to display error page as it has two side | // we can't really use router to display error page as it has two side | ||||
// effects: it changes the URL and adds the error page to browser history. | // effects: it changes the URL and adds the error page to browser history. | ||||
// For now we'll be replacing current view with error page "manually". | // For now we'll be replacing current view with error page "manually". | ||||
const map = { | |||||
400: "Bad request", | |||||
401: "Unauthorized", | |||||
403: "Access denied", | |||||
404: "Not found", | |||||
405: "Method not allowed", | |||||
500: "Internal server error" | |||||
} | |||||
if (!msg) msg = map[code] || "Unknown Error" | if (!msg) msg = this.$te('error.' + code) ? this.$t('error.' + code) : this.$t('error.unknown') | ||||
if (!hint) hint = '' | if (!hint) hint = '' | ||||
const error_page = '<div id="error-page" class="error-page">' | const error_page = '<div id="error-page" class="error-page">' | ||||
+ `<div class="code">${code}</div><div class="message">${msg}</div><div class="hint">${hint}</div>` | + `<div class="code">${code}</div><div class="message">${msg}</div><div class="hint">${hint}</div>` | ||||
+ '</div>' | + '</div>' | ||||
$('#error-page').remove() | $('#error-page').remove() | ||||
$('#app').append(error_page) | $('#app').append(error_page) | ||||
Show All 36 Lines | methods: { | ||||
} | } | ||||
link.href = window.URL.createObjectURL(response.data) | link.href = window.URL.createObjectURL(response.data) | ||||
link.download = filename | link.download = filename | ||||
link.click() | link.click() | ||||
}) | }) | ||||
}, | }, | ||||
price(price, currency) { | price(price, currency) { | ||||
// TODO: Set locale argument according to the currently used locale | |||||
return ((price || 0) / 100).toLocaleString('de-DE', { style: 'currency', currency: currency || 'CHF' }) | return ((price || 0) / 100).toLocaleString('de-DE', { style: 'currency', currency: currency || 'CHF' }) | ||||
}, | }, | ||||
priceLabel(cost, discount) { | priceLabel(cost, discount) { | ||||
let index = '' | let index = '' | ||||
if (discount) { | if (discount) { | ||||
cost = Math.floor(cost * ((100 - discount) / 100)) | cost = Math.floor(cost * ((100 - discount) / 100)) | ||||
index = '\u00B9' | index = '\u00B9' | ||||
Show All 21 Lines | methods: { | ||||
if (!domain.isVerified || !domain.isLdapReady || !domain.isConfirmed) { | if (!domain.isVerified || !domain.isLdapReady || !domain.isConfirmed) { | ||||
return 'text-danger' | return 'text-danger' | ||||
} | } | ||||
return 'text-success' | return 'text-success' | ||||
}, | }, | ||||
domainStatusText(domain) { | domainStatusText(domain) { | ||||
if (domain.isDeleted) { | if (domain.isDeleted) { | ||||
return 'Deleted' | return this.$t('status.deleted') | ||||
} | } | ||||
if (domain.isSuspended) { | if (domain.isSuspended) { | ||||
return 'Suspended' | return this.$t('status.suspended') | ||||
} | } | ||||
if (!domain.isVerified || !domain.isLdapReady || !domain.isConfirmed) { | if (!domain.isVerified || !domain.isLdapReady || !domain.isConfirmed) { | ||||
return 'Not Ready' | return this.$t('status.notready') | ||||
} | } | ||||
return 'Active' | return this.$t('status.active') | ||||
}, | }, | ||||
distlistStatusClass(list) { | distlistStatusClass(list) { | ||||
if (list.isDeleted) { | if (list.isDeleted) { | ||||
return 'text-muted' | return 'text-muted' | ||||
} | } | ||||
if (list.isSuspended) { | if (list.isSuspended) { | ||||
return 'text-warning' | return 'text-warning' | ||||
} | } | ||||
if (!list.isLdapReady) { | if (!list.isLdapReady) { | ||||
return 'text-danger' | return 'text-danger' | ||||
} | } | ||||
return 'text-success' | return 'text-success' | ||||
}, | }, | ||||
distlistStatusText(list) { | distlistStatusText(list) { | ||||
if (list.isDeleted) { | if (list.isDeleted) { | ||||
return 'Deleted' | return this.$t('status.deleted') | ||||
} | } | ||||
if (list.isSuspended) { | if (list.isSuspended) { | ||||
return 'Suspended' | return this.$t('status.suspended') | ||||
} | } | ||||
if (!list.isLdapReady) { | if (!list.isLdapReady) { | ||||
return 'Not Ready' | return this.$t('status.notready') | ||||
} | } | ||||
return 'Active' | return this.$t('status.active') | ||||
}, | }, | ||||
pageName(path) { | pageName(path) { | ||||
let page = this.$route.path | let page = this.$route.path | ||||
// check if it is a "menu page", find the page name | // check if it is a "menu page", find the page name | ||||
// otherwise we'll use the real path as page name | // otherwise we'll use the real path as page name | ||||
window.config.menu.every(item => { | window.config.menu.every(item => { | ||||
if (item.location == page && item.page) { | if (item.location == page && item.page) { | ||||
page = item.page | page = item.page | ||||
return false | return false | ||||
} | } | ||||
}) | }) | ||||
page = page.replace(/^\//, '') | page = page.replace(/^\//, '') | ||||
return page ? page : '404' | return page ? page : '404' | ||||
}, | }, | ||||
supportDialog(container) { | supportDialog(container) { | ||||
let dialog = $('#support-dialog') | let dialog = $('#support-dialog') | ||||
// FIXME: Find a nicer way of doing this | // FIXME: Find a nicer way of doing this | ||||
if (!dialog.length) { | if (!dialog.length) { | ||||
SupportForm.i18n = i18n | |||||
let form = new Vue(SupportForm) | let form = new Vue(SupportForm) | ||||
form.$mount($('<div>').appendTo(container)[0]) | form.$mount($('<div>').appendTo(container)[0]) | ||||
form.$root = this | form.$root = this | ||||
form.$toast = this.$toast | form.$toast = this.$toast | ||||
dialog = $(form.$el) | dialog = $(form.$el) | ||||
} | } | ||||
dialog.on('shown.bs.modal', () => { | dialog.on('shown.bs.modal', () => { | ||||
Show All 12 Lines | methods: { | ||||
if (!user.isImapReady || !user.isLdapReady) { | if (!user.isImapReady || !user.isLdapReady) { | ||||
return 'text-danger' | return 'text-danger' | ||||
} | } | ||||
return 'text-success' | return 'text-success' | ||||
}, | }, | ||||
userStatusText(user) { | userStatusText(user) { | ||||
if (user.isDeleted) { | if (user.isDeleted) { | ||||
return 'Deleted' | return this.$t('status.deleted') | ||||
} | } | ||||
if (user.isSuspended) { | if (user.isSuspended) { | ||||
return 'Suspended' | return this.$t('status.suspended') | ||||
} | } | ||||
if (!user.isImapReady || !user.isLdapReady) { | if (!user.isImapReady || !user.isLdapReady) { | ||||
return 'Not Ready' | return this.$t('status.notready') | ||||
} | } | ||||
return 'Active' | return this.$t('status.active') | ||||
}, | }, | ||||
updateBodyClass(name) { | updateBodyClass(name) { | ||||
// Add 'class' attribute to the body, different for each page | // Add 'class' attribute to the body, different for each page | ||||
// so, we can apply page-specific styles | // so, we can apply page-specific styles | ||||
document.body.className = 'page-' + (name || this.pageName()).replace(/\/.*$/, '') | document.body.className = 'page-' + (name || this.pageName()).replace(/\/.*$/, '') | ||||
} | } | ||||
} | } | ||||
}) | }) | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | error => { | ||||
} | } | ||||
else if (error.response && error.response.data) { | else if (error.response && error.response.data) { | ||||
error_msg = error.response.data.message | error_msg = error.response.data.message | ||||
} | } | ||||
else { | else { | ||||
error_msg = error.request ? error.request.statusText : error.message | error_msg = error.request ? error.request.statusText : error.message | ||||
} | } | ||||
app.$toast.error(error_msg || "Server Error") | app.$toast.error(error_msg || app.$t('error.server')) | ||||
// Pass the error as-is | // Pass the error as-is | ||||
return Promise.reject(error) | return Promise.reject(error) | ||||
} | } | ||||
) | ) |