From aa0f2e9f4c992f5463c5bcd508968c4f35ead6f4 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 9 Sep 2014 10:45:40 -0400 Subject: [PATCH] feature(client) createFileTable: add error check --- lib/client.js | 79 +++++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/lib/client.js b/lib/client.js index 56555259..d65d3c1f 100644 --- a/lib/client.js +++ b/lib/client.js @@ -362,52 +362,57 @@ var Util, DOM, CloudFunc; Files.get(names, function(error, templFile, templPath, templLink, templPathLink) { var n, found, varCurrent, varName, current, + Dialog = DOM.Dialog, dir = DOM.getCurrentDirName(), name = DOM.getCurrentName(), i = panel.childNodes.length; - while (i--) - panel.removeChild(panel.lastChild); - - panel.innerHTML = CloudFunc.buildFromJSON({ - data : json, - id : panel.id, - template : { - file : templFile, - path : templPath, - pathLink : templPathLink, - link : templLink - } - }); - - files = DOM.getFiles(panel); - - /* searching current file */ - if (wasRefresh) { - n = files.length; + if (error) { + Dialog.alert(error.responseText); + } else { + while (i--) + panel.removeChild(panel.lastChild); - for (i = 0; i < n ; i++) { - varCurrent = files[i], - varName = DOM.getCurrentName(varCurrent); - found = varName === name; + panel.innerHTML = CloudFunc.buildFromJSON({ + data : json, + id : panel.id, + template : { + file : templFile, + path : templPath, + pathLink : templPathLink, + link : templLink + } + }); + + files = DOM.getFiles(panel); + + /* searching current file */ + if (wasRefresh) { + n = files.length; - if (found) { - current = files[i]; - break; + for (i = 0; i < n ; i++) { + varCurrent = files[i], + varName = DOM.getCurrentName(varCurrent); + found = varName === name; + + if (found) { + current = files[i]; + break; + } } } + if (!found) /* .. */ + current = files[0]; + + DOM.setCurrentFile(current, { + history: history + }); + + Listeners.setOnPanel(panel.id); + + if (name === '..' && dir !== '/') + currentToParent(dir); } - if (!found) /* .. */ - current = files[0]; - - DOM.setCurrentFile(current, { - history: history - }); - - Listeners.setOnPanel(panel.id); - - if (name === '..' && dir !== '/') - currentToParent(dir); }); }