diff --git a/src/Yavsc/wwwroot/js/yavsc-remote-fs.js b/src/Yavsc/wwwroot/js/yavsc-remote-fs.js
index 6fb278bf..89202fad 100644
--- a/src/Yavsc/wwwroot/js/yavsc-remote-fs.js
+++ b/src/Yavsc/wwwroot/js/yavsc-remote-fs.js
@@ -17,8 +17,10 @@ if (typeof XMLHttpRequest === 'undefined') {
rmDialog: null,
mvDialog: null,
flist: null,
+ fmlist: null,
selection: [],
- dirBar: null,
+ curDirBar: null,
+ subDirsBar: null,
destination: null,
rootDisplay: null,
setRoot: function(sub) {
@@ -35,12 +37,13 @@ if (typeof XMLHttpRequest === 'undefined') {
this.setRoot(sub);
var owner = this.element.data('owner');
this.selection = [];
- this.dirBar.empty();
+ this.curDirBar.empty();
+ this.subDirsBar.empty();
$('')
.click(function () {
_this.openDir(null);
})
- .appendTo(this.dirBar);
+ .appendTo(this.curDirBar);
var npath = null
if (_this.root) {
@@ -52,49 +55,71 @@ if (typeof XMLHttpRequest === 'undefined') {
$('')
.append(part)
.click(function () {
- _this.OpenDir(npath);
+ _this.openDir(npath);
})
- .appendTo(this.dirBar);
+ .appendTo(_this.curDirBar);
});
}
+
this.ftable.find('tr.fileinfo').remove();
var fsiourl = this.root ? '/api/fs/' + this.root : '/api/fs';
$.get(fsiourl, function (data) {
- $.each(data.SubDirectories, function () {
- var item = this;
- var spath = _this.root ? _this.root + '/' + item.Name : item.Name;
- $('')
- .append(item.Name)
- .click(function () {
- _this.openDir(spath);
- })
- .appendTo(_this.dirBar);
- });
-
- $.each(data.Files, function () {
- var item = this;
- var $tr = $('
');
- var $td = $(' | ');
- $td.appendTo($tr);
- $('')
- .addClass('check-box')
- .click(function () {
- _this.SetItemSelected(item.Name, this.checked);
- })
- .appendTo($td);
+ if (data.SubDirectories.length == 0 && data.Files.length == 0)
+ {
+ $('').click(
+ function() {
+ var xmlhttp = new XMLHttpRequest();
+ xmlhttp.open('DELETE', '/api/fs/' + _this.root, true);
+ xmlhttp.send();
- $(' | ')
- .append($('')
+ xmlhttp.onreadystatechange = function(event) {
+ // XMLHttpRequest.DONE === 4
+ if (this.readyState === XMLHttpRequest.DONE) {
+ if (this.status === 200) {
+ var dnames = _this.root.split('/');
+ var dcnt = dnames.length;
+ var nroot = dnames.slice(0,dcnt-1).join('/');
+ _this.openDir(nroot);
+ }
+ }
+ }
+ }).appendTo(_this.subDirsBar);
+ }
+ else
+ {
+ $.each(data.SubDirectories, function () {
+ var item = this;
+ var spath = _this.root ? _this.root + '/' + item.Name : item.Name;
+ $('')
.append(item.Name)
.click(function () {
- if (_this.root) document.location = '/' + owner + '/' + _this.root + '/' + item.Name;
- else document.location = '/files/' + owner + '/' + item.Name;
- })).appendTo($tr);
- $('' + item.Size + ' | ').appendTo($tr);
- $('' + item.LastModified + ' | ').appendTo($tr);
- $tr.appendTo(_this.ftable);
- });
+ _this.openDir(spath);
+ })
+ .appendTo(_this.subDirsBar);
+ });
+
+ $.each(data.Files, function () {
+ var item = this;
+ var $tr = $('
');
+ var $td = $(' | ');
+ $td.appendTo($tr);
+ $('')
+ .addClass('check-box')
+ .click(function () {
+ _this.SetItemSelected(item.Name, this.checked);
+ })
+ .appendTo($td);
+ var furl = (_this.root) ? '/files/' + owner + '/' + _this.root + '/' + item.Name
+ : '/files/' + owner + '/' + item.Name;
+ $(' | ')
+ .append($('').attr('href',furl)
+ .append(item.Name)).appendTo($tr);
+ $('' + item.Size + ' | ').appendTo($tr);
+ $('' + item.LastModified + ' | ').appendTo($tr);
+ $tr.appendTo(_this.ftable);
+ });
+ }
});
},
SetItemSelected: function (name, selected) {
@@ -106,26 +131,43 @@ if (typeof XMLHttpRequest === 'undefined') {
});
}
},
+ setFileAway: function(fname)
+ {
+ this.selection = this.selection.filter(function (ele) {
+ return ele !== fname;
+ });
+ this.ftable.find('tr.fileinfo').filter(function () {
+ return $(this).children('td:nth-child(2)').text() == fname;
+ }).remove();
+ },
RemoveSelectedFiles: function () {
+ var _this = this;
$.each(this.selection, function () {
+ var dfile = this;
+ var dfilep = _this.root ? _this.root + '/' + this : this;
var xmlhttp = new XMLHttpRequest();
- xmlhttp.open('DELETE', '/api/fs/' + this, true);
+ xmlhttp.onreadystatechange = function(event) {
+ if (this.readyState === XMLHttpRequest.DONE) {
+ if (this.status === 200) {
+ _this.setFileAway(dfile);
+ }
+ else {
+ alert( 'deletion of : ' + dfile + 'failed : '+ this.statusText );
+ }
+ }
+ };
+ xmlhttp.open('DELETE', '/api/fs/' + dfilep, true);
xmlhttp.send();
});
- this.selection = [];
- // FIXME this could fail for a very long list of big files
- setTimeout(500, function () {
- this.openDir(this.root);
- });
},
moveSelectedFiles: function () {
var _this = this;
var dest = this.destination;
$.each(this.selection, function () {
+ var mfile = this;
var data = {};
- data['id'] = _this.root ? _this.root + '/' + this : this;
+ data['id'] = _this.root ? _this.root + '/' + mfile : mfile;
data['to'] = dest;
- console.log(data);
var request = $.ajax({
url: '/api/fsc/mvftd',
type: 'POST',
@@ -133,20 +175,14 @@ if (typeof XMLHttpRequest === 'undefined') {
contentType: 'application/json;charset=utf-8'
});
- request.done(function( msg ) {
- $( "#log" ).html( msg );
+ request.done(function() {
+ _this.setFileAway(mfile);
});
request.fail(function( jqXHR, textStatus, msg ) {
- alert( 'Request failed: ' + textStatus );
- $( '#log' ).html( msg );
+ alert( 'Failed to move : ' + mfile + ' : ' + textStatus );
});
});
- this.selection = [];
- // FIXME this could fail for a very long list of big files
- setTimeout(500, function () {
- this.openDir(this.root);
- });
},
askForRemoval: function () {
this.flist.empty();
@@ -157,10 +193,10 @@ if (typeof XMLHttpRequest === 'undefined') {
this.rmDialog.modal({ show: true });
},
askForMoving: function () {
- this.flist.empty();
+ this.fmlist.empty();
var _this = this;
$.each(this.selection, function () {
- _this.flist.append('' + this + '');
+ _this.fmlist.append('' + this + '');
});
this.mvDialog.modal({ show: true });
},
@@ -212,8 +248,8 @@ if (typeof XMLHttpRequest === 'undefined') {
mdCnt.append(mdHeader);
var mdBody = $('');
mdBody.append('You´re about to move these files :
');
- this.flist = $('');
- mdBody.append(this.flist);
+ this.fmlist = $('');
+ mdBody.append(this.fmlist);
var inputDest = $('').on('change', function() { _this.onDestinationChanged(this); });
this.rootDisplay = $('');
this.rootDisplay.addClass('hidden');
@@ -236,9 +272,11 @@ if (typeof XMLHttpRequest === 'undefined') {
_create: function () {
var $view = this.element;
var _this = this;
- this.dirBar = $('');
- this.dirBar.appendTo($view);
- this.ftable = $('')
+ this.curDirBar = $('');
+ this.curDirBar.appendTo($view);
+ this.subDirsBar = $('');
+ this.subDirsBar.appendTo($view);
+ this.ftable = $('')
.css('border-spacing', '6px')
.css('border-collapse', 'separate');
var btnRm = $('').click(function () {
@@ -251,7 +289,6 @@ if (typeof XMLHttpRequest === 'undefined') {
_this.ftable.append(tr);
tr.append($(' | ').append(btnRm).append(btnMv)).append('Nom | Taille | Modification | ');
_this.ftable.appendTo($view);
- $('Logs
').appendTo($view);
this.createRmDialog();
this.createMvDialog();
this.openDir($view.data('path'));