fix: création fichier/dossier instantanée sans refresh de page
Avant: doCreate() appelait _reloadAfterAction() → page reload → le nouvel élément ne s'affichait pas immédiatement dans l'arbre. Après: insertion AJAX du nouveau node dans this.tree via _insertIntoParent(). Le parent est auto-expandé. displayTree mis à jour si aucun filtre actif. Plus besoin de refresh. Reste reload pour rename/delete/upload (complexité renderChildren).
This commit is contained in:
@@ -668,13 +668,52 @@ document.addEventListener('alpine:init', function() {
|
|||||||
body:JSON.stringify(body)
|
body:JSON.stringify(body)
|
||||||
});
|
});
|
||||||
if (r.ok) {
|
if (r.ok) {
|
||||||
|
var d = await r.json();
|
||||||
this.showCreate = false;
|
this.showCreate = false;
|
||||||
this.parentFolder = null;
|
this.parentFolder = null;
|
||||||
this.newName = '';
|
this.newName = '';
|
||||||
this._reloadAfterAction();
|
// Insert new node into tree without reload
|
||||||
|
var isFolder = this.createType === 'folder';
|
||||||
|
var newNode = {
|
||||||
|
id: d.id, db_id: d.id, name: d.name || n,
|
||||||
|
is_folder: isFolder, type: isFolder ? 'folder' : 'page',
|
||||||
|
content_format: isFolder ? null : 'blocks',
|
||||||
|
children: [], has_children: false, depth: 0
|
||||||
|
};
|
||||||
|
if (this.parentFolder && this.parentFolder.db_id) {
|
||||||
|
// Insert as child of parent folder
|
||||||
|
this._insertIntoParent(this.tree, this.parentFolder.db_id, newNode);
|
||||||
|
// Auto-expand parent so the new item is visible
|
||||||
|
this.expanded[this.parentFolder.db_id] = true;
|
||||||
|
this.expanded = Object.assign({}, this.expanded);
|
||||||
|
} else {
|
||||||
|
// Insert at root
|
||||||
|
this.tree.unshift(newNode);
|
||||||
|
}
|
||||||
|
// Update displayTree
|
||||||
|
if (!this.searchQuery && !this.filterType) {
|
||||||
|
this.displayTree = this.tree;
|
||||||
|
}
|
||||||
|
this._saveExpandedState();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_insertIntoParent(nodes, parentId, newNode) {
|
||||||
|
for (var i=0; i<nodes.length; i++) {
|
||||||
|
if (nodes[i].id === parentId) {
|
||||||
|
if (!nodes[i].children) nodes[i].children = [];
|
||||||
|
nodes[i].children.unshift(newNode);
|
||||||
|
nodes[i].has_children = true;
|
||||||
|
newNode.depth = (nodes[i].depth || 0) + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (nodes[i].children && this._insertIntoParent(nodes[i].children, parentId, newNode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
openPage(id) { window.location = '/pages/'+id; },
|
openPage(id) { window.location = '/pages/'+id; },
|
||||||
|
|
||||||
startRename(node) {
|
startRename(node) {
|
||||||
|
|||||||
Reference in New Issue
Block a user