feature(rest) add put patch

This commit is contained in:
coderaiser 2013-07-15 13:28:05 +00:00
parent d2ba63e050
commit ee5d3bc7e9
5 changed files with 57 additions and 21 deletions

View file

@ -116,10 +116,10 @@ var CloudCmd, Util, DOM, CloudFunc;
});
};
this.save = function(pUrl, pData, pCallBack){
this.save = function(pUrl, pData, pCallBack, pQuery){
sendRequest({
method : 'PUT',
url : CloudFunc.FS + pUrl,
url : CloudFunc.FS + pUrl + (pQuery || ''),
data : pData,
callback : pCallBack,
imgPosition : { top: true }

View file

@ -73,10 +73,26 @@ var CloudCmd, Util, DOM, JsDiff, ace;
exec : function (pEditor) {
var lCurrent = DOM.getCurrentFile(),
lPath = DOM.getCurrentPath(lCurrent),
lValue = Ace.getValue();
lName = DOM.getCurrentName(lCurrent),
lValue = Ace.getValue(),
lLength = lValue.length;
DOM.setCurrentSize( lValue.length, lCurrent );
DOM.RESTfull.save( lPath, lValue );
DOM.setCurrentSize( lLength, lCurrent );
diff(lName, lValue, function(pDiff) {
var lData,
lPatch = '',
lDiffLength = pDiff.length;
if (lDiffLength >= lLength)
lData = lValue;
else {
lData = pDiff;
lPatch = '?patch';
}
DOM.RESTfull.save( lPath, lData, null, lPatch);
});
}
});
}
@ -112,16 +128,13 @@ var CloudCmd, Util, DOM, JsDiff, ace;
Ace.moveCursorTo(0, 0);
}
this.diff = function(pName){
var lName = DOM.getCurrentName(),
lNewValue = Ace.getValue();
function diff(pName, pNewValue, pCallBack){
DOM.jsload('/lib/util/jsdiff/diff.js', function(){
var lPatch = JsDiff.createPatch(lName, Value, lNewValue);
var lPatch = JsDiff.createPatch(pName, Value, pNewValue);
Util.log(lPatch);
Util.exec(pCallBack, lPatch);
});
};
}
function load(pCallBack){
Util.time(Name + ' load');