puzzle/public/lib/fn.js
n0rdye 5133931122 modified: index.js
modified:   object.js
	modified:   project.js
	new file:   public/img/background/photo_2023-06-06_08-53-47 1.png
	new file:   public/img/icon/copy.svg
	new file:   public/img/icon/download.svg
	new file:   public/img/icon/edit.svg
	new file:   public/img/icon/save.svg
	new file:   public/img/icon/trash.svg
	new file:   public/img/new_proj.png
	new file:   public/img/ok.svg
	new file:   public/img/telegram.svg
	new file:   public/img/vk.svg
	new file:   public/img/youtube.svg
	new file:   "public/img/\320\243\320\274\320\275\320\270\321\207\320\272\320\260 \320\273\320\276\320\263\320\276 \321\201 \320\276\320\261\320\262\320\276\320\264\320\272\320\276\320\271-02 1.png"
	modified:   public/lib/fn.js
	modified:   public/lib/inter.js
	modified:   user.js
	modified:   views/admin.ejs
	modified:   views/header.ejs
	new file:   views/load.ejs
	modified:   views/login.ejs
	modified:   views/main.ejs
	new file:   views/old/project.ejs
	modified:   views/project.ejs
	modified:   views/static/end.ejs
	modified:   views/static/start.ejs
2023-08-01 20:20:43 +05:00

150 lines
3.8 KiB
JavaScript

function get_from_uuid(callback){
const uid = $.cookie("uuid");
const sid = $.cookie("sid");
$.post( "/get_cr_uuid", { uuid:uid,sid:sid })
.done(function( res ) {
if (res["out"] == "good"){
// console.log("good");
callback(res["body"])
}
});
}
function set_pos(obj,x,y){
obj.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
obj.setAttribute('data-x', x)
obj.setAttribute('data-y', y)
}
function log_by_sid() {
// const uuid = $.cookie("uuid");
// const sid = $.cookie("sid");
// console.log("log");
if($.cookie('sid') == null){
// get_sid(location.hostname);
get_sid();
}
else if ($.cookie('sid') != null && $.cookie('uuid') != null){
$.post( "/sid_log")
.done(function( res ) {
// console.log("ping");
if(res["out"] == "good"){
goto(res["url"]);
}
else if (res["out"] == "bad"){
clear_ck(false);
}
})}
}
function clear_ck(redirect = true){
let uuid = $.cookie("uuid");
let sid = $.cookie("sid");
$.removeCookie("uuid");
$.removeCookie('sid');
// console.log("sid");
setTimeout(()=>{
$.post( "/clear_sid",{uuid:uuid,sid:sid})
.done(function( res ) {
// console.log("sid");
if(res["out"] == "good"){
// get_sid();
if (redirect) goto("/login");
}
// console.log("clear");
})
},100)
}
function check_sid(redirect = true){
// console.log("checking sid");
if($.cookie('sid') == null || $.cookie('uuid') == null){
clear_ck(redirect);
}
else{
$.post( "/sid_log")
.done(function( res ) {
if(res["out"] == "bad"){
clear_ck(redirect);
}
})
}
}
function logout(redirect = true) {
let dialog = confirm(`выйти?`);
if(dialog){
clear_ck(redirect);
}
}
function ask(text,def = "") {
let name = prompt(text,def);
if(name != "" && name != " "){
return name;
}
}
function get_sid(){
$.post( "/get_sid", {})
.done(function( res ) {
// if(res["out"] == "good"){
// console.log(res["body"]);
// }
});
}
function load_groups(callback){
let select = document.getElementById("group_select");
// let name = select.options[select.selectedIndex].text;
$.post( "/get_groups")
.done(function( res ) {
if(res["out"] == "good"){
select.innerHTML = "";
res["body"].forEach(group => {
let group_div = document.createElement("option");
group_div.innerText = group["name"].replace("$"," ");
group_div.setAttribute("group_count",group["count"]);
group_div.setAttribute("gid",group["id"]);
group_div.id = `obj_group_${group["id"]}`;
select.append(group_div);
if(group["id"] == res["body"].at(-1)["id"]){
if(callback)callback();
}
});
}
// callback(res);
});
}
// redirect
function goto(url) {
loading();
setTimeout(()=>{
location.href = url;
},1000)
}
function postForm(path, params, method) {
method = method || 'post';
var form = document.createElement('form');
form.setAttribute('method', method);
form.setAttribute('action', path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
var hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}