2024-10-03 21:53:35 +03:00
function createModal ( id , type , value ) {
2024-10-05 14:16:39 +03:00
if ( type === 'EDIT_COMMENT' ) {
var modal = `
< div id = "modal`+id+`" class = "modal" style = "display: block;" >
< div class = "modal-content" >
< span data - modal - id = "`+id+`" class = "close" > & times ; < / s p a n >
< h3 > < b > Отредактировать комментарий < / b > < / h 3 >
< div style = "padding:0 11px 11px" >
2024-10-06 16:03:11 +03:00
< textarea style = " width : 100 % ;
height : 200 px ; " name=" wtext " id=" bodypost _ _commedit ` +id+ ` " > ` +value+ ` < / t e x t a r e a > < b r >
2024-10-05 14:16:39 +03:00
< p id = "statusSend" style = "display: none;" > Ошибка < / p >
< div class = "cmt-submit" >
< button type = "submit" onclick = "editComment('` + id + `', document.getElementById('bodypost__commedit` + id + `').value)" id = "sbmt" > Отредактировать < / b u t t o n > & e n s p ; & e m s p ; C t r l + E n t e r
< / d i v >
< / d i v >
< / d i v >
< / d i v > ` ;
}
document . body . innerHTML += modal ;
2024-10-01 06:31:32 +03:00
}
2024-10-05 14:16:39 +03:00
document . addEventListener ( "click" , function ( event ) {
if ( event . target . classList . contains ( "close" ) ) {
var modalId = event . target . getAttribute ( "data-modal-id" ) ;
document . getElementById ( "modal" + modalId ) . style . display = "none" ;
}
2024-10-01 06:31:32 +03:00
2024-10-05 14:16:39 +03:00
var modals = document . querySelectorAll ( ".modal" ) ;
modals . forEach ( function ( modal ) {
if ( event . target == modal ) {
modal . style . display = "none" ;
}
} ) ;
} ) ;
2024-10-01 06:31:32 +03:00
2024-10-05 14:16:39 +03:00
const editComment = ( postId , body ) => {
$ ( document ) . ready ( function ( ) {
$ . ajax ( {
type : "POST" ,
url : '/api/photo/comment/' + postId + '/edit' ,
data : JSON . stringify ( { "value" : body } ) ,
success : function ( response ) {
var jsonData = JSON . parse ( response ) ;
console . log ( response ) ;
if ( jsonData . errorcode == "1" ) {
Notify . noty ( 'danger' , JSON . stringify ( response ) ) ;
} else {
document . getElementById ( "modal" + postId ) . style . display = "none" ;
Notify . noty ( 'success' , 'Успешно отредактировано!' ) ;
const url = window . location . pathname ;
const segments = url . split ( '/' ) ;
const id = segments [ segments . length - 1 ] ;
$ . ajax ( {
type : "POST" ,
url : "/api/photo/getcomments/" + id ,
processData : false ,
async : true ,
success : function ( r ) {
$ ( '#posts' ) . html ( r )
} ,
error : function ( r ) {
console . log ( r )
}
} ) ;
}
}
} ) ;
} ) ;
}