From 7d19747fa46c6ae7bd0c0940272004ef929fa658 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 14 Jan 2015 08:16:46 -0500 Subject: [PATCH] feature(edit) RESTful -> restafary --- lib/client/edit.js | 39 +++++++++++++++++++-------------------- lib/client/edward.js | 4 +++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index 8576a14d..71f15bf1 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -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); }); } diff --git a/lib/client/edward.js b/lib/client/edward.js index d5ae3f38..32510946 100644 --- a/lib/client/edward.js +++ b/lib/client/edward.js @@ -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); }); }