Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/app.js
Show All 27 Lines | data() { | ||||
} | } | ||||
}, | }, | ||||
methods: { | methods: { | ||||
// Clear (bootstrap) form validation state | // Clear (bootstrap) form validation state | ||||
clearFormValidation(form) { | clearFormValidation(form) { | ||||
$(form).find('.is-invalid').removeClass('is-invalid') | $(form).find('.is-invalid').removeClass('is-invalid') | ||||
$(form).find('.invalid-feedback').remove() | $(form).find('.invalid-feedback').remove() | ||||
}, | }, | ||||
hasRoute(name) { | |||||
return this.$router.resolve({ name: name }).resolved.matched.length > 0 | |||||
}, | |||||
hasBeta(name) { | |||||
const authInfo = store.state.authInfo | |||||
return authInfo.statusInfo.betaSKUs && authInfo.statusInfo.betaSKUs.indexOf(name) != -1 | |||||
}, | |||||
isController(wallet_id) { | isController(wallet_id) { | ||||
if (wallet_id && store.state.authInfo) { | if (wallet_id && store.state.authInfo) { | ||||
let i | let i | ||||
for (i = 0; i < store.state.authInfo.wallets.length; i++) { | for (i = 0; i < store.state.authInfo.wallets.length; i++) { | ||||
if (wallet_id == store.state.authInfo.wallets[i].id) { | if (wallet_id == store.state.authInfo.wallets[i].id) { | ||||
return true | return true | ||||
} | } | ||||
} | } | ||||
Show All 40 Lines | methods: { | ||||
this.refreshTimeout = setTimeout(() => { | this.refreshTimeout = setTimeout(() => { | ||||
axios.post('/api/auth/refresh').then(response => { | axios.post('/api/auth/refresh').then(response => { | ||||
this.loginUser(response.data, false, true) | this.loginUser(response.data, false, true) | ||||
}) | }) | ||||
}, timeout * 1000) | }, timeout * 1000) | ||||
}, | }, | ||||
// Set user state to "not logged in" | // Set user state to "not logged in" | ||||
logoutUser() { | logoutUser(redirect) { | ||||
store.commit('logoutUser') | store.commit('logoutUser') | ||||
localStorage.setItem('token', '') | localStorage.setItem('token', '') | ||||
delete axios.defaults.headers.common.Authorization | delete axios.defaults.headers.common.Authorization | ||||
if (redirect !== false) { | |||||
if (this.hasRoute('login')) { | |||||
this.$router.push({ name: 'login' }) | this.$router.push({ name: 'login' }) | ||||
} | |||||
} | |||||
clearTimeout(this.refreshTimeout) | clearTimeout(this.refreshTimeout) | ||||
}, | }, | ||||
// Display "loading" overlay inside of the specified element | // Display "loading" overlay inside of the specified element | ||||
addLoader(elem) { | addLoader(elem) { | ||||
$(elem).css({position: 'relative'}).append($(loader).addClass('small')) | $(elem).css({position: 'relative'}).append($(loader).addClass('small')) | ||||
}, | }, | ||||
// Remove loader element added in addLoader() | // Remove loader element added in addLoader() | ||||
removeLoader(elem) { | removeLoader(elem) { | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | methods: { | ||||
} | } | ||||
}, | }, | ||||
downloadFile(url) { | downloadFile(url) { | ||||
// TODO: This might not be a best way for big files as the content | // TODO: This might not be a best way for big files as the content | ||||
// will be stored (temporarily) in browser memory | // will be stored (temporarily) in browser memory | ||||
// TODO: This method does not show the download progress in the browser | // TODO: This method does not show the download progress in the browser | ||||
// but it could be implemented in the UI, axios has 'progress' property | // but it could be implemented in the UI, axios has 'progress' property | ||||
axios.get(url, { responseType: 'blob' }) | axios.get(url, { responseType: 'blob' }) | ||||
.then (response => { | .then(response => { | ||||
const link = document.createElement('a') | const link = document.createElement('a') | ||||
const contentDisposition = response.headers['content-disposition'] | const contentDisposition = response.headers['content-disposition'] | ||||
let filename = 'unknown' | let filename = 'unknown' | ||||
if (contentDisposition) { | if (contentDisposition) { | ||||
const match = contentDisposition.match(/filename="(.+)"/); | const match = contentDisposition.match(/filename="(.+)"/); | ||||
if (match.length === 2) { | if (match.length === 2) { | ||||
filename = match[1]; | filename = match[1]; | ||||
▲ Show 20 Lines • Show All 241 Lines • Show Last 20 Lines |