refactor(dom) saveDataToCache

This commit is contained in:
coderaiser 2013-11-19 12:44:59 +00:00
parent b7d4277f6d
commit 6a3dc106c6

View file

@ -1486,6 +1486,8 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
lName += lExt;
}
DOM.saveDataToCache(lName, pData);
Util.exec(pCallBack, {
data: pData,
name: lName
@ -1758,25 +1760,26 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
*/
this.saveDataToCache = function(name, data, callback) {
CloudCmd.getConfig(function(config) {
var cacheName,
allowed = config.localStorage;
var hash,
nameHash = name + '-hash',
nameData = name + '-data',
allowed = config.localStorage;
if (!allowed)
Util.exec(callback);
else {
cacheName = name + '-data';
hash = Cache.get(name + '-hash');
if (!!Cache.get(cacheName)) {
Cache.set(cacheName, data);
DOM.loadCurrentHash(function(hash) {
var isContain = Util.isContainStr(hash, 'error');
if (!isContain)
Cache.set(name + '-hash', hash);
Util.exec(callback, hash);
});
}
DOM.loadCurrentHash(function(pHash) {
var isContain = Util.isContainStr(hash, 'error');
if (!isContain && hash !== pHash) {
Cache.set(nameHash, pHash);
Cache.set(nameData, data);
}
Util.exec(callback, hash);
});
}
});
};