CLOUD: Add "ajax" parameter for "/create" and "/upload"

If it's set, these redirect to "/filesAJAX" instead of "/files".
This commit is contained in:
Alexander Tkachev 2016-07-19 13:41:25 +06:00
parent e6caa482e1
commit da229dd84c
5 changed files with 26 additions and 7 deletions

View file

@ -85,7 +85,9 @@ void CreateDirectoryHandler::handle(Client &client) {
client.queryParameter("path").c_str(),
_("Back to parent directory")
),
"/files?path=" + LocalWebserver::urlEncodeQueryParameterValue(client.queryParameter("path"))
(client.queryParameter("ajax") == "true" ? "/filesAJAX?path=" : "/files?path=") +
LocalWebserver::urlEncodeQueryParameterValue(client.queryParameter("path"))
);
}

View file

@ -33,6 +33,19 @@ FilesAjaxPageHandler::FilesAjaxPageHandler() {}
FilesAjaxPageHandler::~FilesAjaxPageHandler() {}
namespace {
Common::String encodeDoubleQuotesAndSlashes(Common::String s) {
Common::String result = "";
for (uint32 i = 0; i < s.size(); ++i)
if (s[i] == '"') {
result += "\\\"";
} else if (s[i] == '\\') {
result += "\\\\";
} else result += s[i];
return result;
}
}
void FilesAjaxPageHandler::handle(Client &client) {
// load stylish response page from the archive
Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME);
@ -55,6 +68,7 @@ void FilesAjaxPageHandler::handle(Client &client) {
replace(response, "{index_of}", _("Index of "));
replace(response, "{loading}", _("Loading..."));
replace(response, "{error}", _("Error occurred"));
replace(response, "{start_path}", encodeDoubleQuotesAndSlashes(path));
LocalWebserver::setClientGetHandler(client, response);
}

View file

@ -160,7 +160,9 @@ void UploadFileClientHandler::handleBlockContent(Client *client) {
client->queryParameter("path").c_str(),
_("Back to parent directory")
),
"/files?path=" + LocalWebserver::urlEncodeQueryParameterValue(client->queryParameter("path"))
(client->queryParameter("ajax") == "true" ? "/filesAJAX?path=" : "/files?path=") +
LocalWebserver::urlEncodeQueryParameterValue(client->queryParameter("path"))
);
_state = UFH_STOP;
return;

Binary file not shown.

View file

@ -19,13 +19,14 @@
<p>{create_directory_desc}</p>
<form action="create" id="create_directory_form">
<input type="hidden" name="path" value="{path}"/>
<input type="hidden" name="ajax" value="true"/>
<input type="text" name="directory_name" value=""/>
<input type="submit" value="{create_directory_button}"/>
</form>
</div>
<div id="upload_file" class="modal">
<p>{upload_file_desc}</p>
<form action="upload?path={path}" method="post" enctype="multipart/form-data" id="files_upload_form">
<form action="upload?path={path}&ajax=true" method="post" enctype="multipart/form-data" id="files_upload_form">
<!-- we don't need "[]" in the name, as our webserver is not using PHP -->
<!-- "allowdirs" is a proposal, not implemented yet -->
<input type="file" name="upload_file-f" allowdirs multiple/>
@ -59,7 +60,7 @@
<script src="ajax.js"></script>
<script>
window.onload = function () {
showDirectory("/");
showDirectory("{start_path}");
}
function showDirectory(path) {
@ -112,7 +113,7 @@
function openDirectory(path, items) {
// update path
document.getElementById("create_directory_form").elements["path"].value = path;
document.getElementById("files_upload_form").action = "upload?path=" + path;
document.getElementById("files_upload_form").action = "upload?path=" + path + "&ajax=true";
// update table contents
listDirectory(path, items);