cyrilleinvalides/choupas/www/admin/editor/scripts/dsfs.js

201 lines
5.6 KiB
JavaScript
Executable File

function DSFS(url) { // url : script de traitement,
// uploadmod : flashobject charger de l'upload de plusieurs fichiers
/* verification des dependances */
if (!xhrQuery || !xhrProc) {
alert('DSFS Erreur Fatale : Dependances non satisfaites');
return false;
}
/* variables d'initialisation */
this.gateway = url;
/* evenements */
this.onprogress = null;
this.onfileselect = null;
this.onfilesupload = null;
/* données internes */
this.files = new Array();
this.swf = null;
/* variables local */
var self = this;
/*****************************/
/* Methodes de configuration */
/*****************************/
this.setSWF = function (swf) {
this.swf = swf;
return swf;
}
/* appelée lors de l'évenement du flash object filReference onProgress */
this.onFileProgress = function (name, upped, total) {
this.files[name]['up'] = upped;
this.files[name]['total'] = total;
if (this.onprogress) this.onprogress(name, upped, total);
}
/********************/
/* Methodes Metiers */
/********************/
this.browseForUpload = function () {
if (!this.swf) {
alert("pas d'objet flash detecté !");
return false;
}
this.swf.parcourir();
return true;
}
function upload() {
if (!this.swf) {
alert("pas d'objet flash detecté !");
return false;
}
if (this.onfilesupload) this.onfilesupload();
this.swf.upload(this.gateway + "action=upload");
return true;
}
this.write = function (file, content, onsuccess, rmode) {
if (!rmode) rmode = 'bin';
var xhr = new xhrQuery(this.gateway + '?action=write', 'POST');
xhr.addPost('file', file);
xhr.addPost('content', content);
xhr.addPost('mode', rmode);
xhr.callback = function (respo) {
if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return file;
}
this.append = function (file, content, onsuccess, rmode) {
if (!rmode) rmode = 'bin';
var xhr = new xhrQuery(this.gateway + '?action=append', 'POST');
xhr.addPost('file', file);
xhr.addPost('content', content);
xhr.addPost('mode', rmode);
xhr.callback = function (respo) {
if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return file;
}
this.read = function (file, onsuccess, rmode) {
if (!rmode) rmode = 'bin';
var xhr = new xhrQuery(this.gateway + '?action=read', 'POST');
xhr.addPost('file', file);
xhr.addPost('mode', rmode);
xhr.callback = function (respo) {
// if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return file;
}
this.remove = function (file, onsuccess) {
var xhr = new xhrQuery(this.gateway + '?action=remove', 'POST');
xhr.addPost('file', file);
xhr.callback = function (respo) {
if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return file;
}
this.browse = function (dir, deep, onsuccess) {
var xhr = new xhrQuery(this.gateway + '?action=browse', 'POST');
xhr.addPost('dir', dir);
xhr.addPost('deep', deep);
xhr.callback = function (respo) {
// if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return true;
}
this.mkDir = function (dir, onsuccess) {
var xhr = new xhrQuery(this.gateway + '?action=mkdir', 'POST');
xhr.addPost('dir', dir);
xhr.callback = function (respo) {
if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\nErreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return true;
}
this.rename = function (oldname, newname, onsuccess) {
var xhr = new xhrQuery(this.gateway + '?action=rename', 'POST');
xhr.addPost('old', oldname);
xhr.addPost('new', newname);
xhr.callback = function (respo) {
if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return true;
}
this.move = function (from, to, onsuccess) {
var xhr = new xhrQuery(this.gateway + '?action=move', 'POST');
xhr.addPost('from', from);
xhr.addPost('to', to);
xhr.callback = function (respo) {
if (respo.text) return this.onerror("DSFS Erreur", respo.text);
if (onsuccess) onsuccess(respo);
return true;
}
xhr.onerror = function (status, statusText) {
alert(status + " : " + statusText + "\n Erreur lors de l'ecriture du fichier " + file + " .");
}
xhrProc.process(xhr);
return true;
}
}