implements the file moves ui

This commit is contained in:
2019-09-08 05:17:21 +01:00
parent a727ee1f49
commit 9e3f0ecd0a
7 changed files with 353 additions and 174 deletions

View File

@ -60,6 +60,12 @@ namespace Yavsc.Helpers
UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, userName, subdir); UserDirectoryInfo di = new UserDirectoryInfo(UserFilesDirName, userName, subdir);
return di; return di;
} }
public static bool IsRegularFile(string userName, string subdir)
{
FileInfo fi = new FileInfo( Path.Combine(Path.Combine(UserFilesDirName, userName), subdir));
return fi.Exists;
}
// Server side only supports POSIX file systems // Server side only supports POSIX file systems
public const char RemoteDirectorySeparator = '/'; public const char RemoteDirectorySeparator = '/';

View File

@ -1,7 +1,18 @@
namespace Yavsc.Helpers namespace Yavsc.Helpers
{ {
public enum ErrorCode {
NotFound,
InternalError,
DestExists,
InvalidRequest
}
public class FsOperationInfo { public class FsOperationInfo {
public bool Done { get; set; } = false; public bool Done { get; set; } = false;
public string Error { get; set; }
public ErrorCode ErrorCode { get; set; }
public string ErrorMessage { get; set; }
} }
} }

View File

