Topic: Ajax Requests from on?????
Hi,
Thanks for this code - truly excellent. However I am having some issues and it is probably down to my misunderstanding, so I hope you can point me the the right direction or give me a proper example.
I have no problem with performing actions on the file tree itself, such as removing, renaming, moving & copying nodes. I do want, however, to perform these actions on the actual files themselves so assumed that I create a new request to call a bit of php script but it appears that I am having timing issues in that the call sometimes get sent straight away and other times there is a delay. Example code is below and the question I have is - am I calling this in the right way and in the right place?
Many thanks
Peter
Code:
window.addEvent('domready',function(){
tree = new Mif.Tree({
container: $('mytree'),
open: true,
initialize: function(){
this.initSortable();
new Mif.Tree.KeyNav(this);
new Mif.Tree.Drag(this);
},
types: {
folder:{
openIcon: 'mif-tree-open-icon',
closeIcon: 'mif-tree-close-icon',
loadable: true
},
file:{
openIcon: 'mif-tree-file-open-icon',
closeIcon: 'mif-tree-file-close-icon'
},
loader:{
openIcon: 'mif-tree-loader-open-icon',
closeIcon: 'mif-tree-loader-close-icon',
DDnotAllowed: ['inside','after']
}
},
dfltType:'folder',
onRename: function(node, newName, oldName){
tree.unselect(node);
node.set({
property: {
name: newName
},
type: 'file',
data: {
abs_path: node.data.abs_path.replace(oldName,newName)
}
});
var req = new Request({
url: rootDir+"plugins/myupload/myupload_ajax.php",
data: { "f" : "mgRenameFile",
"b" : node.data.abs_path.replace(newName,oldName),
"c" : newName,
"d" : rootDir
},
onComplete: function(response) {
//alert(response);
var bits = response.split("|");
if(bits[0] == "Error") {
alert(bits[4]);
}
}
}).send();
tree.select(node);
},
onCopy: function(from, to, where, copy){
alert("copy");
if(from.getParent()==copy.getParent()){
copy.set({
property: {
name: 'copy '+from.name
}
});
}
},
onMove: function(from, to, where){
//alert("move from "+from.data.abs_path+" to "+to.data.abs_path);
var req = new Request({
method: "put",
url: rootDir+"plugins/myupload/myupload_ajax.php",
data: { "f" : "mgMoveFile",
"b" : from.data.abs_path,
"c" : to.data.abs_path,
"d" : rootDir
},
onComplete: function(response) {
//alert(response);
var bits = response.split("|");
$(previewText).set({html: bits[4]});
if(bits[0] == "Error") {
alert(bits[4]);
} else {
$(directoryField).set({html: bits[0].replace(rootDir,"")});
$(filePathField).set({html: bits[3]});
}
}
}).send();
}
});
tree.load({
url: rootDir+'plugins/myupload/getRoot.php'
});
tree.loadOptions=function(node){
return {
url: rootDir+'plugins/myupload/get_children.php',
data: {'abs_path': node.data.abs_path}
};
};
tree.addEvent('load', function(){
tree.root.toggle();
});
tree.wrapper.addEvent('keydown', function(event){
if(event.key!='delete') return;
var selected=tree.getSelected();
if(selected){
if(confirm('delete node?')){
$(previewMenuDiv).set({html: ""});
$(previewImage).set({html: ""});
selected.remove();
}
}
});
tree.addEvent('select',function(node){
//alert(node.data.abs_path);
var req = new Request({
method: "put",
url: rootDir+"plugins/myupload/myupload_ajax.php",
data: { "f" : "showPreview",
"b" : node.data.abs_path
},
onComplete: function(response) { $(loaderDiv).set({html: response}); completeAjaxRequest(tree,node); },
}).send();
});
});