mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(util) spead improvement; exec: rm condition
This commit is contained in:
parent
1fa1d70699
commit
2064e9991b
5 changed files with 34 additions and 75 deletions
|
|
@ -1056,53 +1056,35 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
* @pCallBack - function({data, name}) {}
|
||||
* @pCurrentFile
|
||||
*/
|
||||
this.getCurrentData = function(pCallBack, pCurrentFile) {
|
||||
var lParams,
|
||||
lHash,
|
||||
ONE_MEGABYTE = 1024 * 1024 * 1024,
|
||||
this.getCurrentData = function(callback, pCurrentFile) {
|
||||
var lHash,
|
||||
lCurrentFile = pCurrentFile ? pCurrentFile : Cmd.getCurrentFile(),
|
||||
lPath = DOM.getCurrentPath(lCurrentFile),
|
||||
path = DOM.getCurrentPath(lCurrentFile),
|
||||
isDir = DOM.isCurrentIsDir(lCurrentFile),
|
||||
|
||||
lFunc = function(pData) {
|
||||
var length = pData.length,
|
||||
lExt = '.json',
|
||||
lName = DOM.getCurrentName(lCurrentFile);
|
||||
func = function(data, hash) {
|
||||
var length,
|
||||
ONE_MEGABYTE = 1024 * 1024 * 1024;
|
||||
|
||||
if (Util.isObject(pData)) {
|
||||
pData = Util.stringifyJSON(pData);
|
||||
|
||||
if (!Util.checkExtension(lName, lExt))
|
||||
lName += lExt;
|
||||
}
|
||||
if (Util.isObject(data))
|
||||
data = Util.stringifyJSON(data);
|
||||
|
||||
length = data.length;
|
||||
if (lHash && length < ONE_MEGABYTE)
|
||||
DOM.saveDataToStorage(lPath, pData, lHash);
|
||||
DOM.saveDataToStorage(path, data, lHash);
|
||||
|
||||
Util.exec(pCallBack, {
|
||||
data: pData,
|
||||
name: lName
|
||||
});
|
||||
Util.exec(callback, data);
|
||||
};
|
||||
|
||||
if (!Util.isObject(pCallBack))
|
||||
lParams = lFunc;
|
||||
else
|
||||
lParams = {
|
||||
success : lFunc,
|
||||
error : pCallBack.error
|
||||
};
|
||||
|
||||
|
||||
if (isDir)
|
||||
DOM.getCurrentFileContent(lParams, lCurrentFile);
|
||||
DOM.getCurrentFileContent(func, lCurrentFile);
|
||||
else
|
||||
DOM.checkStorageHash(lPath, function(error, equal, hash) {
|
||||
DOM.checkStorageHash(path, function(error, equal, hash) {
|
||||
Util.ifExec(!error && equal, function() {
|
||||
DOM.getDataFromStorage(lPath, lFunc);
|
||||
DOM.getDataFromStorage(path, callback);
|
||||
}, function() {
|
||||
lHash = hash;
|
||||
DOM.getCurrentFileContent(lParams, lCurrentFile);
|
||||
DOM.getCurrentFileContent(func, lCurrentFile);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -77,17 +77,10 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch;
|
|||
CloudCmd.View.show(Element, focus);
|
||||
Key.unsetBind();
|
||||
} else
|
||||
Info.getData({
|
||||
success : function(pData) {
|
||||
var lValue = '';
|
||||
|
||||
if (pData)
|
||||
lValue = pData.data;
|
||||
|
||||
Value = lValue;
|
||||
Ace.setValue(lValue);
|
||||
CloudCmd.View.show(Element, focus);
|
||||
}
|
||||
Info.getData(function(data) {
|
||||
Value = data;
|
||||
Ace.setValue(data);
|
||||
CloudCmd.View.show(Element, focus);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -79,8 +79,12 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
}
|
||||
else if (Util.isString(pObjectName)) {
|
||||
lObj = function(key, opt) {
|
||||
Info.getData(function(pParams) {
|
||||
CloudCmd.execFromModule(pObjectName, 'uploadFile', pParams);
|
||||
Info.getData(function(data) {
|
||||
var name = Info.name;
|
||||
CloudCmd.execFromModule(pObjectName, 'uploadFile', {
|
||||
name: name,
|
||||
data: data
|
||||
});
|
||||
});
|
||||
|
||||
Util.log('Uploading to ' + pObjectName+ '...');
|
||||
|
|
|
|||
|
|
@ -44,26 +44,14 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
}
|
||||
|
||||
function init() {
|
||||
var lFunc, lIsFunc, lIsCallBack;
|
||||
var func = CallBack || Util.bind(show, null);
|
||||
|
||||
Loading = true;
|
||||
|
||||
if (CallBack) {
|
||||
lIsFunc = Util.isFunction(CallBack);
|
||||
lIsCallBack = Util.isFunction(CallBack.callback);
|
||||
}
|
||||
|
||||
if (lIsFunc)
|
||||
lFunc = CallBack;
|
||||
else if (lIsCallBack)
|
||||
lFunc = CallBack.callback;
|
||||
else
|
||||
lFunc = Util.retExec(View.show, null);
|
||||
|
||||
Util.loadOnLoad([
|
||||
DOM.jqueryLoad,
|
||||
load,
|
||||
lFunc
|
||||
func
|
||||
]);
|
||||
|
||||
Events.addKey(listener);
|
||||
|
|
@ -100,12 +88,12 @@ var CloudCmd, Util, DOM, CloudFunc, $;
|
|||
if (isImage) {
|
||||
$.fancybox.open({ href : lPath }, Config);
|
||||
} else
|
||||
Info.getData(function(pParams) {
|
||||
var data = document.createTextNode(pParams.data);
|
||||
Info.getData(function(data) {
|
||||
var element = document.createTextNode(data);
|
||||
/* add margin only for view text documents */
|
||||
Element.css('margin', '2%');
|
||||
|
||||
$.fancybox(Element.append(data), Config);
|
||||
$.fancybox(Element.append(element), Config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
lib/util.js
16
lib/util.js
|
|
@ -849,19 +849,11 @@
|
|||
* @param pArgN
|
||||
*/
|
||||
this.exec = function(callback) {
|
||||
var ret, args = Util.slice(arguments);
|
||||
|
||||
args.shift();
|
||||
var ret,
|
||||
args = Util.slice(arguments, 1);
|
||||
|
||||
if (callback) {
|
||||
if (Util.isFunction(callback))
|
||||
ret = callback.apply(null, args);
|
||||
else {
|
||||
callback = callback.callback || callback.success;
|
||||
args.unshift(callback);
|
||||
ret = Util.exec.apply(null, args);
|
||||
}
|
||||
}
|
||||
if (Util.isFunction(callback))
|
||||
ret = callback.apply(null, args);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue