diff --git a/HELP.md b/HELP.md
index 5b1893d3..8850cb15 100644
--- a/HELP.md
+++ b/HELP.md
@@ -213,6 +213,7 @@ Here is description of options:
"port" : 8000, /* http port */
"ip" : null, /* ip or null(default) */
"root" : "/" /* root directory */
+ "progressOfCopying" : false /* show progress of copying */
}
```
diff --git a/html/config.html b/html/config.html
index ce17ea33..487067b1 100644
--- a/html/config.html
+++ b/html/config.html
@@ -121,4 +121,10 @@
placeholder="Port"
class="form-control">
+
+
+
diff --git a/json/config.json b/json/config.json
index 16d2c852..754289d4 100644
--- a/json/config.json
+++ b/json/config.json
@@ -16,5 +16,6 @@
"showKeysPanel": true,
"port": 8000,
"ip": null,
- "root": "/"
+ "root": "/",
+ "progressOfCopying": false
}
diff --git a/json/modules.json b/json/modules.json
index dba70e1c..644c02db 100644
--- a/json/modules.json
+++ b/json/modules.json
@@ -7,6 +7,7 @@
"config",
"contact",
"upload",
+ "operation",
"konsole", [{
"name": "remote",
"data": [{
diff --git a/lib/client/buffer.js b/lib/client/buffer.js
index 65d5607a..9282a27c 100644
--- a/lib/client/buffer.js
+++ b/lib/client/buffer.js
@@ -1,13 +1,15 @@
-var Util, DOM;
+/* global Util */
+/* global DOM */
+/* global CloudCmd */
-(function(Util, DOM) {
+(function(Util, DOM, CloudCmd) {
'use strict';
var DOMProto = Object.getPrototypeOf(DOM);
- DOMProto.Buffer = new BufferProto(Util, DOM);
+ DOMProto.Buffer = new BufferProto(Util, DOM, CloudCmd);
- function BufferProto(Util, DOM) {
+ function BufferProto(Util, DOM, CloudCmd) {
var Storage = DOM.Storage,
Dialog = DOM.Dialog,
Files = DOM.Files,
@@ -112,9 +114,10 @@ var Util, DOM;
cut = Storage.get.bind(Storage, CUT);
Util.exec.parallel([copy, cut], function(error, cp, ct) {
- var data = {},
- msg = 'Path is same!',
- path = Info.dirPath;
+ var data = {},
+ Operation = CloudCmd.Operation,
+ msg = 'Path is same!',
+ path = Info.dirPath;
if (!error && !cp && !ct)
error = 'Buffer is empty!';
@@ -128,7 +131,7 @@ var Util, DOM;
if (data.from === path)
Dialog.alert(msg);
else
- DOM.copyFiles(data);
+ Operation.show('copy', data);
} else if (ct) {
data = json.parse(ct);
@@ -137,7 +140,7 @@ var Util, DOM;
if (data.from === path)
Dialog.alert(msg);
else
- DOM.moveFiles(data);
+ Operation.show('move', data);
}
clear();
@@ -146,4 +149,4 @@ var Util, DOM;
return Buffer;
}
-})(Util, DOM);
+})(Util, DOM, CloudCmd);
diff --git a/lib/client/cloudcmd.js b/lib/client/cloudcmd.js
index 49132d36..a716b8ed 100644
--- a/lib/client/cloudcmd.js
+++ b/lib/client/cloudcmd.js
@@ -21,8 +21,8 @@ var CloudCmd;
client + 'notify',
client + 'storage',
client + 'files',
- client + 'buffer',
'client',
+ client + 'buffer',
client + 'listeners',
client + 'key'
].map(function(name) {
diff --git a/lib/client/dom.js b/lib/client/dom.js
index 18a323d9..563ae665 100644
--- a/lib/client/dom.js
+++ b/lib/client/dom.js
@@ -1576,122 +1576,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
}
};
- /*
- * process files (copy or move)
- * @param data
- * @param operation
- */
- function processFiles(data, operation, message) {
- var name, files,
- panel,
- shouldAsk,
- sameName,
- ok,
- tmpl = '"{{ name }}" already exist. Overwrite?',
-
- from = '',
- to = '',
-
- names = [];
-
- if (data) {
- from = data.from;
- to = data.to;
- names = data.names;
- panel = CurrentInfo.panel;
- } else {
- from = CurrentInfo.dirPath;
- to = DOM.getNotCurrentDirPath();
- names = Cmd.getSelectedNames();
- data = {};
- shouldAsk = true;
- panel = CurrentInfo.panelPassive;
- }
-
- if (!names.length)
- names.push(DOM.getCurrentName());
-
- name = names[0];
-
- sameName = !!DOM.getCurrentByName(name, panel);
-
- if (name === '..') {
- Dialog.alert('No files selected!');
- } else {
- if (shouldAsk)
- to = message(to, names);
-
- ok = from !== to && to;
-
- if (ok && shouldAsk && sameName)
- ok = Dialog.confirm(rendy(tmpl, {
- name: name
- }));
-
- if (ok) {
- Images.show.load('top');
-
- files = {
- from : from,
- to : to,
- names : names
- };
-
- operation(files, function() {
- var path = CloudFunc.rmLastSlash(from);
-
- DOM.Storage.remove(path, function() {
- var panel = CurrentInfo.panel,
- panelPassive = CurrentInfo.panelPassive,
- setCurrent = function() {
- var current;
-
- if (!name)
- name = data.names[0];
-
- current = DOM.getCurrentByName(name);
- DOM.setCurrentFile(current);
- };
-
- if (!CurrentInfo.isOnePanel)
- CloudCmd.refresh(panelPassive, {noCurrent: true}, function() {});
-
- CloudCmd.refresh(panel, setCurrent);
- });
- });
- }
- }
- }
-
- function message(msg) {
- return function(to, names) {
- var ret,
- n = names.length,
- name = names[0];
-
- msg += ' ';
-
- if (names.length > 1)
- msg += n + ' file(s)';
- else
- msg += '"' + name + '"';
-
- msg += ' to';
-
- ret = Dialog.prompt(msg, to);
-
- return ret;
- };
- }
-
- this.copyFiles = function(data) {
- processFiles(data, DOM.RESTful.cp, message('Copy'));
- };
-
- this.moveFiles = function(data) {
- processFiles(data, DOM.RESTful.mv, message('Rename/Move'));
- };
-
/**
* unified way to scrollIntoViewIfNeeded
* (native suporte by webkit only)
diff --git a/lib/client/key.js b/lib/client/key.js
index 0069f007..e31f0f0b 100644
--- a/lib/client/key.js
+++ b/lib/client/key.js
@@ -291,12 +291,12 @@ var CloudCmd, Util, DOM;
break;
case Key.F5:
- DOM.copyFiles();
+ CloudCmd.Operation.show('copy');
event.preventDefault();
break;
case Key.F6:
- DOM.moveFiles();
+ CloudCmd.Operation.show('move');
event.preventDefault();
break;
diff --git a/lib/client/listeners.js b/lib/client/listeners.js
index 637392d7..b33aa3b6 100644
--- a/lib/client/listeners.js
+++ b/lib/client/listeners.js
@@ -36,14 +36,14 @@ var Util, DOM, CloudFunc, CloudCmd;
'f1' : CloudCmd.Help.show,
'f3' : CloudCmd.View.show,
'f4' : CloudCmd.Edit.show,
+ 'f5' : CloudCmd.Operation.show.bind(null, 'copy'),
+ 'f6' : CloudCmd.Operation.show.bind(null, 'move'),
'f9' : CloudCmd.Menu.show,
'f10' : CloudCmd.Config.show,
'~' : CloudCmd.Konsole.show,
'contact' : CloudCmd.Contact.show,
'f2' : DOM.renameCurrent,
- 'f5' : DOM.copyFiles,
- 'f6' : DOM.moveFiles,
'f7' : DOM.promptNewDir,
'f8' : DOM.promptDelete
},
diff --git a/lib/client/operation.js b/lib/client/operation.js
new file mode 100644
index 00000000..c914582f
--- /dev/null
+++ b/lib/client/operation.js
@@ -0,0 +1,245 @@
+/* global CloudCmd */
+/* global Util */
+/* global DOM */
+/* global CloudFunc */
+/* global rendy */
+/* global spero */
+
+(function(CloudCmd, Util, DOM, CloudFunc, rendy) {
+ 'use strict';
+
+ CloudCmd.Operation = OperationProto;
+
+ function OperationProto(operation, data) {
+ var Name = 'Operation',
+ Loaded,
+ copyFn = DOM.RESTful.cp,
+ moveFn = DOM.RESTful.mv,
+ Images = DOM.Images,
+ Dialog = DOM.Dialog,
+
+ Operation = this;
+
+ function init() {
+ Images.show.load();
+
+ Util.exec.series([
+ function(callback) {
+ var Files = DOM.Files;
+
+ Files.get('config', function(error, config) {
+ if (error)
+ alert(error);
+ else if (config.progressOfCopying)
+ load(function() {
+ create(callback);
+ });
+ else
+ callback();
+ });
+ },
+ function() {
+ Loaded = true;
+ Operation.show(operation, data);
+ }
+ ]);
+ }
+
+ function create(callback) {
+ spero(function() {
+ var parse = function(fn) {
+ return function(data, callback) {
+ var progress = function(value) {
+ Images.setProgress(value);
+ },
+
+ end = function() {
+ callback();
+ spero.removeListener('progress', progress);
+ spero.removeListener('end', end);
+ },
+
+ error = function(data) {
+ var msg = data + '\n Continue?',
+ is = confirm(msg);
+
+ if (is)
+ spero.continue();
+ else
+ spero.abort();
+ };
+
+ Images.show('top');
+
+ fn(data.from, data.to, data.names);
+
+ spero.on('progress', progress);
+ spero.on('end', end);
+ spero.on('error', error);
+ };
+ };
+
+ spero.on('connect', function() {
+ copyFn = parse(spero.copy);
+ });
+
+ spero.on('disconnect', function() {
+ copyFn = DOM.RESTful.cp;
+ });
+
+ Util.exec(callback);
+ });
+ }
+
+ this.hide = function() {
+ CloudCmd.View.hide();
+ };
+
+ this.show = function(operation, data) {
+ if (Loaded)
+ switch(operation) {
+ case 'copy':
+ this.copy(data);
+ break;
+
+ case 'move':
+ this.move(data);
+ break;
+ }
+ };
+
+ this.copy = function(data) {
+ processFiles(data, copyFn, message('Copy'));
+ };
+
+ this.move = function(data) {
+ processFiles(data, moveFn, message('Rename/Move'));
+ };
+
+ /*
+ * process files (copy or move)
+ * @param data
+ * @param operation
+ */
+ function processFiles(data, operation, message) {
+ var name, files,
+ CurrentInfo = DOM.CurrentInfo,
+ panel,
+ shouldAsk,
+ sameName,
+ ok,
+ tmpl = '"{{ name }}" already exist. Overwrite?',
+
+ from = '',
+ to = '',
+
+ names = [];
+
+ if (data) {
+ from = data.from;
+ to = data.to;
+ names = data.names;
+ panel = CurrentInfo.panel;
+ } else {
+ from = CurrentInfo.dirPath;
+ to = DOM.getNotCurrentDirPath();
+ names = DOM.getSelectedNames();
+ data = {};
+ shouldAsk = true;
+ panel = CurrentInfo.panelPassive;
+ }
+
+ if (!names.length)
+ names.push(DOM.getCurrentName());
+
+ name = names[0];
+
+ sameName = !!DOM.getCurrentByName(name, panel);
+
+ if (name === '..') {
+ Dialog.alert('No files selected!');
+ } else {
+ if (shouldAsk)
+ to = message(to, names);
+
+ ok = from !== to && to;
+
+ if (ok && shouldAsk && sameName)
+ ok = Dialog.confirm(rendy(tmpl, {
+ name: name
+ }));
+
+ if (ok) {
+ Images.show.load('top');
+
+ files = {
+ from : from,
+ to : to,
+ names : names
+ };
+
+ operation(files, function() {
+ var path = CloudFunc.rmLastSlash(from);
+
+ DOM.Storage.remove(path, function() {
+ var panel = CurrentInfo.panel,
+ panelPassive = CurrentInfo.panelPassive,
+ setCurrent = function() {
+ var current;
+
+ if (!name)
+ name = data.names[0];
+
+ current = DOM.getCurrentByName(name);
+ DOM.setCurrentFile(current);
+ };
+
+ if (!CurrentInfo.isOnePanel)
+ CloudCmd.refresh(panelPassive, {noCurrent: true}, function() {});
+
+ CloudCmd.refresh(panel, setCurrent);
+ });
+ });
+ }
+ }
+ }
+
+ function message(msg) {
+ return function(to, names) {
+ var ret,
+ n = names.length,
+ name = names[0];
+
+ msg += ' ';
+
+ if (names.length > 1)
+ msg += n + ' file(s)';
+ else
+ msg += '"' + name + '"';
+
+ msg += ' to';
+
+ ret = Dialog.prompt(msg, to);
+
+ return ret;
+ };
+ }
+
+ function load(callback) {
+ DOM.load.js('/spero/spero.js', function(error) {
+ if (error) {
+ Dialog.alert(error.message);
+ } else {
+ Loaded = true;
+ Util.timeEnd(Name + ' load');
+ Util.exec(callback);
+ }
+ });
+
+ Util.time(Name + ' load');
+ }
+
+ init();
+ }
+
+})(CloudCmd, Util, DOM, CloudFunc, rendy);
diff --git a/lib/cloudcmd.js b/lib/cloudcmd.js
index 92e601f5..914f3fcc 100644
--- a/lib/cloudcmd.js
+++ b/lib/cloudcmd.js
@@ -20,6 +20,7 @@
webconsole = require('console-io'),
edward = require('edward'),
dword = require('dword'),
+ spero = require('spero'),
root = function() {
return config('root');
@@ -72,6 +73,10 @@
size: size,
root: root
});
+
+ spero.listen(socket, {
+ root: root
+ });
};
function cloudcmd() {
@@ -125,6 +130,11 @@
zip : isZip
}),
+ spero({
+ minify: isMinify,
+ online: isOnline
+ }),
+
mollify({
dir : DIR_ROOT,
is : isMinify
diff --git a/package.json b/package.json
index 6c891cc5..7ddd0bf7 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
"rendy": "~1.1.0",
"restafary": "~1.3.0",
"socket.io": "~1.3.5",
+ "spero": "~1.0.0",
"try-catch": "~1.0.0",
"tryrequire": "~1.1.5"
},