try usng a promise
parent
35d375188e
commit
b39126fdd9
|
@ -123,20 +123,21 @@ function getCSSRule(rules) {
|
||||||
// We must create functions that do the requests to the webdav backend.
|
// We must create functions that do the requests to the webdav backend.
|
||||||
// this functions will contain a 'callback' to be used withing the other function.
|
// this functions will contain a 'callback' to be used withing the other function.
|
||||||
|
|
||||||
webdav.rename = function(oldLink, newLink, callback) {
|
webdav.move = function(oldLink, newLink) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
|
request.open('MOVE', toWebDavURL(oldLink), true);
|
||||||
request.open('MOVE', toWebDavURL(oldLink));
|
|
||||||
request.setRequestHeader('Destination', toWebDavURL(newLink));
|
request.setRequestHeader('Destination', toWebDavURL(newLink));
|
||||||
|
request.onload = () => {
|
||||||
|
if (request.status == 201 || request.status == 204) {
|
||||||
|
resolve(request.response);
|
||||||
|
} else {
|
||||||
|
reject(request.statusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request.onerror = () => reject(request.statusText);
|
||||||
request.send();
|
request.send();
|
||||||
request.onreadystatechange = function() {
|
});
|
||||||
if (request.readyState == 4) {
|
|
||||||
if (typeof callback == 'function') {
|
|
||||||
// This callback argument is a 'success'
|
|
||||||
callback(request.status == 201 || request.status == 204);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,21 +130,22 @@ listing.rename = function(event) {
|
||||||
let newName = event.currentTarget.querySelector('input').value,
|
let newName = event.currentTarget.querySelector('input').value,
|
||||||
newLink = removeLastDirectoryPartOf(link) + "/" + newName,
|
newLink = removeLastDirectoryPartOf(link) + "/" + newName,
|
||||||
html = buttons.rename.querySelector('i').changeToLoading();
|
html = buttons.rename.querySelector('i').changeToLoading();
|
||||||
|
closePrompt(event);
|
||||||
|
|
||||||
webdav.rename(link, newLink, success => {
|
webdav.move(link, newLink)
|
||||||
if (success) {
|
.then(data => {
|
||||||
listing.reload(() => {
|
listing.reload(() => {
|
||||||
newName = btoa(newName);
|
newName = btoa(newName);
|
||||||
selectedItems = [newName];
|
selectedItems = [newName];
|
||||||
document.getElementById(newName).setAttribute("aria-selected", true);
|
document.getElementById(newName).setAttribute("aria-selected", true);
|
||||||
listing.handleSelectionChange();
|
listing.handleSelectionChange();
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
item.querySelector('.name').innerHTML = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
closePrompt(event);
|
buttons.rename.querySelector('i').changeToDone(false, html);
|
||||||
buttons.rename.querySelector('i').changeToDone(!success, html);
|
})
|
||||||
|
.catch(error => {
|
||||||
|
item.querySelector('.name').innerHTML = name;
|
||||||
|
buttons.rename.querySelector('i').changeToDone(true, html);
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue