diff --git a/lib/client.js b/lib/client.js index 91a58db6..d854bb46 100644 --- a/lib/client.js +++ b/lib/client.js @@ -7,12 +7,16 @@ var Util, DOM, CloudFunc, join; function CloudCmdProto(Util, DOM, CloudFunc) { var Key, - log = function() { - DOM.Files.get('config', function(error, config) { - if (!error && config.debug) - console.log.apply(console, arguments); - }); + Debug, + log = function(str) { + var date = Util.getShortDate(), + time = Util.getTime(), + prefix = date + ' ' + time; + + if (Debug) + console.log('[' + prefix + '] ' + str); }, + Listeners, Files = DOM.Files, Images = DOM.Images, @@ -21,6 +25,7 @@ var Util, DOM, CloudFunc, join; Storage = DOM.Storage, type = Util.type; + this.log = log, this.PREFIX = '', this.MousePosition = {}; this.LIBDIR = '/lib/'; @@ -28,6 +33,15 @@ var Util, DOM, CloudFunc, join; this.MIN_ONE_PANEL_WIDTH = 1155; this.HOST = location.origin || location.protocol + '//' + location.host; + + log.enable = function() { + Debug = true; + }; + + log.disable = function() { + Debug = false; + }; + /** * Функция привязываеться ко всем ссылкам и * загружает содержимое каталогов @@ -179,7 +193,7 @@ var Util, DOM, CloudFunc, join; if (file && !current) { msg = CloudFunc.formatMsg('set current file', file, 'error'); - log(msg); + CloudCmd.log(msg); } else { DOM.setCurrentFile(current); CloudCmd.execFromModule(module, 'show'); @@ -347,7 +361,7 @@ var Util, DOM, CloudFunc, join; if (!options) options = {}; - log('reading dir: "' + path + '";'); + CloudCmd.log('reading dir: "' + path + '";'); Files.get('config', function(error, config) { var dirStorage; diff --git a/lib/client/config.js b/lib/client/config.js index e169b4fa..561b500c 100644 --- a/lib/client/config.js +++ b/lib/client/config.js @@ -65,7 +65,7 @@ var CloudCmd, Util, DOM, io; }); socket.on('log', function(msg) { - Util.log(msg); + CloudCmd.log(msg); }); socket.on('disconnect', function() { diff --git a/lib/client/dom.js b/lib/client/dom.js index a44cc962..a2e6f45a 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -133,7 +133,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; if (!isQuiet) Dialog.alert(text); - Util.log(text); + CloudCmd.log(text); }, 100); return image; @@ -1390,13 +1390,13 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog; if (!panel) - Util.log('Error can not find Active Panel'); + throw(Error('can not find Active Panel!')); return panel; }; this.getFiles = function(element) { - var files = DOM.getByDataName('js-files', element), + var files = DOM.getByDataName('js-files', element), ret = files.children || []; return ret; diff --git a/lib/client/key.js b/lib/client/key.js index 576a9bec..211b1f21 100644 --- a/lib/client/key.js +++ b/lib/client/key.js @@ -420,7 +420,7 @@ var CloudCmd, Util, DOM; */ case Key.R: if (ctrlMeta) { - Util.log('reloading page...\n'); + CloudCmd.log('reloading page...\n'); CloudCmd.refresh(); Events.preventDefault(event); @@ -450,10 +450,10 @@ var CloudCmd, Util, DOM; /* чистим хранилище */ case Key.D: if (ctrlMeta) { - Util.log('clearing storage...'); + CloudCmd.log('clearing storage...'); DOM.Storage.clear(function() { - Util.log('storage cleared'); + CloudCmd.log('storage cleared'); }); Events.preventDefault(event); diff --git a/lib/client/menu.js b/lib/client/menu.js index f54ada47..5716cb89 100644 --- a/lib/client/menu.js +++ b/lib/client/menu.js @@ -213,7 +213,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; }); }); - Util.log('Uploading to ' + name + '...'); + CloudCmd.log('Uploading to ' + name + '...'); } function getFromPicker() { @@ -241,7 +241,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO; isDir = DOM.isCurrentIsDir(file), dir = isDir ? '&&json' : ''; - Util.log('downloading file ' + path +'...'); + CloudCmd.log('downloading file ' + path +'...'); path = apiURL + FS + path + '?download' + dir; diff --git a/lib/client/rest.js b/lib/client/rest.js index a69f4894..f9a5034d 100644 --- a/lib/client/rest.js +++ b/lib/client/rest.js @@ -192,7 +192,7 @@ var Util, DOM, CloudFunc, CloudCmd; Images.hide(); if (!p.notLog) - Util.log(data); + CloudCmd.log(data); Util.exec(p.callback, data); } diff --git a/lib/client/storage/_dropbox.js b/lib/client/storage/_dropbox.js index 868209c9..83def8c6 100644 --- a/lib/client/storage/_dropbox.js +++ b/lib/client/storage/_dropbox.js @@ -18,7 +18,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client; } - cb = function (err, data){ Util.log(err || data);}; + cb = function (err, data){ console.log(err || data);}; /** * function loads dropbox.js @@ -42,7 +42,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client; var lHello = 'Hello ' + pData.name + ' :)!', lMsg = pError ? pError : lHello; - Util.log(lMsg); + console.log(lMsg); }); Util.exec(callback); @@ -72,7 +72,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client; })); Client.authenticate(function(error, client) { - Util.log(error); + console.log(error); Client = client; Util.exec(callback); }); @@ -137,7 +137,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client; Client.writeFile(name, data, function(error, data){ DOM.Images.hide(); - Util.log(error || data); + console.log(error || data); Util.exec(callback); }); } diff --git a/lib/client/storage/_filepicker.js b/lib/client/storage/_filepicker.js index 51ab2a65..dd246cba 100644 --- a/lib/client/storage/_filepicker.js +++ b/lib/client/storage/_filepicker.js @@ -18,7 +18,7 @@ var CloudCmd, Util, DOM, filepicker; this.uploadFile = function(params) { var content = params.data, name = params.name, - log = Util.log.bind(Util); + log = console.log.bind(console); filepicker.store(content, { mimetype: '', @@ -33,7 +33,7 @@ var CloudCmd, Util, DOM, filepicker; this.saveFile = function(callback) { filepicker.pick(function(fpFile) { - Util.log(fpFile); + console.log(fpFile); DOM.load.ajax({ url : fpFile.url, diff --git a/lib/client/storage/_gdrive.js b/lib/client/storage/_gdrive.js index 7cd79bdf..7aa59fa9 100644 --- a/lib/client/storage/_gdrive.js +++ b/lib/client/storage/_gdrive.js @@ -89,7 +89,7 @@ var CloudCmd, Util, DOM, gapi; if (!pCallBack) pCallBack = function(file) { - Util.log(file); + console.log(file); }; request.execute(pCallBack); diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index 69a603e9..efdb3d50 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -12,7 +12,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb; GH, User; - cb = function (err, data) { Util.log(err || data);}; + cb = function (err, data) { console.log(err || data);}; function init(callback) { Util.exec.series([ @@ -78,7 +78,7 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb; if (!error) { name = data.name; - Util.log('Hello ' + name + ' :)!'); + console.log('Hello ' + name + ' :)!'); } else DOM.Storage.remove('token'); }); @@ -133,9 +133,9 @@ var CloudCmd, Util, join, DOM, CloudFunc, Github, cb; gist.create(options, function(error, data) { if (error) - Util.log(error); + console.log(error); else - Util.log(data, data.html_url); + console.log(data, data.html_url); Util.exec(callback); DOM.Images.hide(); diff --git a/lib/client/storage/_skydrive.js b/lib/client/storage/_skydrive.js index 95b4655d..e91832dd 100644 --- a/lib/client/storage/_skydrive.js +++ b/lib/client/storage/_skydrive.js @@ -39,10 +39,10 @@ var CloudCmd, Util, DOM, WL; scope: ['wl.skydrive wl.signin'] }).then( function(response) { - Util.log(response); + console.log(response); }, function() { - Util.log('Failed to authenticate.'); + console.log('Failed to authenticate.'); }); WL.Event.subscribe('auth.login', onLogin); @@ -60,7 +60,7 @@ var CloudCmd, Util, DOM, WL; function (response) { if (!response.error) { strGreeting = 'Hi, ' + response.first_name + '!'; - Util.log(strGreeting); + console.log(strGreeting); } }); } diff --git a/lib/client/storage/_vk.js b/lib/client/storage/_vk.js index de53e56d..11deb8ac 100644 --- a/lib/client/storage/_vk.js +++ b/lib/client/storage/_vk.js @@ -42,8 +42,8 @@ var CloudCmd, Util, DOM, VK; VK.Api.call('getVariable', {key: lNAME}, function(r) { var lName = r.response; - if(lName) - Util.log ('Hello, ' + lName + ':)'); + if (lName) + console.log ('Hello, ' + lName + ':)'); }); Util.exec(callback); @@ -74,11 +74,11 @@ var CloudCmd, Util, DOM, VK; }, dataType: 'application/x-www-form-urlencoded', success : function(data){ - Util.log(data); - VK.Api.call('docs.save', {}, Util.log); + console.log(data); + VK.Api.call('docs.save', {}, console.log); }, - error : Util.log + error : console.log }); }); }; diff --git a/lib/client/view.js b/lib/client/view.js index 978d5bd0..0669d5f4 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -238,7 +238,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; name = Info.name; if (error) { - Util.log(error); + alert(error); } else { if (!TemplateAudio) TemplateAudio = template; diff --git a/lib/server/route.js b/lib/server/route.js index 6d73a3ce..0c63ec99 100644 --- a/lib/server/route.js +++ b/lib/server/route.js @@ -99,7 +99,7 @@ files.read(filesList, 'utf8', function(error, files) { if (error) - Util.log(error.message); + throw(error); else Object.keys(files).forEach(function(path) { var name = paths[path]; @@ -134,7 +134,7 @@ if (!isAuth && !isFS) callback(); else if (isAuth) { - Util.log('* Routing' + '-> ' + name); + console.log('* Routing' + '-> ' + name); p.name = DIR_HTML + name + '.html'; ponse.sendFile(p); diff --git a/lib/server/terminal.js b/lib/server/terminal.js index 6e34fa90..e655e03d 100644 --- a/lib/server/terminal.js +++ b/lib/server/terminal.js @@ -100,7 +100,7 @@ lRet = 'client #' + pConnNum + lType + pStr; - Util.log(lRet); + console.log(lRet); } return lRet; diff --git a/lib/util.js b/lib/util.js index 99a4de53..deac5c74 100644 --- a/lib/util.js +++ b/lib/util.js @@ -220,26 +220,6 @@ }; } - /** - * function log pArg if it's not empty - * @param pArg - */ - this.log = function() { - var args = [].slice.call(arguments), - console = Scope.console, - lDate = '[' + Util.getDate() + '] '; - - if (console && args.length && args[0]) { - args.unshift(lDate); - - console.log.apply(console, args); - - args.shift(); - } - - return args.join(' '); - }; - /** * function remove substring from string * @param str