var MENU=
{
mixins:[COMP.base],
mounted()
{
this.$refs.menu?.setSelected(this.menu_selected);
},
methods:
{
buildTab(name,tag,path,onclick,cls)
{
var core = "lib/core_svg.php?svg="
return{
name:name,
tag:tag,
path:core+path,
click:onclick,
cls:cls
}
},
onMenu(item)
{
item.click?item.click(item):this.$emit("onMenu",item);
}
},
}
var FORM=
{
mixins:[COMP.base],
props:["btns_show"],
methods:
{
buildField(label,type,_default)
{
return{
label:label,
type:type||"text",
default:_default
}
},
buildOption(label,options,default_,onSelect)
{
return{
label:label,
type:"option",
options:options,
default:default_,
onSelect:onSelect?onSelect:()=>{}
}
},
buildFunction(label,cls,func)
{
return {label:label,type:"function",cls_header:cls,func:func}
},
loadBtns()
{
var btns = {}
if(!this.readonly)
{
btns.save =
{
text:"Save",
onClick:this.save
};
if(this.val?.id)
btns.delete =
{
text:"Delete",
onClick:this.delete
}
}
this.btns = btns;
},
async save()
{
if(this.form_data)
{
delete this.form_data.type;
var req =
{
action:"save",
input:
{
data:this.form_data
}
}
var res = await WEB.api(this.path,req);
this.$parent.$emit("onSave",res);
POPUP.close();
POPUP.prompt("Save Successful","Data saved successfully");
}
},
async delete()
{
var name = this.form_data?.name;
var msg = "Are you sure you want to delete : "+name+"?";
var heading = "Delete "+name+"?";
POPUP.confirm(heading,msg,async ()=>
{
var req =
{
action:"delete",
input: this.form_data
}
var res = await WEB.api(this.path,req);
this.$emit("onDelete",res);
POPUP.close();
})
}
},
}
var LIST =
{
mixins:[COMP.base],
props:
{
show_heading:
{
default:true
},
_onSelect:{},
},
watch:
{
parent:
{
deep:true,
handler(val)
{
this.requestFetch()
}
},
},
data()
{
return {
path:"",
search:"",
fields:{},
rows:{},
action:null
}
},
created()
{
if(!this.path) console.log("no path to api");
},
methods:
{
async load(input)
{
// var rows_pre = UTIL.deepCopy(this.rows);
if( !UTIL.Empty(this.parent))
{
var type = this.parent.type?this.parent.type:"account";
this.path = "./api/"+type+".php";
input.parent = this.parent;
}
if( !UTIL.Empty(this.child))
{
input.child = this.child;
}
var req =
{
action: this.action? this.action:(UTIL.Empty(this.parent)?"list":"link_list"),
input: input
}
var rows= await WEB.api(this.path,req);
if(this.$refs.list)
{
if(this.$refs.list.can_lock)
for (var k in rows)
{
var row = rows[k];
// console.log(row.lock);
if(!row.lock) row.lock=false;
}
}
this.rows = rows;
},
onSelect()
{
console.log("please add a onSelect method");
},
select(row)
{
this.$emit("onSelect",row);
},
requestFetch()
{
if(this.$refs.list) this.$refs.list.requestFetch();
},
buildIputText(label,cls)
{
return {label:label,type:"input_text",cls_header:cls}
},
buildImage(label,cls)
{
return {label:label,type:"image",col_cls:cls}
},
buildText(label,cls)
{
return {label:label,col_cls:cls}
},
buildSvg(label,cls)
{
return {label:label,type:"svg",col_cls:cls}
},
buildIputNumber(label,cls,func)
{
return {label:label,type:"input_number",cls_header:cls,func:func}
},
buildFunction(label,cls,func)
{
return {label:label,type:"function",cls_header:cls,func:func}
},
buildTypeOptions(label,options,cls)
{
return {
label:label,
type:"option",
options:options,
cls_header:cls
}
},
},
}
var FILE =
{
loaded :{},
async save(file,account_id)
{
var res = {};
if(file.data)
{
file.name = file.name?file.name:UTIL.genHash(6);
var path_file = "./d/api/file.php";
var res_file =
{
action:"save",
input:
{
name:file.name,
data:file.data,
account_id:account_id
}
}
if(file.id)res_file.input.id = file.id;
console.log(res_file);
res = await WEB.api(path_file,res_file);
}
return res;
},
async get(image)
{
// var image_id = image?.id;
// var image_size = image?.size||"<300";
// var res = FILE.loaded[image_id+"_"+image_size];
// if(!res)
// {
var path = "./d/api/file.php";
var res_file =
{
action:"get",
input: image
}
res = await WEB.api(path,res_file);
// console.log(res,"res_file");
// FILE.loaded[image_id+"_"+image_size]=res;
// }
return res;
},
async toCsv(text)
{
var path = "./d/api/csv.php";
var req =
{
action:"getArrayFromCSV",
input:
{
data:text
}
}
return awaitWEB.api(path,req, true);
}
}
var SHOP =
{
data()
{
return {
path : "./d/api/shopItem.php",
}
},
methods:
{
async save(data)
{
if(data)
{
delete data.type;
var req =
{
action:"save",
input:
{
data
}
}
var res = await WEB.api(this.path,req);
this.$parent.$emit("onSave",res);
POPUP.close();
POPUP.prompt("Save Successful","Data saved successfully");
}
},
async delete(data)
{
var name = data?.name;
var msg = "Are you sure you want to delete : "+name+"?";
var heading = "Delete "+name+"?";
POPUP.confirm(heading,msg,async ()=>
{
var req =
{
action:"delete",
input: data
}
var res = await WEB.api(this.path,req);
this.$emit("onDelete",res);
POPUP.close();
})
}
}
}