- bump kwaadpepper/crud-policies - npm i vue-select moment --save-dev - Add Planning components - csrf_token to axios - Add Model WeekendPlanning - Add Enums CellModel, CellType, TableRow
45 lines
1.9 KiB
JavaScript
Vendored
45 lines
1.9 KiB
JavaScript
Vendored
export default {
|
|
methods: {
|
|
route(routeName, parameters = []) {
|
|
let route = Object.keys(window._routes).indexOf(routeName) !== -1 ?
|
|
window._routes[routeName] : null;
|
|
if (!route) {
|
|
return route;
|
|
}
|
|
// copy parameters
|
|
let iParameters = Object.assign({}, parameters);
|
|
let origin = window.location.origin;
|
|
let pathname = route.replace(origin, '');
|
|
let hash = window.location.hash;
|
|
|
|
// replace in path name
|
|
for (let paramName in iParameters) {
|
|
let paramValue = parameters[paramName];
|
|
if (pathname.indexOf(paramName) !== -1) {
|
|
pathname = pathname.replace(paramName, paramValue);
|
|
}
|
|
delete parameters[paramName];
|
|
}
|
|
|
|
// search, dont copy if target url is different than actual
|
|
let search = pathname == window.location.pathname ? window.location.search : ''
|
|
|
|
for (let paramName in parameters) {
|
|
let paramValue = parameters[paramName];
|
|
if (search.indexOf(paramName + "=") >= 0) {
|
|
prefix = search.substring(0, search.indexOf(paramName + "="));
|
|
suffix = search.substring(search.indexOf(paramName + "="));
|
|
suffix = suffix.substring(suffix.indexOf("=") + 1);
|
|
suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : '';
|
|
search = prefix + paramName + "=" + paramValue + suffix;
|
|
} else if (search.indexOf("?") < 0) {
|
|
search += "?" + paramName + "=" + paramValue
|
|
} else {
|
|
search += "&" + paramName + "=" + paramValue
|
|
}
|
|
}
|
|
return origin + pathname + search + hash;
|
|
}
|
|
},
|
|
}
|
|
|