aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/networking/sdl_net/handlers/createdirectoryhandler.cpp32
-rw-r--r--backends/networking/sdl_net/handlers/createdirectoryhandler.h2
-rw-r--r--backends/networking/wwwroot.zipbin241963 -> 242704 bytes
-rw-r--r--backends/networking/wwwroot/.filesAJAX.html34
4 files changed, 58 insertions, 10 deletions
diff --git a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp
index fc02b643c1..2ded9785a0 100644
--- a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp
+++ b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp
@@ -38,25 +38,25 @@ void CreateDirectoryHandler::handle(Client &client) {
// check that <path> is not an absolute root
if (path == "" || path == "/") {
- HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Can't create directory here!"));
+ handleError(client, _("Can't create directory here!"));
return;
}
// transform virtual path to actual file system one
Common::String prefixToRemove = "", prefixToAdd = "";
if (!transformPath(path, prefixToRemove, prefixToAdd) || path.empty()) {
- HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Invalid path!"));
+ handleError(client, _("Invalid path!"));
return;
}
// check that <path> exists and is directory
AbstractFSNode *node = g_system->getFilesystemFactory()->makeFileNodePath(path);
if (!node->exists()) {
- HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Parent directory doesn't exists!"));
+ handleError(client, _("Parent directory doesn't exists!"));
return;
}
if (!node->isDirectory()) {
- HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Can't create a directory within a file!"));
+ handleError(client, _("Can't create a directory within a file!"));
return;
}
@@ -65,17 +65,23 @@ void CreateDirectoryHandler::handle(Client &client) {
node = g_system->getFilesystemFactory()->makeFileNodePath(path + name);
if (node->exists()) {
if (!node->isDirectory()) {
- HandlerUtils::setFilesManagerErrorMessageHandler(client, _("There is a file with that name in the parent directory!"));
+ handleError(client, _("There is a file with that name in the parent directory!"));
return;
}
} else {
// create the <directory_name> in <path>
if (!node->create(true)) {
- HandlerUtils::setFilesManagerErrorMessageHandler(client, _("Failed to create the directory!"));
+ handleError(client, _("Failed to create the directory!"));
return;
}
}
+ // if json requested, respond with it
+ if (client.queryParameter("answer_json") == "true") {
+ setJsonResponseHandler(client, "success", _("Directory created successfully!"));
+ return;
+ }
+
// set redirect on success
HandlerUtils::setMessageHandler(
client,
@@ -91,6 +97,20 @@ void CreateDirectoryHandler::handle(Client &client) {
);
}
+void CreateDirectoryHandler::handleError(Client &client, Common::String message) const {
+ if (client.queryParameter("answer_json") == "true") setJsonResponseHandler(client, "error", message);
+ else HandlerUtils::setFilesManagerErrorMessageHandler(client, message);
+}
+
+void CreateDirectoryHandler::setJsonResponseHandler(Client &client, Common::String type, Common::String message) const {
+ Common::JSONObject response;
+ response.setVal("type", new Common::JSONValue(type));
+ response.setVal("message", new Common::JSONValue(message));
+
+ Common::JSONValue json = response;
+ LocalWebserver::setClientGetHandler(client, json.stringify(true));
+}
+
/// public
ClientHandlerCallback CreateDirectoryHandler::getHandler() {
diff --git a/backends/networking/sdl_net/handlers/createdirectoryhandler.h b/backends/networking/sdl_net/handlers/createdirectoryhandler.h
index 2ffaf96f1f..bd0e8874da 100644
--- a/backends/networking/sdl_net/handlers/createdirectoryhandler.h
+++ b/backends/networking/sdl_net/handlers/createdirectoryhandler.h
@@ -29,6 +29,8 @@ namespace Networking {
class CreateDirectoryHandler: public FilesBaseHandler {
void handle(Client &client);
+ void handleError(Client &client, Common::String message) const;
+ void setJsonResponseHandler(Client &client, Common::String type, Common::String message) const;
public:
CreateDirectoryHandler();
virtual ~CreateDirectoryHandler();
diff --git a/backends/networking/wwwroot.zip b/backends/networking/wwwroot.zip
index 6f821d9090..b767d7c5d7 100644
--- a/backends/networking/wwwroot.zip
+++ b/backends/networking/wwwroot.zip
Binary files differ
diff --git a/backends/networking/wwwroot/.filesAJAX.html b/backends/networking/wwwroot/.filesAJAX.html
index d648466d2c..f736b74b7e 100644
--- a/backends/networking/wwwroot/.filesAJAX.html
+++ b/backends/networking/wwwroot/.filesAJAX.html
@@ -17,7 +17,7 @@
</tr></table>
<div id="create_directory" class="modal">
<p>{create_directory_desc}</p>
- <form action="create" id="create_directory_form">
+ <form action="create" id="create_directory_form" onsubmit="return createDirectory();">
<input type="hidden" name="path" value="{path}"/>
<input type="hidden" name="ajax" value="true"/>
<input type="text" name="directory_name" value=""/>
@@ -71,6 +71,32 @@
function getCallback(path) {
return function (jsonResponse) {
+ if (jsonResponse.type == "error") {
+ showError();
+ return;
+ }
+
+ openDirectory(path, jsonResponse.items);
+ hideLoading();
+ };
+ }
+
+ function createDirectory() {
+ if (isLoading) return;
+ showLoading();
+
+ var data = {"answer_json": "true"};
+ var elements = document.getElementById("create_directory_form").elements;
+ for (var el in elements)
+ data[elements[el].name] = elements[el].value;
+
+ ajax.getAndParseJson("./create", data, getCreateDirectoryCallback(data["path"]));
+ show("create_directory");
+ return false; // invalidate form, so it won't submit
+ }
+
+ function getCreateDirectoryCallback(path) {
+ return function (jsonResponse) {
console.log(jsonResponse);
if (jsonResponse.type == "error") {
@@ -78,8 +104,8 @@
return;
}
- openDirectory(path, jsonResponse.items);
hideLoading();
+ showDirectory(path);
};
}
@@ -122,7 +148,7 @@
function makeBreadcrumb(name, path) {
var a = createElementWithContents("a", name);
a.onclick = function () { showDirectory(path); };
- a.href = "javascript:onclick();";
+ a.href = "javascript:void(0);";
return a;
}
@@ -194,7 +220,7 @@
var a = createElementWithContents("a", item.name);
if (item.isDirectory) {
a.onclick = function () { showDirectory(item.path); };
- a.href = "javascript:onclick();";
+ a.href = "javascript:void(0);";
} else
a.href = "./download?path=" + encodeURIComponent(item.path);
td.appendChild(a);