2023-05-16 08:31:27 +00:00
|
|
|
/*eslint no-undef:0*/
|
|
|
|
/*eslint-env browser*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
var towns = towns || {};
|
|
|
|
|
2023-06-28 13:23:17 +00:00
|
|
|
towns.loadtpldata = (fortpl) => {
|
2023-05-31 13:19:21 +00:00
|
|
|
// adapte tpldata to template tpl
|
2023-06-28 13:23:17 +00:00
|
|
|
if (fortpl == "owner") {
|
|
|
|
const dataowner = apx.data.tpldata.setup;
|
|
|
|
dataowner.alias = apx.data.headers.xalias;
|
|
|
|
dataowner.auth = dataowner.alias != "anonymous";
|
|
|
|
dataowner.devtown = dataowner.townId == "devfarm";
|
|
|
|
if (dataowner.mayorId)
|
|
|
|
dataowner.owner = dataowner.mayorId == dataowner.alias;
|
|
|
|
console.log("Data return to template", dataowner);
|
|
|
|
return dataowner;
|
|
|
|
}
|
|
|
|
if (fortpl == "tribes") {
|
|
|
|
const data= {
|
|
|
|
idcomponent: "tribesmanager",
|
|
|
|
objectname:"tribes",
|
|
|
|
itm: [
|
|
|
|
{ tribeId: "tribe1", druidId: "philc" },
|
|
|
|
{ tribeId: "tribe2", druidId: "toto" },
|
|
|
|
]
|
|
|
|
};
|
|
|
|
data.tplform=`
|
|
|
|
<div class='mb-3'>
|
|
|
|
<label for='tribeIdinput' class='form-label'>Tribes Name</label>
|
|
|
|
<input type='text' class='form-control' id='tribIdinput' placeholder='A unique name'>
|
|
|
|
</div>
|
|
|
|
<div class='mb-3'>
|
|
|
|
<label for='druidIdinput' class='form-label'>Druid Alias</label>
|
|
|
|
<input type='text' class='form-control' id='druidIdinput' placeholder='An existing alias to become Tribe's Druid'>
|
|
|
|
</div>
|
|
|
|
<div class='input-group mb-3 objaction'>
|
|
|
|
<button class=' objsave btn btn-outline-primary btn-sm' onclick='towns.addupdatetribe('{{tribeId');'><i class='bi-cloud-arrow-up'></i></button>
|
|
|
|
</div>`;
|
|
|
|
return data;
|
|
|
|
}
|
2023-05-31 13:19:21 +00:00
|
|
|
};
|
2023-06-21 07:27:59 +00:00
|
|
|
towns.owntown = (newowner) => {
|
2023-05-31 13:19:21 +00:00
|
|
|
// only the owner can give ownership to someone else
|
2023-06-28 13:23:17 +00: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.mayorId = newowner;
|
|
|
|
apx.save();
|
2023-06-29 08:57:44 +00:00
|
|
|
app.load("apxmain", "townowner", towns.loadtpldata("owner"));
|
2023-06-28 13:23:17 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
2023-05-31 13:19:21 +00:00
|
|
|
};
|
2023-06-28 13:23:17 +00:00
|
|
|
towns.addtribe=(tribeId)=>{
|
|
|
|
|
|
|
|
}
|