feature(files) add

This commit is contained in:
coderaiser 2014-06-17 10:12:16 -04:00
parent 6b11242c53
commit e265214051
16 changed files with 144 additions and 90 deletions

View file

@ -9,9 +9,7 @@
var opener = window.opener;
if (opener) {
var CloudCmd = opener.CloudCmd;
CloudCmd.getModules(function(error, modules) {
DOM.Files.get('modules', function(error, modules) {
var Util = opener.Util,
Storage = Util.findObjByNameInArr(modules, 'storage'),
GitHub = Util.findObjByNameInArr(Storage, 'GitHub'),

View file

@ -49,6 +49,7 @@
client + 'load',
client + 'notify',
client + 'storage',
client + 'files',
'client',
client + 'listeners',
client + 'key'

View file

@ -6,12 +6,9 @@ var Util, DOM, CloudFunc;
scope.CloudCmd = new CloudCmdProto(Util, DOM, CloudFunc);
function CloudCmdProto(Util, DOM, CloudFunc) {
var Key, Config, Modules, Extensions,
FileTemplate, PathTemplate, Listeners,
DIR_HTML = '/html/',
DIR_HTML_FS = DIR_HTML + 'fs/',
DIR_JSON = '/json/',
var Key,
Listeners,
Files = DOM.Files,
Images = DOM.Images,
Info = DOM.CurrentInfo,
CloudCmd = this,
@ -97,12 +94,13 @@ var Util, DOM, CloudFunc;
*/
function loadModule(params) {
var name, path, func, doBefore, slash, afterSlash,
isContain;
funcName, isContain;
if (params) {
name = params.name,
path = params.path,
func = params.func,
funcName = params.funcName,
doBefore = params.dobefore;
if (path && !name) {
@ -137,7 +135,7 @@ var Util, DOM, CloudFunc;
});
};
CloudCmd[name].show = CloudCmd[name];
CloudCmd[name][funcName] = CloudCmd[name];
}
}
}
@ -203,7 +201,7 @@ var Util, DOM, CloudFunc;
});
});
CloudCmd.getModules(function(error, modules) {
DOM.Files.get('modules', function(error, modules) {
var storageObj, mod, path,
STORAGE = 'storage',
showLoad = Images.showLoad.bind(Images),
@ -215,8 +213,11 @@ var Util, DOM, CloudFunc;
},
load = function(name, path, func) {
var isTmpl = path === 'template';
loadModule({
name : name,
funcName : isTmpl ? 'get' : 'show',
path : path,
dobefore : func
});
@ -262,7 +263,7 @@ var Util, DOM, CloudFunc;
Listeners.initKeysPanel();
CloudCmd.getConfig(function(error, config) {
Files.get('config', function(error, config) {
var localStorage = config.localStorage,
dirPath = DOM.getCurrentDirPath();
@ -283,55 +284,6 @@ var Util, DOM, CloudFunc;
callback();
}
this.getTemplate = function(data, name, callback) {
var path = DIR_HTML + name +'.html',
func = getSystemFile(data, path);
func(callback);
};
function getSystemFile(global, url) {
var get = function (callback) {
var success = Util.exec.with(callback, null);
Util.exec.if(global, success, function() {
DOM.load.ajax({
url : url,
success : function(local) {
global = local;
success(local);
},
error : function(error) {
callback(error);
}
});
});
};
return get;
}
this.setConfig = function(config) { Config = config; };
this.getConfig = function(callback) {
var func = Util.exec.with(callback, null);
Util.exec.if(Config, func, function(callback) {
var RESTful = DOM.RESTful;
RESTful.Config.read(function(config) {
Config = config;
callback(config);
});
});
};
this.getModules = getSystemFile(Modules, DIR_JSON + 'modules.json');
this.getExt = getSystemFile(Extensions, DIR_JSON + 'ext.json');
this.getFileTemplate = getSystemFile(FileTemplate, DIR_HTML_FS + 'file.html');
this.getPathTemplate = getSystemFile(PathTemplate, DIR_HTML_FS + 'path.html');
this.getPathLinkTemplate = getSystemFile(PathTemplate, DIR_HTML_FS + 'pathLink.html');
this.getLinkTemplate = getSystemFile(PathTemplate, DIR_HTML_FS + 'link.html');
this.execFromModule = function(moduleName, funcName, params) {
var obj = CloudCmd[moduleName],
isObj = Util.isObject(obj);
@ -408,14 +360,9 @@ var Util, DOM, CloudFunc;
/* getting current element if was refresh */
path = DOM.getCurrentDirPath(panel),
wasRefresh = path === json.path,
funcs = [
CloudCmd.getFileTemplate,
CloudCmd.getPathTemplate,
CloudCmd.getPathLinkTemplate,
CloudCmd.getLinkTemplate
];
names = ['file', 'path', 'link', 'pathLink'];
Util.exec.parallel(funcs, function(error, templFile, templPath, templPathLink, templLink) {
Files.get(names, function(error, templFile, templPath, templLink, templPathLink) {
var n, found, varCurrent, varName, current,
dir = DOM.getCurrentDirName(),
name = DOM.getCurrentName(),

View file

@ -50,7 +50,7 @@ var CloudCmd, Util, DOM;
if (!Template)
Template = template;
CloudCmd.getConfig(function(error, config) {
DOM.Files.get('config', function(error, config) {
var div, data, inputs, inputFirst,
focus, obj;
@ -136,9 +136,10 @@ var CloudCmd, Util, DOM;
}
CONFIG[name] = data;
CloudCmd.setConfig(CONFIG);
Config.write(obj);
CloudCmd.set('config', CONFIG, function() {
Config.write(obj);
});
}
function onKey(event) {

View file

@ -334,10 +334,9 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
}
this.loadRemote = function(name, callback) {
var getConfig = CloudCmd.getConfig,
getModules = CloudCmd.getModules;
var Files = DOM.Files;
Util.exec.parallel([getConfig, getModules], function(error, config, modules) {
Files.get(['config', 'modules'], function(error, config, modules) {
var remoteTmpls, local, remote,
load = DOM.load,
online = config.online && navigator.onLine,
@ -1217,7 +1216,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
* @param callback
*/
this.saveDataToStorage = function(name, data, hash, callback) {
CloudCmd.getConfig(function(error, config) {
DOM.Files.get('config', function(error, config) {
var allowed = config.localStorage,
isDir = DOM.isCurrentIsDir(),
nameHash = name + '-hash',
@ -1250,7 +1249,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
* @param callback
*/
this.getDataFromStorage = function(name, callback) {
CloudCmd.getConfig(function(error, config) {
DOM.Files.get('config', function(error, config) {
var Storage = DOM.Storage,
nameHash = name + '-hash',
nameData = name + '-data',
@ -1581,7 +1580,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
};
this.getType = function(name, callback) {
CloudCmd.getExt(function(extensions) {
DOM.Files.get('ext', function(error, extensions) {
var index,
ext = Util.getExt(name);

View file

@ -230,7 +230,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Zip, MenuI
var path = Info.path,
value = Ace.getValue();
CloudCmd.getConfig(function(error, config) {
DOM.Files.get('config', function(error, config) {
var isDiff = config.diff,
isZip = config.zip;

108
lib/client/files.js Normal file
View file

@ -0,0 +1,108 @@
/* load and store templates data */
var Util, DOM;
(function(Util, DOM) {
var DOMProto = Object.getPrototypeOf(DOM);
DOMProto.Files = new FilesProto(Util, DOM);
function FilesProto(Util, DOM) {
var Files = this,
funcs = [],
Data = {},
DIR_HTML = '/html/',
DIR_HTML_FS = DIR_HTML + 'fs/',
DIR_JSON = '/json/';
this.get = function(name, callback) {
var type = Util.getType(name);
Util.checkArgs(arguments, ['name', 'callback']);
switch(type) {
case 'string':
getModule(name, callback);
break;
case 'array':
funcs = name.map(function(name) {
return function(callback) {
Files.get(name, callback);
};
});
Util.exec.parallel(funcs, callback);
break;
}
return Files;
};
this.set = function(name, data, callback) {
Util.checkArgs(arguments, [name, data]);
Data[name] = data;
callback(null);
return Files;
};
function getModule(name, callback) {
var path,
json = 'config|modules|ext',
html = 'file|path|link|pathLink',
regExpHTML = new RegExp(html),
regExpJSON = new RegExp(json),
isHTML = name.match(regExpHTML),
isJSON = name.match(regExpJSON);
if (isHTML) {
path = DIR_HTML_FS + name + '.html',
getSystemFile(Data[name], path , callback);
} else if (isJSON) {
if (name === 'config') {
getConfig(callback);
} else {
path = DIR_JSON + name + '.json';
getSystemFile(Data[name], path, callback);
}
} else {
throw(new Error('Wrong file name: ' + name));
}
}
function getSystemFile(global, url, callback) {
var success = Util.exec.with(callback, null);
Util.exec.if(global, success, function() {
DOM.load.ajax({
url : url,
success : function(local) {
global = local;
success(local);
},
error : function(error) {
callback(error);
}
});
});
}
function getConfig(callback) {
var func = Util.exec.with(callback, null);
Util.exec.if(Data.config, func, function(callback) {
var RESTful = DOM.RESTful;
RESTful.Config.read(function(config) {
Data.config = config;
callback(config);
});
});
}
}
})(Util, DOM);

View file

@ -9,7 +9,7 @@ var Util, DOM, CloudCmd;
var Info = DOM.CurrentInfo,
Storage = DOM.Storage,
Events = DOM.Events,
getConfig = CloudCmd.getConfig,
Files = DOM.Files,
EventsFiles = {
'mousedown' : Util.exec.with(execIfNotUL, setCurrentFileByEvent),
'contextmenu' : onContextMenu,
@ -20,7 +20,7 @@ var Util, DOM, CloudCmd;
};
this.analytics = function() {
getConfig(function(error, config) {
Files.get('config', function(error, config) {
var analytics = config.analytics,
online = config.online;
@ -241,7 +241,7 @@ var Util, DOM, CloudCmd;
}
function appStorage() {
getConfig(function(error, config) {
Files.get('config', function(error, config) {
var isAppStorage = config.appStorage,
appStorage = window.applicationStorage;

View file

@ -183,7 +183,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO;
}
function getUploadTo(callback) {
CloudCmd.getModules(function(error, modules) {
DOM.Files.get('modules', function(error, modules) {
var menu = {},
storage = Util.findObjByNameInArr(modules, 'storage'),
items = Util.getNamesFromObjArray(storage) || [];

View file

@ -26,7 +26,7 @@ var Util, DOM, CloudCmd;
});
this.send = function(msg) {
CloudCmd.getConfig(function(error, config) {
DOM.Files.get('config', function(error, config) {
var notify,
notifications = config.notifications,
focus = window.focus.bind(window),

View file

@ -64,7 +64,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dropbox, cb, Client;
* @param pData = {key, secret}
*/
this.login = function(callback) {
CloudCmd.getModules(function(error, modules){
DOM.Files.get('modules', function(error, modules){
var url = CloudCmd.HOST + '/html/auth/dropbox.html',
storage = Util.findObjByNameInArr(modules, 'storage'),
dropbox = Util.findObjByNameInArr(storage, 'DropBox'),

View file

@ -23,7 +23,7 @@ var Util, CloudCmd, DOM, Dropbox;
function load(){
Util.time('dropbox load');
CloudCmd.getConfig(function(error, config){
DOM.Files.get('config', function(error, config){
var element = DOM.load({
src : CHOOSER_API,
notAppend : true,

View file

@ -49,7 +49,7 @@ var CloudCmd, Util, DOM, filepicker;
Util.time('filepicker load');
DOM.load.js('//api.filepicker.io/v1/filepicker.js', function() {
CloudCmd.getModules(function(error, modules) {
DOM.Files.get('modules', function(error, modules) {
var storage = Util.findObjByNameInArr(modules, 'storage'),
picker = Util.findObjByNameInArr(storage, 'FilePicker'),
key = picker && picker.key;

View file

@ -16,7 +16,7 @@ var CloudCmd, Util, DOM, gapi;
var lUrl = 'https://apis.google.com/js/client.js';
DOM.load.js(lUrl, function() {
CloudCmd.getModules(function(error, modules) {
DOM.Files.get('modules', function(error, modules) {
var storage = Util.findObjByNameInArr(modules, 'storage'),
gDrive = Util.findObjByNameInArr(storage, 'GDrive'),
gDriveId = gDrive && gDrive.id,

View file

@ -25,7 +25,7 @@ var CloudCmd, Util, DOM, WL;
}
function auth() {
CloudCmd.getModules(function(error, modules){
DOM.Files.get('modules', function(error, modules){
var lStorage = Util.findObjByNameInArr(modules, 'storage'),
lSkyDrive = Util.findObjByNameInArr(lStorage, 'SkyDrive'),
lSkyDriveKey = lSkyDrive && lSkyDrive.id;

View file

@ -32,7 +32,7 @@ var CloudCmd, Util, DOM, VK;
}
function auth(callback) {
CloudCmd.getConfig(function(error, config){
DOM.Files.get('config', function(error, config){
var lDOCUMENTS_ACCESS = 131072;
VK.init({ apiId: config.vk_id});