diff --git a/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml b/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml
index 4098d3ff..43dc0a2b 100644
--- a/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml
+++ b/src/Yavsc/Views/Shared/_FSScriptsPartial.cshtml
@@ -1 +1,24 @@
-
\ No newline at end of file
+
+
diff --git a/src/Yavsc/wwwroot/js/yavsc-remote-fs.js b/src/Yavsc/wwwroot/js/yavsc-remote-fs.js
index 6f541070..5863f4f1 100644
--- a/src/Yavsc/wwwroot/js/yavsc-remote-fs.js
+++ b/src/Yavsc/wwwroot/js/yavsc-remote-fs.js
@@ -1,128 +1,136 @@
// requires DropZone ª toMarkdown
-if (typeof jQuery === 'undefined') {
+
+if (typeof window.jQuery === 'undefined') {
throw new Error('yavsc-remote-fs script requires jQuery');
}
-if (typeof Dropzone === 'undefined') {
- throw new Error('yavsc-remote-fs requires Dropzone');
-}
-if (typeof updateMD === 'undefined') {
- throw new Error('yavsc-remote-fs requires md-helpers.js');
-}
-(function($, Dropzone, updateMD) {
+(function ($) {
+ $.widget('psc.yarfs', {
+ options: {
+ fsnurl: '/api/fs'
+ },
+ root: null,
+ rmAlert: null,
+ flist: null,
+ selection: [],
+ dirBar: null,
+ openDir: function (sub) {
+ var _this = this;
+ this.root = sub;
+ var owner = this.element.data('owner');
+ this.selection = [];
+ this.dirBar.empty();
+ $('').click(function() {
+ _this.openDir(null);
+ }).appendTo(this.dirBar);
+ var npath = null;
- window.RemoteFS = (function ($) {
+ if (_this.root) {
+ var dnames = _this.root.split('/');
+ $.each(dnames, function () {
+ var part = this;
+ if (npath == null) npath = part;
+ else npath = npath + '/' + part;
+ $('').append(part).click(function() {
+ _this.OpenDir(npath);
+ }).appendTo(this.dirBar);
+ });
+ }
- /*
- var Combine = function (patha, pathb) {
- if (!patha) return pathb;
- if (!pathb) return patha;
- return patha + '/' + pathb;
- }; */
+ this.ftable.find('tr.fileentry').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);
+ });
- var OpenDir = function ($view, sub) {
- $view.data('path', sub);
- InitDir($view);
- };
- var root;
- var selection = [];
+ $.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 SetItemSelected = function (name, selected) {
- if (selected) selection.push(name);
- else selection = selection.filter(function(ele) {
- return ele != name;
- });
- };
+ $(' | ').append($('').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);
+ });
+ });
+ },
+ SetItemSelected: function (name, selected) {
+ if (selected) this.selection.push(name);
+ else this.selection = this.selection.filter(function(ele) {
+ return ele != name;
+ });
+ },
+ RemoveSelectedFiles: function () {
+ $.each(this.selection, function() {
+ var xmlhttp = new XMLHttpRequest();
+ xmlhttp.open('DELETE', '/api/fs/' + this, true);
+ xmlhttp.send();
+ });
+ 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('' + this + '');
+ });
+ this.rmAlert.modal({ show: true });
+ },
+ _create: function () {
+ var $view = this.element;
+ var _this = this;
+ this.dirBar = $('');
+ this.dirBar.appendTo($view);
+ this.ftable = $('').css('border-spacing', '6px')
+ .css('border-collapse', 'separate');
+ this.openDir($view.data('path'));
+ var btnRm = $('').click(function() { _this.askForRemoval(); });
+ var tr = $('');
+ _this.ftable.append(tr);
+ tr.append($(' | ').append(btnRm)).append('Nom | Taille | Modification | ');
+ _this.ftable.appendTo($view);
+ this.rmAlert = $('');
+ this.rmAlert.addClass('modal');
+ this.rmAlert.addClass('fade');
+ var md = $('');
+ md.addClass('modal-dialog');
+ this.rmAlert.append(md);
+ var mdCnt = $('');
+ mdCnt.addClass('modal-content');
+ var mdHeader = $('');
+ mdHeader.append('File removal
');
+ mdHeader.append('');
+ mdCnt.append(mdHeader);
+ var mdBody = $('');
+ mdBody.append('You´re about to remove these files :
');
+ this.flist = $('');
+ mdBody.append(this.flist);
+ mdCnt.append(mdBody);
+ var rmcBtn = $('')
+ .click(function() { _this.RemoveSelectedFiles(); });
+ var mdFooter = $('');
+ mdFooter.append(rmcBtn);
+ mdFooter.append('');
+ mdCnt.append(mdFooter);
+ md.append(mdCnt);
+ this.rmAlert.appendTo($view);
+ }
+ });
- var RemoveSelectedFiles = function () {
- var xmlhttp = new XMLHttpRequest();
- $.each(selection, function() {
- xmlhttp.open('DELETE', '/api/fs/' + this, true);
- xmlhttp.send();
- });
- };
-
- var InitDir = function ($view) {
-
- root = $view.data('path');
- var owner = $view.data('owner');
- var fsiourl = root ? '/api/fs/' + root : '/api/fs';
-
- $view.empty();
-
- $.get(fsiourl, function(data) {
- $('').click(function() {
- OpenDir($view, null);
- }).appendTo($view);
-
- var npath = null;
-
- if (root) $.each(root.split('/'), function () {
- var part = this;
- if (npath == null) npath = part;
- else npath = npath + '/' + part;
- $('').append(part).click(function() {
- OpenDir($view, npath);
- }).appendTo($view);
- });
-
- $.each(data.SubDirectories, function () {
- var item = this;
- var spath = (root) ? root + '/' + item.Name : item.Name;
- $('').append(item.Name).click(function() {
- OpenDir($view, spath);
- }).appendTo($view);
- });
- var $divedit = $('');
- $('').addClass('glyphicon').append().click(function() {
- RemoveSelectedFiles();
- }).appendTo($divedit);
- $divedit.appendTo($view);
- var $ftable = $('').css('border-spacing', '6px')
- .css('border-collapse', 'separate')
- .append('');
- $.each(data.Files, function () {
- var item = this;
- var $tr = $('
');
- var $td = $(' | ');
- $('').addClass('check-box').click(function() {
- SetItemSelected(item.Name, this.checked)
- }).appendTo($td);
- $td.append(' ');
- $('').append(item.Name).click(function() {
- if (root) document.location = '/' + owner + '/' + root + '/' + item.Name;
- else document.location = '/files/' + owner + '/' + item.Name;
- }).appendTo($td);
- $td.appendTo($tr);
- $('' + item.Size + ' | ').appendTo($tr);
- $('' + item.LastModified + ' | ').appendTo($tr);
- $tr.appendTo($ftable);
- });
- $ftable.appendTo($view);
- });
- };
- $(document).ready(function () {
- OpenDir($('.dirinfo'));
- });
- })($);
-
-
- Dropzone.options.postfiles = {
- maxFilesize: 20, // MB TODO: let sell it.
- autoProcessQueue: true,
- accept: function(file, done) {
- if (file.name == 'justinbieber.jpg') {
- done('Naha, you don\'t.');
- } else { done(); }
- },
- success: function (file, response) {
- for (var i = 0; i < response.length; i++) {
- var filer = response[i];
- $('' + filer.FileName + '
').appendTo('#ql-editor-2');
- updateMD('Content', $('#contentview').html());
- }
- },
- url: '/api/fs'
- };
-})($, Dropzone, updateMD);
+})(window.jQuery);