2019-06-02 07:32:36 +00:00
|
|
|
function insertNewURL() {
|
2019-01-26 22:34:48 +00:00
|
|
|
var url = document.getElementById ( "form-url" ).value;
|
|
|
|
var xhr = new XMLHttpRequest ( );
|
2019-02-07 11:36:44 +00:00
|
|
|
xhr.open ( "POST", 'insert', true );
|
2019-01-26 22:34:48 +00:00
|
|
|
xhr.onreadystatechange = function ( ) {
|
2019-06-02 07:27:47 +00:00
|
|
|
if ( xhr.status == 200 ) {
|
|
|
|
if ( xhr.readyState == XMLHttpRequest.DONE ) {
|
2019-01-26 22:34:48 +00:00
|
|
|
var response = xhr.responseText;
|
|
|
|
response = JSON.parse ( response );
|
|
|
|
if ( response [ 'status' ] == 200 ) {
|
|
|
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'message' ];
|
2019-06-02 07:27:47 +00:00
|
|
|
setTimeout( function( ) {
|
|
|
|
document.getElementById ( 'responsetext' ).innerHTML = ""
|
|
|
|
}, 1500 );
|
2019-01-26 22:34:48 +00:00
|
|
|
var div = document.createElement ( 'div' );
|
2019-06-16 04:11:47 +00:00
|
|
|
div.classList.add ( "urlContainer" );
|
|
|
|
div.appendChild ( document.createElement ( 'text' ) );
|
|
|
|
div.appendChild ( document.createElement ( 'div' ) );
|
|
|
|
div.childNodes [ 1 ].classList.add ( "urlId" );
|
|
|
|
div.childNodes [ 1 ].innerHTML = response [ 'last_insert' ];
|
|
|
|
div.appendChild ( document.createElement ( 'text' ) );
|
|
|
|
div.appendChild ( document.createElement ( 'input' ) );
|
|
|
|
div.childNodes [ 3 ].type = 'text';
|
|
|
|
div.childNodes [ 3 ].classList.add ( "urlLink" );
|
|
|
|
div.childNodes [ 3 ].setAttribute ( 'value', url );
|
|
|
|
div.appendChild ( document.createElement ( 'text' ) );
|
|
|
|
div.appendChild ( document.createElement ( 'div' ) );
|
|
|
|
div.childNodes [ 5 ].classList.add ( "urlControl" );
|
|
|
|
div.childNodes [ 5 ].setAttribute ( 'style', "display: none;" );
|
|
|
|
div.childNodes [ 5 ].appendChild ( document.createElement ( 'text' ) );
|
|
|
|
div.childNodes [ 5 ].appendChild ( document.createElement ( 'button' ) );
|
|
|
|
div.childNodes [ 5 ].childNodes [ 1 ].innerHTML = "<i class=\"fas fa-check\"></i>";
|
|
|
|
div.childNodes [ 5 ].appendChild ( document.createElement ( 'text' ) );
|
|
|
|
div.childNodes [ 5 ].appendChild ( document.createElement ( 'button' ) );
|
|
|
|
div.childNodes [ 5 ].childNodes [ 3 ].innerHTML = "<i class=\"fas fa-times\"></i>";
|
|
|
|
makeURLEditable ( div.childNodes [ 3 ] );
|
|
|
|
document.getElementsByClassName ( "urlList" ) [ 0 ].appendChild ( div );
|
2019-01-26 22:34:48 +00:00
|
|
|
document.getElementById ( "form-url" ).value = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
|
2019-06-02 07:27:47 +00:00
|
|
|
setTimeout( function( ) {
|
|
|
|
document.getElementById ( 'responsetext' ).innerHTML = ""
|
|
|
|
}, 1500 );
|
2019-01-26 22:34:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 07:27:47 +00:00
|
|
|
else {
|
|
|
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
|
|
|
|
setTimeout( function( ) {
|
|
|
|
document.getElementById ( 'responsetext' ).innerHTML = ""
|
|
|
|
}, 1500 );
|
|
|
|
}
|
2019-01-26 22:34:48 +00:00
|
|
|
}
|
|
|
|
data = new FormData ( );
|
|
|
|
data.append('url', url);
|
|
|
|
xhr.send( data );
|
|
|
|
}
|
2019-06-02 12:46:51 +00:00
|
|
|
function editURL(node) {
|
|
|
|
var url = node.childNodes[3].value;
|
|
|
|
var url_id = node.childNodes[1].innerHTML
|
|
|
|
var xhr = new XMLHttpRequest ( );
|
|
|
|
xhr.open ( "POST", 'edit', true );
|
|
|
|
xhr.onreadystatechange = function ( ) {
|
|
|
|
if ( xhr.status == 200 ) {
|
|
|
|
if ( xhr.readyState == XMLHttpRequest.DONE ) {
|
|
|
|
var response = xhr.responseText;
|
|
|
|
response = JSON.parse ( response );
|
|
|
|
if ( response [ 'status' ] == 200 ) {
|
|
|
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'message' ];
|
|
|
|
setTimeout( function( ) {
|
|
|
|
document.getElementById ( 'responsetext' ).innerHTML = ""
|
|
|
|
}, 1500 );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
|
|
|
|
setTimeout( function( ) {
|
|
|
|
document.getElementById ( 'responsetext' ).innerHTML = ""
|
|
|
|
}, 1500 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
document.getElementById ( "responsetext" ).innerHTML = response [ 'error_message' ];
|
|
|
|
setTimeout( function( ) {
|
|
|
|
document.getElementById ( 'responsetext' ).innerHTML = ""
|
|
|
|
}, 1500 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data = new FormData ( );
|
|
|
|
data.append('url', url);
|
|
|
|
data.append('url_id', url_id);
|
|
|
|
xhr.send( data );
|
|
|
|
}
|
2019-06-16 04:11:47 +00:00
|
|
|
function makeURLEditable ( node ) {
|
|
|
|
node.onclick = function() {
|
|
|
|
var oldText = this.value;
|
|
|
|
this.parentNode.childNodes[5].style.display = "";
|
|
|
|
this.parentNode.childNodes[5].childNodes[1].onclick = function() {
|
|
|
|
editURL(this.parentNode.parentNode);
|
|
|
|
this.parentNode.style.display = "none";
|
|
|
|
}
|
|
|
|
this.parentNode.childNodes[5].childNodes[3].onclick = function() {
|
|
|
|
this.parentNode.parentNode.childNodes[3].value = oldText;
|
|
|
|
this.parentNode.style.display = "none";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 12:46:51 +00:00
|
|
|
(function(){
|
|
|
|
var URLs = document.getElementsByClassName("urlLink");
|
|
|
|
for(i=0;i<URLs.length;i++) {
|
2019-06-16 04:11:47 +00:00
|
|
|
makeURLEditable(URLs[i]);
|
2019-06-02 12:46:51 +00:00
|
|
|
}
|
|
|
|
})();
|