2023-05-16 10:31:27 +02:00
|
|
|
/*eslint no-undef:0*/
|
|
|
|
/*eslint-env browser*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
var towns = towns || {};
|
|
|
|
|
2023-05-31 15:19:21 +02:00
|
|
|
towns.loadtpldata = () => {
|
|
|
|
// adapte tpldata to template tpl
|
|
|
|
const dataowner = apx.data.tpldata.setup;
|
|
|
|
dataowner.alias=apx.data.headers.xalias;
|
2023-06-21 09:27:59 +02:00
|
|
|
dataowner.auth = dataowner.alias!="anonymous";
|
2023-05-31 15:19:21 +02:00
|
|
|
dataowner.devtown = dataowner.townId == "devfarm";
|
|
|
|
if (dataowner.mayorid) dataowner.owner = dataowner.mayorid == dataowner.alias;
|
|
|
|
console.log('Data return to template',dataowner)
|
|
|
|
return dataowner;
|
|
|
|
};
|
2023-06-21 09:27:59 +02:00
|
|
|
towns.owntown = (newowner) => {
|
2023-05-31 15:19:21 +02:00
|
|
|
// only the owner can give ownership to someone else
|
2023-06-21 09:27:59 +02:00
|
|
|
if (!newowner) {newowner=apx.data.headers.xalias}
|
|
|
|
axios.get(`api/towns/changeowner/${newowner}`,{ headers: apx.data.headers }).then(rep=>{
|
|
|
|
console.log(rep)
|
|
|
|
apx.data.tpldata.setup.moyorId=newowner;
|
|
|
|
apx.save();
|
|
|
|
app.load('apxmain','townowner',towns.loadtpldata())
|
|
|
|
}).catch(err=>{
|
|
|
|
console.log(err)
|
|
|
|
})
|
2023-05-31 15:19:21 +02:00
|
|
|
|
|
|
|
};
|