1
0

Force the respose type to be text/html to avoid the bug where the

buffering iframe doesn't know what to do with a JSON reply.

Print out an appropriate message after the upload completes.
This commit is contained in:
Bharat Mediratta 2010-08-01 10:23:57 -07:00
parent 8eec328a06
commit 351a9d16b3

View File

@ -39,6 +39,9 @@ class Uploader_Controller extends Controller {
if ($form->validate()) {
batch::start();
$count = 0;
$added_a_movie = false;
$added_a_photo = false;
foreach (array("file1", "file2", "file3") as $key) {
if ($form->add_photos->$key->value == "") {
continue;
@ -57,16 +60,18 @@ class Uploader_Controller extends Controller {
in_array(strtolower($path_info["extension"]), array("flv", "mp4", "m4v"))) {
$item->type = "movie";
$item->save();
$added_a_movie = true;
log::success("content", t("Added a movie"),
html::anchor("movies/$item->id", t("view movie")));
} else {
$item->type = "photo";
$item->save();
$added_a_photo = true;
log::success("content", t("Added a photo"),
html::anchor("photos/$item->id", t("view photo")));
}
$count++;
module::event("add_photos_form_completed", $item, $form);
} catch (Exception $e) {
// Lame error handling for now. Just record the exception and move on
Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
@ -83,10 +88,26 @@ class Uploader_Controller extends Controller {
}
}
batch::stop();
if ($count) {
if ($added_a_photo && $added_a_movie) {
message::success(t("Added %count photos and movies", array("count" => $count)));
} else if ($added_a_photo) {
message::success(t2("Added one photo", "Added %count photos", $count));
} else {
message::success(t2("Added one movie", "Added %count movies", $count));
}
}
json::reply(array("result" => "success"));
} else {
json::reply(array("result" => "error", "html" => (string) $form));
}
// Override the application/json mime type. The dialog based HTML uploader uses an iframe to
// buffer the reply, and on some browsers (Firefox 3.6) it does not know what to do with the
// JSON that it gets back so it puts up a dialog asking the user what to do with it. So force
// the encoding type back to HTML for the iframe.
// See: http://jquery.malsup.com/form/#file-upload
header("Content-Type: text/html; charset=" . Kohana::CHARSET);
}
private function _get_add_form($album) {