@ -15,13 +15,14 @@ namespace Yavsc.ApiControllers
using Yavsc.Models.FileSystem; using Yavsc.Models.FileSystem;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Yavsc.Attributes.Validation; using Yavsc.Attributes.Validation;
using System.IO;
[Authorize,Route("api/fs")] [Authorize,Route("api/fs")]
public class FileSystemApiController : Controller public partial class FileSystemApiController : Controller
{ {
ApplicationDbContext dbContext; ApplicationDbContext dbContext;
private IAuthorizationService AuthorizationService; private IAuthorizationService AuthorizationService;
private ILogger logger; private ILogger _logger;
public FileSystemApiController(ApplicationDbContext context, public FileSystemApiController(ApplicationDbContext context,
IAuthorizationService authorizationService, IAuthorizationService authorizationService,
@ -30,7 +31,7 @@ namespace Yavsc.ApiControllers
{ {
AuthorizationService = authorizationService; AuthorizationService = authorizationService;
dbContext = context; dbContext = context;
logger = loggerFactory.CreateLogger<FileSystemApiController>(); _logger = loggerFactory.CreateLogger<FileSystemApiController>();
} }
[HttpGet()] [HttpGet()]
@ -61,24 +62,24 @@ namespace Yavsc.ApiControllers
pathex = ex; pathex = ex;
} }
if (pathex!=null) { if (pathex!=null) {
logger.LogError($"invalid sub path: '{subdir}'."); _logger.LogError($"invalid sub path: '{subdir}'.");
return HttpBadRequest(pathex); return HttpBadRequest(pathex);
} }
logger.LogInformation($"Receiving files, saved in '{destDir}' (specified as '{subdir}')."); _logger.LogInformation($"Receiving files, saved in '{destDir}' (specified as '{subdir}').");
var uid = User.GetUserId(); var uid = User.GetUserId();
var user = dbContext.Users.Single( var user = dbContext.Users.Single(
u => u.Id == uid u => u.Id == uid
); );
int i=0; int i=0;
logger.LogInformation($"Receiving {Request.Form.Files.Count} files."); _logger.LogInformation($"Receiving {Request.Form.Files.Count} files.");
foreach (var f in Request.Form.Files) foreach (var f in Request.Form.Files)
{ {
var item = user.ReceiveUserFile(destDir, f); var item = user.ReceiveUserFile(destDir, f);
dbContext.SaveChanges(User.GetUserId()); dbContext.SaveChanges(User.GetUserId());
received.Add(item); received.Add(item);
logger.LogInformation($"Received '{item.FileName}'."); _logger.LogInformation($"Received '{item.FileName}'.");
if (item.QuotaOffensed) if (item.QuotaOffensed)
break; break;
i++; i++;
@ -100,42 +101,54 @@ namespace Yavsc.ApiControllers
return Ok(len); return Ok(len);
} }
[Route("/api/fsc/movefile")] [HttpPost]
[Route("/api/fsc/mvftd")]
[Authorize()] [Authorize()]
public IActionResult MoveFile([ValidRemoteUserFilePath] string from, [ValidRemoteUserFilePath] string to) public IActionResult MoveFile([FromBody] RenameFileQuery query)
{ {
if (!ModelState.IsValid) return new BadRequestObjectResult(ModelState); if (!ModelState.IsValid) return new BadRequestObjectResult(ModelState);
var uid = User.GetUserId(); var uid = User.GetUserId();
var user = dbContext.Users.Single( var user = dbContext.Users.Single(
u => u.Id == uid u => u.Id == uid
); );
var info = user.MoveUserFile(from, to); var info = user.MoveUserFileToDir(query.id, query.to);
if (!info.Done) if (!info.Done) return new BadRequestObjectResult(info);
return new BadRequestObjectResult(info);
return Ok(); return Ok();
} }
[HttpPatch] [HttpPost]
[Route("/api/fsc/movedir")] [Route("/api/fsc/mvf")]
[Authorize()] [Authorize()]
public IActionResult MoveDir([ValidRemoteUserFilePath] string from,[ValidRemoteUserFilePath] string to) public IActionResult RenameFile([FromBody] RenameFileQuery query)
{ {
if (!ModelState.IsValid) return new BadRequestObjectResult(ModelState); if (!ModelState.IsValid) {
var idvr = new ValidRemoteUserFilePathAttribute();
return this.HttpBadRequest(new { id = idvr.IsValid(query.id), to = idvr.IsValid(query.to), errors = ModelState });
}
_logger.LogInformation($"Valid move query: {query.id} => {query.to}");
var uid = User.GetUserId(); var uid = User.GetUserId();
var user = dbContext.Users.Single( var user = dbContext.Users.Single(
u => u.Id == uid u => u.Id == uid
); );
try { try {
var result = user.MoveUserDir(from, to); if (Startup.UserFilesOptions.FileProvider.GetFileInfo(Path.Combine(user.UserName, query.id)).Exists)
if (!result.Done) {
return new BadRequestObjectResult(result); var result = user.MoveUserFile(query.id, query.to);
if (!result.Done) return new BadRequestObjectResult(result);
}
else {
var result = user.MoveUserDir(query.id, query.to);
if (!result.Done) return new BadRequestObjectResult(result);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
return new BadRequestObjectResult( return new BadRequestObjectResult(
new FsOperationInfo { new FsOperationInfo {
Done = false, Done = false,
Error = ex.Message ErrorCode = ErrorCode.InternalError,
ErrorMessage = ex.Message
}); });
} }
return Ok(); return Ok();
@ -161,7 +174,8 @@ namespace Yavsc.ApiControllers
return new BadRequestObjectResult( return new BadRequestObjectResult(
new FsOperationInfo { new FsOperationInfo {
Done = false, Done = false,
Error = ex.Message ErrorCode = ErrorCode.InternalError,
ErrorMessage = ex.Message
}); });
} }
return Ok(new { deleted=id }); return Ok(new { deleted=id });

View File

@ -0,0 +1,23 @@
using Yavsc.Attributes.Validation;
namespace Yavsc.Models.FileSystem
{
public class RenameFileQuery {
[ValidRemoteUserFilePath]
[YaStringLength(1, 512)]
public string id { get; set; }
[YaStringLength(0, 512)]
[ValidRemoteUserFilePath]
public string to { get; set; }
}
public class MoveFileQuery {
[ValidRemoteUserFilePath]
[YaStringLength(1, 512)]
public string id { get; set; }
[YaStringLength(0, 512)]
[ValidRemoteUserFilePath]
public string to { get; set; }
}
}

View File

@ -108,18 +108,18 @@ namespace Yavsc.Helpers
{ {
var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName); var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName);
if (string.IsNullOrEmpty(dirName)) if (string.IsNullOrEmpty(dirName))
return new FsOperationInfo { Done = false, Error = "specify a directory or file name"} ; return new FsOperationInfo { Done = false, ErrorCode = ErrorCode.InvalidRequest, ErrorMessage = "specify a directory or file name"} ;
var di = new DirectoryInfo(Path.Combine(root, dirName)); var di = new DirectoryInfo(Path.Combine(root, dirName));
if (!di.Exists) { if (!di.Exists) {
var fi = new FileInfo(Path.Combine(root, dirName)); var fi = new FileInfo(Path.Combine(root, dirName));
if (!fi.Exists) return new FsOperationInfo { Done = false, Error = "non existent"} ; if (!fi.Exists) return new FsOperationInfo { Done = false, ErrorCode = ErrorCode.NotFound, ErrorMessage = "non existent"} ;
fi.Delete(); fi.Delete();
user.DiskUsage -= fi.Length; user.DiskUsage -= fi.Length;
} }
else { else {
if (di.GetDirectories().Length>0 || di.GetFiles().Length>0) if (di.GetDirectories().Length>0 || di.GetFiles().Length>0)
return new FsOperationInfo { Done = false, Error = "not eñpty"} ; return new FsOperationInfo { Done = false, ErrorCode = ErrorCode.InvalidRequest, ErrorMessage = "dir is not empty, refusing to remove it"} ;
di.Delete(); di.Delete();
} }
return new FsOperationInfo { Done = true }; return new FsOperationInfo { Done = true };
@ -129,36 +129,49 @@ namespace Yavsc.Helpers
{ {
var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName); var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName);
if (string.IsNullOrEmpty(fromDirName)) if (string.IsNullOrEmpty(fromDirName))
return new FsOperationInfo { Done = false, Error = "fromDirName: specify a dir name "} ; return new FsOperationInfo { Done = false, ErrorCode = ErrorCode.InvalidRequest , ErrorMessage = "specify a dir name "} ;
var di = new DirectoryInfo(Path.Combine(root, fromDirName)); var di = new DirectoryInfo(Path.Combine(root, fromDirName));
if (!di.Exists) return new FsOperationInfo { Done = false, Error = "fromDirName: non existent"} ; if (!di.Exists) return new FsOperationInfo { Done = false, ErrorCode = ErrorCode.NotFound, ErrorMessage = "fromDirName: non existent"} ;
if (string.IsNullOrEmpty(toDirName)) if (string.IsNullOrEmpty(toDirName)) toDirName = ".";
return new FsOperationInfo { Done = false, Error = "toDirName: specify a dir name to move"} ;
var destPath = Path.Combine(root, toDirName); var destPath = Path.Combine(root, toDirName);
var fo = new FileInfo(destPath);
var fout = new FileInfo(destPath);
if (fout.Exists) return new FsOperationInfo { Done = false, ErrorCode = ErrorCode.InvalidRequest, ErrorMessage = "destination is a regular file" } ;
var dout = new DirectoryInfo(destPath); var dout = new DirectoryInfo(destPath);
if (fo.Exists) return new FsOperationInfo { Done = false, Error = "toDirName: yet a regular file" } ;
if (dout.Exists) { if (dout.Exists) {
destPath = Path.Combine(destPath, fo.Name); destPath = Path.Combine(destPath, dout.Name);
} }
di.MoveTo(destPath); di.MoveTo(destPath);
return new FsOperationInfo { Done = true }; return new FsOperationInfo { Done = true };
} }
public static FsOperationInfo MoveUserFileToDir(this ApplicationUser user, string fileNameFrom, string fileNameDest)
{
var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName);
var fi = new FileInfo(Path.Combine(root, fileNameFrom));
if (!fi.Exists) return new FsOperationInfo { ErrorCode = ErrorCode.NotFound, ErrorMessage = "no file to move" } ;
string dest;
if (!string.IsNullOrEmpty(fileNameDest)) dest = Path.Combine(root, fileNameDest);
else dest = root;
var fo = new FileInfo(dest);
if (fo.Exists) return new FsOperationInfo { ErrorCode = ErrorCode.DestExists , ErrorMessage = "destination file name is an existing file" } ;
var dout = new DirectoryInfo(dest);
if (!dout.Exists) dout.Create();
fi.MoveTo(Path.Combine(dout.FullName, fi.Name));
return new FsOperationInfo { Done = true };
}
public static FsOperationInfo MoveUserFile(this ApplicationUser user, string fileNameFrom, string fileNameDest) public static FsOperationInfo MoveUserFile(this ApplicationUser user, string fileNameFrom, string fileNameDest)
{ {
var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName); var root = Path.Combine(AbstractFileSystemHelpers.UserFilesDirName, user.UserName);
var fi = new FileInfo(Path.Combine(root, fileNameFrom)); var fi = new FileInfo(Path.Combine(root, fileNameFrom));
if (!fi.Exists) return new FsOperationInfo { Error = "no file to move" } ; if (!fi.Exists) return new FsOperationInfo { ErrorCode = ErrorCode.NotFound, ErrorMessage = "no file to move" } ;
var fo = new FileInfo(Path.Combine(root, fileNameDest)); var fo = new FileInfo(Path.Combine(root, fileNameDest));
if (fo.Exists) return new FsOperationInfo { Error = "destination file name is an existing file" } ; if (fo.Exists) return new FsOperationInfo { ErrorCode = ErrorCode.DestExists , ErrorMessage = "destination file name is an existing file" } ;
fi.MoveTo(fo.FullName); fi.MoveTo(fo.FullName);
return new FsOperationInfo { Done = true }; return new FsOperationInfo { Done = true };
} }

