modified: func.js
modified: index.js modified: object.js modified: public/lib/fn.js modified: public/lib/inter.js modified: views/admin/objects/object_creation.ejs modified: views/admin/objects/object_edit.ejs modified: views/admin/objects/object_groups.ejs modified: views/header.ejs modified: views/load.ejs modified: views/main.ejs modified: views/project.ejs modified: views/static/start.ejs
This commit is contained in:
@ -23,19 +23,29 @@
|
||||
</style>
|
||||
|
||||
<form action="#" class="nobj">
|
||||
<div>
|
||||
<style>
|
||||
#img_prev_div:hover{
|
||||
border: 1px solid black;
|
||||
border-radius: 0.5vw;
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
<div id="img_file_div" >
|
||||
<div class="img_preview">
|
||||
<label for="img_file">макс. размер 2мб</label><br>
|
||||
<input type="file" id="img_file" onchange="previewFile()" accept="image/*" value="" maxlength="1"><br>
|
||||
|
||||
<input hidden type="file" id="img_file" onchange="previewFile()" accept="image/*" value="" maxlength="1"><br>
|
||||
</div>
|
||||
<div style="width: 200px; height: 200px;">
|
||||
<img src="" id="img_prev" height="100" alt="предпросмотр картинки">
|
||||
<div id="img_prev_div" style="width: 200px; height: 200px;" onclick="document.getElementById('img_file').click();">
|
||||
<img src="" id="img_prev" height="100" alt="выбрать изображение">
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="obj_color_check">
|
||||
<label for="obj_color_check">можно менять цвет</label>
|
||||
</div>
|
||||
</div>
|
||||
<textarea id="nobj_description" cols="30" rows="5" placeholder="описание товара"></textarea>
|
||||
<div>
|
||||
<div id="object_edit_type" style="text-align: right;">creation</div>
|
||||
<div id="object_edit_type" style="display: flex;justify-content: space-between;"><div>creation</div></div>
|
||||
<div class="nobj_options">
|
||||
<input type="text" id="nobj_name" placeholder="название товара">
|
||||
<input type="submit" onclick="create_obj()" id="obj_apply_btn" value="создать товар">
|
||||
@ -91,15 +101,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
function set_obj_edit_params(img = "",name = "",description="",height = 100,width = 100,cost = 0,gid = 0){
|
||||
function set_obj_edit_params(img = "",name = "",description="",height = 100,width = 100,cost = 0,gid = 0, id = null){
|
||||
if(img ==""&&name ==""&&description == ""){
|
||||
document.getElementById("object_edit_type").innerText = "добавление";
|
||||
document.getElementById("obj_apply_btn").value = "добавить товар";
|
||||
document.getElementById("obj_apply_btn").setAttribute("onclick","create_obj()");
|
||||
}else {
|
||||
document.getElementById("object_edit_type").innerText = "редактирование";
|
||||
let del_btn = document.createElement("button");
|
||||
del_btn.setAttribute("onclick",`obj_del(${id})`);
|
||||
del_btn.innerText = "удалить объект";
|
||||
document.getElementById("object_edit_type").append(del_btn);
|
||||
document.getElementById("obj_apply_btn").value = "сохранить";
|
||||
document.getElementById("obj_apply_btn").setAttribute("onclick","save_edited_obj()");
|
||||
document.getElementById("obj_apply_btn").setAttribute("onclick",`save_edited_obj(${id})`);
|
||||
// document.getElementById("group_select").selectedIndex = document.getElementById("group_select").options[`obj_group_${gid}`].index;
|
||||
gids = [parseInt(gid)]
|
||||
console.log(gid);
|
||||
@ -148,14 +162,21 @@
|
||||
|
||||
function new_obj(cost,name,img,height,width,description,callback){
|
||||
let gid = gids[0];
|
||||
if(name!=""){
|
||||
$.post( "/admin/objects/new", { cost:cost,name:name,img:img,desc:description,height:height,width:width,gid:gid})
|
||||
.done(function( res ) {
|
||||
// if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
// }
|
||||
callback(res);
|
||||
});
|
||||
if(gid != null){
|
||||
if(name!=""){
|
||||
$.post( "/admin/objects/new", { cost:cost,name:name,img:img,desc:description,height:height,width:width,gid:gid})
|
||||
.done(function( res ) {
|
||||
// if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
// }
|
||||
callback(res);
|
||||
});
|
||||
}
|
||||
}
|
||||
else{
|
||||
alert("группа не выбранна")
|
||||
let res = {out:"bad"}
|
||||
callback(res);
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,7 +187,7 @@
|
||||
let width = document.getElementById("obj_width").value;
|
||||
var img = document.querySelector('#img_prev').src;
|
||||
var cost = document.getElementById("obj_cost").value;
|
||||
name = name.replace(" ","$");
|
||||
name = name.replaceAll(" ","$");
|
||||
if(name != ""){
|
||||
if (img != "http://n0rsrv2:3002/admin"){
|
||||
document.getElementById("obj_resp").innerHTML = "добавление товара";
|
||||
@ -174,15 +195,18 @@
|
||||
if(res["out"] == "bad" && res["err"] == "name"){
|
||||
document.getElementById("obj_resp").innerHTML = "товар уже существует";
|
||||
}
|
||||
else if (res["out"] == "bad" ){
|
||||
document.getElementById("obj_resp").innerHTML = "ошибка при добавлении товара";
|
||||
}
|
||||
else if(res["out"] == "good"){
|
||||
document.getElementById("obj_resp").innerHTML = "товар добавлен";
|
||||
setTimeout(()=>{
|
||||
edit_get_objs();
|
||||
},1000)
|
||||
setTimeout(()=>{
|
||||
document.getElementById("obj_resp").innerHTML = "";
|
||||
},3000)
|
||||
}
|
||||
setTimeout(()=>{
|
||||
document.getElementById("obj_resp").innerHTML = "";
|
||||
},3000)
|
||||
});
|
||||
}
|
||||
else{
|
||||
|
@ -38,19 +38,21 @@
|
||||
<div id="objs_in_group"></div>
|
||||
</div>
|
||||
|
||||
<div class="cmenu" id="object_edit_menu">
|
||||
<button onclick="obj_del()">удалить объект</button>
|
||||
<button onclick="set_edit()">редактирование объекта</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// load_groups(()=>{
|
||||
// edit_get_objs();
|
||||
// });
|
||||
|
||||
function set_edit(){
|
||||
let menu = document.getElementById("object_edit_menu");
|
||||
set_obj_edit_params(menu.getAttribute("obj_img"),menu.getAttribute("obj_name").split("/")[0],menu.getAttribute("obj_description"),menu.getAttribute("obj_height"),menu.getAttribute("obj_width"),menu.getAttribute("obj_cost"),menu.getAttribute("obj_gid"));
|
||||
function set_edit(id){
|
||||
let menu = document.getElementById(`object_${id}`);
|
||||
set_obj_edit_params(menu.getAttribute("src"),
|
||||
menu.getAttribute("name").split("/")[0],
|
||||
menu.getAttribute("description"),
|
||||
menu.getAttribute("height"),
|
||||
menu.getAttribute("width"),
|
||||
menu.getAttribute("cost"),
|
||||
menu.getAttribute("gid"),
|
||||
menu.getAttribute("obj_id"));
|
||||
}
|
||||
|
||||
function edit_get_objs(by_name){
|
||||
@ -68,17 +70,23 @@
|
||||
}
|
||||
|
||||
function gids_change(){
|
||||
let last = gids.at(-1)
|
||||
gids = [last];
|
||||
edit_get_objs();
|
||||
if (typeof gids[0] == 'undefined'){
|
||||
gids = []
|
||||
edit_get_objs();
|
||||
}
|
||||
else{
|
||||
let last = gids.at(-1)
|
||||
gids = [last];
|
||||
edit_get_objs();
|
||||
}
|
||||
hide_menus();
|
||||
}
|
||||
|
||||
function obj_del(){
|
||||
function obj_del(id){
|
||||
// let select = document.getElementById("group_select");
|
||||
let menu = document.getElementById("object_edit_menu");
|
||||
if (confirm(`вы точно хотите удалить ${menu.getAttribute("obj_name").split("/")[0]}?`)){
|
||||
$.post( "/admin/objects/delete", { id:menu.getAttribute(`obj_id`),})
|
||||
let menu = document.getElementById(`object_${id}`);
|
||||
if (confirm(`вы точно хотите удалить ${menu.getAttribute("name").split("/")[0]}?`)){
|
||||
$.post( "/admin/objects/delete", { id:id,})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
edit_get_objs();
|
||||
@ -87,9 +95,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
function save_edited_obj(){
|
||||
function save_edited_obj(id){
|
||||
let gid = gids[0];
|
||||
let menu = document.getElementById("object_edit_menu");
|
||||
let menu = document.getElementById(`object_${id}`);
|
||||
let attributes = ["name","description","img","height","width","cost"];
|
||||
let cur_atts = {
|
||||
name : document.getElementById("nobj_name").value,
|
||||
@ -116,16 +124,16 @@
|
||||
}
|
||||
});
|
||||
function check_change(element){
|
||||
if(element == "name" && cur_atts[element] != menu.getAttribute(`obj_${element}`).split("/")[0]){
|
||||
if(element == "name" && cur_atts[element] != menu.getAttribute(`${element}`).split("/")[0]){
|
||||
changes[element] = cur_atts[element];
|
||||
}
|
||||
else if (element != "name" && cur_atts[element] != menu.getAttribute(`obj_${element}`)){
|
||||
else if (element != "name" && cur_atts[element] != menu.getAttribute(`${element}`)){
|
||||
changes[element] = cur_atts[element];
|
||||
}
|
||||
}
|
||||
function make_obj_save(){
|
||||
load_group(gid,(group_db)=>{
|
||||
if(changes["name"]) changes["name"] = (changes["name"]+"/g/"+group_db["name"].replace(" ","$"));
|
||||
if(changes["name"]) changes["name"] = (changes["name"]+"/g/"+group_db["name"].replaceAll(" ","$"));
|
||||
document.getElementById("obj_resp").innerHTML = "сохранение товара";
|
||||
$.post( "/admin/objects/edit", { id:menu.getAttribute(`obj_id`),changes:JSON.stringify(changes),gid:gid})
|
||||
.done(function( res ) {
|
||||
@ -178,7 +186,7 @@
|
||||
else{
|
||||
let name = ask("название");
|
||||
if(name != "")[
|
||||
$.post( "/admin/objects/find", { name:name.replace(" ","$")})
|
||||
$.post( "/admin/objects/find", { name:name.replaceAll(" ","$")})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
@ -194,11 +202,12 @@
|
||||
let obj = document.createElement('div');
|
||||
let name_text = document.createElement('div');
|
||||
let img_elm = document.createElement('img');
|
||||
obj.title = `название:${value["name"].split("/")[0].replace("$"," ")}\nцена:${value["cost"]}\nширена:${value["width"]}\nвысота${value["height"]}\nописание:${value["description"]}`;
|
||||
obj.id = "object_menu";
|
||||
obj.title = `название:${value["name"].split("/")[0].replaceAll("$"," ")}\nцена:${value["cost"]}\nширина:${value["width"]}\nвысота${value["height"]}\nописание:${value["description"]}`;
|
||||
obj.id = `object_${value["id"]}`;
|
||||
obj.setAttribute("onclick",`set_edit(${value["id"]})`)
|
||||
obj.classList.add(value["name"]);
|
||||
obj.classList.add("object");
|
||||
obj.setAttribute("name",value["name"].split("/")[0].replace("$"," "))
|
||||
obj.setAttribute("name",value["name"].split("/")[0].replaceAll("$"," "))
|
||||
obj.setAttribute("description",value["description"])
|
||||
obj.setAttribute("src",img)
|
||||
obj.setAttribute("height",value["height"])
|
||||
@ -206,12 +215,12 @@
|
||||
obj.setAttribute("obj_id",value["id"])
|
||||
obj.setAttribute("cost",value["cost"])
|
||||
obj.setAttribute("gid",value["gid"])
|
||||
name_text.innerText = value["name"].split("/")[0].replace("$"," ");
|
||||
name_text.innerText = value["name"].split("/")[0].replaceAll("$"," ");
|
||||
img_elm.src = img;
|
||||
obj.append(img_elm)
|
||||
obj.append(name_text)
|
||||
obj_list.append(obj)
|
||||
|
||||
console.log("obj");
|
||||
// console.log("obj");
|
||||
}
|
||||
</script>
|
@ -4,13 +4,19 @@
|
||||
/* height: 5vh; */
|
||||
margin: auto 0px;
|
||||
}
|
||||
#obj_group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.obj_group{
|
||||
display: flex;
|
||||
}
|
||||
</style>
|
||||
<div id="obj_group">
|
||||
<div style="display: flex;justify-content: space-between;">
|
||||
<h1>группы товаров</h1>
|
||||
<div style="display: block;">
|
||||
<h1>группы товаров</h1>
|
||||
<button onclick="create_new_part()">доб. раздел</button>
|
||||
</div>
|
||||
<style>
|
||||
.group_drop{
|
||||
width: 15vw;
|
||||
@ -47,24 +53,9 @@
|
||||
<script>
|
||||
// load_groups();
|
||||
function delete_group(gid,pid) {
|
||||
let select = document.getElementById("group_select");
|
||||
if(confirm(`вы уверены вы хотите удалить группу ${document.getElementById("obj_group_"+gid).innerText}`) == true){
|
||||
let name = document.getElementById("obj_group_"+gid).getAttribute("group_name");
|
||||
if(confirm(`вы уверены вы хотите удалить группу ${name}`) == true){
|
||||
$.post( "/admin/groups/delete", { gid:gid,pid:pid})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
// load_groups();
|
||||
edit_get_objs();
|
||||
hide_menus();
|
||||
alert(`группа удалена`)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function create_new_group(pid) {
|
||||
let group_name = ask("название группы");
|
||||
if(group_name != ""){
|
||||
$.post( "/admin/groups/new", { name:group_name.replace(" ","$"),pid:pid})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
@ -73,8 +64,44 @@
|
||||
hide_menus();
|
||||
setTimeout(()=>{
|
||||
parts_load();
|
||||
alert(`группа ${group_name.replace(" ","$")} создана`)
|
||||
},200)
|
||||
alert(`группа ${name} удалена`)
|
||||
},500)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function create_new_group(pid) {
|
||||
let group_name = ask("название группы");
|
||||
if(group_name != null && group_name != ""){
|
||||
$.post( "/admin/groups/new", { name:group_name.replaceAll(" ","$"),pid:pid})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
// load_groups();
|
||||
edit_get_objs();
|
||||
hide_menus();
|
||||
setTimeout(()=>{
|
||||
parts_load();
|
||||
alert(`группа ${group_name.replaceAll(" ","$")} создана`)
|
||||
},500)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function create_new_part() {
|
||||
let part_name = ask("название раздела");
|
||||
if(part_name != null && part_name != ""){
|
||||
$.post( "/admin/parts/new", { name:part_name.replaceAll(" ","$")})
|
||||
.done(function( res ) {
|
||||
if(res["out"] == "good"){
|
||||
// console.log(res["body"]);
|
||||
// load_groups();
|
||||
hide_menus();
|
||||
setTimeout(()=>{
|
||||
parts_load();
|
||||
alert(`раздел ${part_name.replaceAll(" ","$")} создан`)
|
||||
},500)
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -92,12 +119,13 @@
|
||||
part_drop.src = "/img/drop.png";
|
||||
part_drop.alt = "\/";
|
||||
|
||||
part_text.innerText = `${value["name"]}`;
|
||||
part_text.innerText = `${value["name"].replaceAll("$", " ")}`;
|
||||
|
||||
part.id = `group_drop-${value["id"]}`;
|
||||
part.classList.add("menu_btn")
|
||||
part.classList.add("group_drop")
|
||||
part.setAttribute("groups",`${value["groups"]}`)
|
||||
part.setAttribute("count",`${value["count"]}`)
|
||||
part.setAttribute("pid",`${value["id"]}`)
|
||||
|
||||
part.append(part_text);
|
||||
|
Reference in New Issue
Block a user