feature(edit) RESTful -> restafary

This commit is contained in:
coderaiser 2015-01-14 08:16:46 -05:00
parent cb2d09ab07
commit 7d19747fa4
2 changed files with 22 additions and 21 deletions

View file

@ -1,4 +1,4 @@
var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward, restafary;
(function(CloudCmd, Util, DOM, CloudFunc) {
'use strict';
@ -22,7 +22,6 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
Menu,
RESTful = DOM.RESTful,
Dialog = DOM.Dialog,
Images = DOM.Images,
Element, JSHintConfig,
@ -86,7 +85,7 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
});
socket.on('message', function(msg) {
onSave(msg);
onSave(null, msg);
});
socket.on('patch', function(name, data, hash) {
@ -361,11 +360,11 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
Edit.save.write = writeHttp;
function patchHttp(path, patch) {
RESTful.patch(path, patch, onSave);
restafary.patch(path, patch, onSave);
}
function writeHttp(path, result) {
RESTful.write(path, result, onSave);
restafary.write(path, result, onSave);
}
function doDiff(path, callback) {
@ -501,13 +500,17 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
});
}
function onSave(text) {
function onSave(error, text) {
var ret,
size = Format.size(Value.length),
isError = /^error/.test(text),
msg = '\nShould I save file anyway?';
if (!isError) {
if (error) {
ret = Dialog.confirm(text + msg);
if (ret)
restafary.write(FileName, Value, onSave);
} else {
Edit.showMessage(text);
sha(function(error, hash) {
@ -518,11 +521,6 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
});
DOM.setCurrentSize(size);
} else {
ret = Dialog.confirm(text + msg);
if (ret)
RESTful.write(FileName, Value, onSave);
}
}
@ -584,13 +582,14 @@ var CloudCmd, Util, DOM, CloudFunc, io, ace, Zip, Format, MenuIO, edward;
function readWithFlag(flag) {
var path = FileName;
Util.check(arguments, ['flag']);
RESTful.read(path + '?' + flag, function(data) {
edward
.setValue(data)
.clearSelection()
.moveCursorTo(0, 0);
restafary.read(path + '?' + flag, function(error, data) {
if (error)
alert(error);
else
edward
.setValue(data)
.clearSelection()
.moveCursorTo(0, 0);
});
}

View file

@ -87,6 +87,7 @@ var join, ace, Util, DOM;
edward.setValue = function(value) {
Ace.setValue(value);
return edward;
};
edward.setValueFirst = function(value) {
@ -171,6 +172,7 @@ var join, ace, Util, DOM;
function loadFiles(callback) {
var css = '/css/edward.css',
js = '/restafary.js',
dir = '/modules/ace-builds/src-noconflict/',
url = join([
'theme-tomorrow_night_blue',
@ -182,7 +184,7 @@ var join, ace, Util, DOM;
}));
loadRemote('ace', function() {
load.parallel([url, css], callback);
load.parallel([url, js, css], callback);
});
}