View File

@ -1,12 +0,0 @@
var constraints = { audio: true, video: false }
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
/* use the stream */
console.log("got stream!");
console.log(stream)
})
.catch(function(err) {
/* handle the error */
console.log(err)
});

View File

@ -3,134 +3,258 @@
if (typeof window.jQuery === 'undefined') { if (typeof window.jQuery === 'undefined') {
throw new Error('yavsc-remote-fs script requires jQuery'); throw new Error('yavsc-remote-fs script requires jQuery');
} }
if (typeof XMLHttpRequest === 'undefined') {
throw new Error('yavsc-remote-fs script requires XMLHttpRequest');
}
(function ($) { (function ($) {
$.widget('psc.yarfs', { 'use strict';
options: { $.widget('psc.yarfs', {
fsnurl: '/api/fs' options: {
}, fsnurl: '/api/fs'
root: null, },
rmAlert: null, root: null,
flist: null, rmDialog: null,
selection: [], mvDialog: null,
dirBar: null, flist: null,
openDir: function (sub) { selection: [],
var _this = this; dirBar: null,
this.root = sub; destination: null,
var owner = this.element.data('owner'); rootDisplay: null,
this.selection = []; setRoot: function(sub) {
this.dirBar.empty(); this.root = sub;
$('<button>' + owner + '</button>').click(function() { if (!this.root) this.rootDisplay.addClass('hidden');
_this.openDir(null); else
}).appendTo(this.dirBar); {
var npath = null; this.rootDisplay.removeClass('hidden');
this.rootDisplay.html('from <code>' + this.root + '</code>');
}
},
openDir: function (sub) {
var _this = this;
this.setRoot(sub);
var owner = this.element.data('owner');
this.selection = [];
this.dirBar.empty();
$('<button>' + owner + '</button>')
.click(function () {
_this.openDir(null);
})
.appendTo(this.dirBar);
var npath = null
if (_this.root) { if (_this.root) {
var dnames = _this.root.split('/'); var dnames = _this.root.split('/');
$.each(dnames, function () { $.each(dnames, function () {
var part = this; var part = this;
if (npath == null) npath = part; if (npath == null) npath = part;
else npath = npath + '/' + part; else npath = npath + '/' + part;
$('<button/>').append(part).click(function() { $('<button/>')
_this.OpenDir(npath); .append(part)
}).appendTo(this.dirBar); .click(function () {
}); _this.OpenDir(npath);
} })
.appendTo(this.dirBar);
});
}
this.ftable.find('tr.fileentry').remove(); this.ftable.find('tr.fileinfo').remove();
var fsiourl = this.root ? '/api/fs/' + this.root : '/api/fs'; var fsiourl = this.root ? '/api/fs/' + this.root : '/api/fs';
$.get(fsiourl, function(data) { $.get(fsiourl, function (data) {
$.each(data.SubDirectories, function () { $.each(data.SubDirectories, function () {
var item = this; var item = this;
var spath = (_this.root) ? _this.root + '/' + item.Name : item.Name; var spath = _this.root ? _this.root + '/' + item.Name : item.Name;
$('<button/>').append(item.Name).click(function() { $('<button/>')
_this.openDir(spath); .append(item.Name)
}).appendTo(_this.dirBar); .click(function () {
}); _this.openDir(spath);
})
.appendTo(_this.dirBar);
});
$.each(data.Files, function () { $.each(data.Files, function () {
var item = this; var item = this;
var $tr = $('<tr class="fileentry"></tr>'); var $tr = $('<tr class="fileinfo"></tr>');
var $td = $('<td></td>'); var $td = $('<td></td>');
$td.appendTo($tr); $td.appendTo($tr);
$('<input type="checkbox" />').addClass('check-box').click(function() { $('<input type="checkbox" />')
_this.SetItemSelected(item.Name, this.checked); .addClass('check-box')
}).appendTo($td); .click(function () {
_this.SetItemSelected(item.Name, this.checked);
})
.appendTo($td);
$('<td></td>').append($('<a></a>').append(item.Name).click(function() { $('<td></td>')
if (_this.root) document.location = '/' + owner + '/' + _this.root + '/' + item.Name; .append($('<a></a>')
else document.location = '/files/' + owner + '/' + item.Name; .append(item.Name)
})).appendTo($tr); .click(function () {
$('<td>' + item.Size + '</td>').appendTo($tr); if (_this.root) document.location = '/' + owner + '/' + _this.root + '/' + item.Name;
$('<td>' + item.LastModified + '</td>').appendTo($tr); else document.location = '/files/' + owner + '/' + item.Name;
$tr.appendTo(_this.ftable); })).appendTo($tr);
}); $('<td>' + item.Size + '</td>').appendTo($tr);
}); $('<td>' + item.LastModified + '</td>').appendTo($tr);
}, $tr.appendTo(_this.ftable);
SetItemSelected: function (name, selected) { });
if (selected) this.selection.push(name); });
else this.selection = this.selection.filter(function(ele) { },
return ele != name; SetItemSelected: function (name, selected) {
}); if (selected) {
}, this.selection.push(name);
RemoveSelectedFiles: function () { } else {
$.each(this.selection, function() { this.selection = this.selection.filter(function (ele) {
var xmlhttp = new XMLHttpRequest(); return ele !== name;
xmlhttp.open('DELETE', '/api/fs/' + this, true); });
xmlhttp.send(); }
}); },
this.selection = []; RemoveSelectedFiles: function () {
// FIXME this could fail for a very long list of big files $.each(this.selection, function () {
setTimeout(500, function() { this.openDir(this.root); }); var xmlhttp = new XMLHttpRequest();
}, xmlhttp.open('DELETE', '/api/fs/' + this, true);
askForRemoval: function () { xmlhttp.send();
this.flist.empty(); });
var _this = this; this.selection = [];
$.each(this.selection, function () { // FIXME this could fail for a very long list of big files
_this.flist.append('<li>' + this + '</li>'); setTimeout(500, function () {
}); this.openDir(this.root);
this.rmAlert.modal({ show: true }); });
}, },
_create: function () { moveSelectedFiles: function () {
var $view = this.element; var _this = this;
var _this = this; var dest = this.destination;
this.dirBar = $('<div></div>'); $.each(this.selection, function () {
this.dirBar.appendTo($view); var data = {};
this.ftable = $('<table border="1">').css('border-spacing', '6px') data['id'] = _this.root ? _this.root + '/' + this : this;
.css('border-collapse', 'separate'); data['to'] = dest;
this.openDir($view.data('path')); console.log(data);
var btnRm = $('<button class="glyphicon">&#xe083;</button>').click(function() { _this.askForRemoval(); }); var request = $.ajax({
var tr = $('<tr class="fileheaders"></tr>'); url: '/api/fsc/mvftd',
_this.ftable.append(tr); type: 'POST',
tr.append($('<th></th>').append(btnRm)).append('<th>Nom</th><th>Taille</th><th>Modification</th>'); data: JSON.stringify(data),
_this.ftable.appendTo($view); contentType: 'application/json;charset=utf-8'
this.rmAlert = $('<div id="rmAlert" tabindex="-1" role="dialog"></div>'); });
this.rmAlert.addClass('modal');
this.rmAlert.addClass('fade');
var md = $('<div role="document"></div>');
md.addClass('modal-dialog');
this.rmAlert.append(md);
var mdCnt = $('<div class="modal-content"></div>');
mdCnt.addClass('modal-content');
var mdHeader = $('<div class="modal-header"></div>');
mdHeader.append('<h5 class="modal-title">File removal</h5>');
mdHeader.append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
mdCnt.append(mdHeader);
var mdBody = $('<div class="modal-body"></div>');
mdBody.append('<p>You´re about to remove these files :</p>');
this.flist = $('<ul></ul>');
mdBody.append(this.flist);
mdCnt.append(mdBody);
var rmcBtn = $('<button type="button" data-dismiss="modal" class="btn btn-primary">Do deletion</button>')
.click(function() { _this.RemoveSelectedFiles(); });
var mdFooter = $('<div class="modal-footer"></div>');
mdFooter.append(rmcBtn);
mdFooter.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
mdCnt.append(mdFooter);
md.append(mdCnt);
this.rmAlert.appendTo($view);
}
});
})(window.jQuery);
request.done(function( msg ) {
$( "#log" ).html( msg );
});
request.fail(function( jqXHR, textStatus, msg ) {
alert( 'Request failed: ' + textStatus );
$( '#log' ).html( msg );
});
});
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();
var _this = this;
$.each(this.selection, function () {
_this.flist.append('<li>' + this + '</li>');
});
this.rmDialog.modal({ show: true });
},
askForMoving: function () {
this.flist.empty();
var _this = this;
$.each(this.selection, function () {
_this.flist.append('<li>' + this + '</li>');
});
this.mvDialog.modal({ show: true });
},
createRmDialog: function () {
var _this = this;
this.rmDialog = $('<div id="rmDialog" tabindex="-1" role="dialog"></div>');
this.rmDialog.addClass('modal');
this.rmDialog.addClass('fade');
var md = $('<div role="document"></div>');
md.addClass('modal-dialog');
this.rmDialog.append(md);
var mdCnt = $('<div class="modal-content"></div>');
mdCnt.addClass('modal-content');
var mdHeader = $('<div class="modal-header"></div>');
mdHeader.append('<h5 class="modal-title">File removal</h5>');
mdHeader.append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
mdCnt.append(mdHeader);
var mdBody = $('<div class="modal-body"></div>');
mdBody.append('<p>You´re about to remove these files :</p>');
this.flist = $('<ul></ul>');
mdBody.append(this.flist);
mdCnt.append(mdBody);
var rmcBtn = $('<button type="button" data-dismiss="modal" class="btn btn-primary">Do deletion</button>').click(function () {
_this.RemoveSelectedFiles();
});
var mdFooter = $('<div class="modal-footer"></div>');
mdFooter.append(rmcBtn);
mdFooter.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
mdCnt.append(mdFooter);
md.append(mdCnt);
this.rmDialog.appendTo(this.element);
},
onDestinationChanged: function (newDest)
{
this.destination = $(newDest).val();
},
createMvDialog: function () {
var _this = this;
this.mvDialog = $('<div id="mvDialog" tabindex="-1" role="dialog"></div>');
this.mvDialog.addClass('modal');
this.mvDialog.addClass('fade');
var md = $('<div role="document"></div>');
md.addClass('modal-dialog');
var mdCnt = $('<div class="modal-content"></div>');
mdCnt.addClass('modal-content');
var mdHeader = $('<div class="modal-header"></div>');
mdHeader.append('<h5 class="modal-title">Move files</h5>');
mdHeader.append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
mdCnt.append(mdHeader);
var mdBody = $('<div class="modal-body"></div>');
mdBody.append('<p>You´re about to move these files :</p>');
this.flist = $('<ul></ul>');
mdBody.append(this.flist);
var inputDest = $('<input type="text" class="form-control" hint="dest/dir">').on('change', function() { _this.onDestinationChanged(this); });
this.rootDisplay = $('<p></p>');
this.rootDisplay.addClass('hidden');
mdBody.append(this.rootDisplay);
var rp = $('<p>to the folowing sub-directory </p>');
mdBody.append(rp);
inputDest.appendTo(mdBody);
mdCnt.append(mdBody);
var moveBtn = $('<button type="button" data-dismiss="modal" class="btn btn-primary">Do move these files</button>').click(function () {
_this.moveSelectedFiles();
});
var mdFooter = $('<div class="modal-footer"></div>');
mdFooter.append(moveBtn);
mdFooter.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
mdCnt.append(mdFooter);
md.append(mdCnt);
this.mvDialog.append(md);
this.mvDialog.appendTo(this.element);
},
_create: function () {
var $view = this.element;
var _this = this;
this.dirBar = $('<div></div>');
this.dirBar.appendTo($view);
this.ftable = $('<table border="1">')
.css('border-spacing', '6px')
.css('border-collapse', 'separate');
var btnRm = $('<button class="glyphicon">&#xe014;</button>').click(function () {
_this.askForRemoval();
});
var btnMv = $('<button class="glyphicon">&#xe068;</button>').click(function () {
_this.askForMoving();
});
var tr = $('<tr class="fileheaders"></tr>');
_this.ftable.append(tr);
tr.append($('<th></th>').append(btnRm).append(btnMv)).append('<th>Nom</th><th>Taille</th><th>Modification</th>');
_this.ftable.appendTo($view);
$('<div id="log">Logs<br/></div>').appendTo($view);
this.createRmDialog();
this.createMvDialog();
this.openDir($view.data('path'));
}
});
})(window.jQuery);