From 1ae9256a566c578c540f6e5c053426b0cc22d6b7 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 18 Nov 2013 12:27:41 +0000 Subject: [PATCH] feature(edit) if on server would be error with diff, try to save without diff --- lib/client/edit.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/client/edit.js b/lib/client/edit.js index f4f3a8d4..048dc495 100644 --- a/lib/client/edit.js +++ b/lib/client/edit.js @@ -15,6 +15,7 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; Ace, Msg, Key = CloudCmd.Key, + Dialog = DOM.Dialog, Images = DOM.Images, Element; @@ -131,12 +132,9 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; query = '?patch'; } - DOM.RESTful.save(lPath, lValue, Edit.showMessage, query); + DOM.RESTful.save(lPath, lValue, onSave, query); }, function(callback) { - diff(lValue, function(diff) { - Value = lValue; - Util.exec(callback, diff); - }); + diff(lValue, callback); }); }); } @@ -188,6 +186,24 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch; } } + function onSave(text) { + var ret, + isError = Util.isContainStrAtBegin(text, 'error'), + path = DOM.getCurrentPath(), + msg = '\nShould I save file anyway?'; + + if (!isError) + Edit.showMessage(text); + else { + ret = Dialog.confirm(text + msg); + + if (ret) { + DOM.RESTful.save(path, Value, onSave); + Value = Ace.getValue(); + } + } + } + this.showMessage = function(text) { var parent, TWO_SECONDS = 2000;