summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-23 07:30:14 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-23 07:30:14 +0000
commit76b1500209e5c5becef180eae2abed78d18d09db (patch)
tree19c929f1a8183bb48db5e09dbbd8081c22644430 /core
parent69daaffb054f20574cb59078ce205920f4678da6 (diff)
Clean up the way that we upload via dialogs:
1) If the create request is Ajax, then return a 201 Created response code 2) If we receive back a 201 response, then switch to the new page. 3) Display a status message when we do an upload.
Diffstat (limited to 'core')
-rw-r--r--core/controllers/items.php33
-rw-r--r--core/helpers/photo.php3
2 files changed, 27 insertions, 9 deletions
diff --git a/core/controllers/items.php b/core/controllers/items.php
index 57be0046..b79d28d2 100644
--- a/core/controllers/items.php
+++ b/core/controllers/items.php
@@ -63,7 +63,13 @@ class Items_Controller extends REST_Controller {
$owner_id);
log::add("content", "Created an album", log::INFO,
html::anchor("albums/$album->id", "view album"));
- url::redirect("albums/$album->id");
+ message::add(_("Successfully created album"));
+ if (request::is_ajax()) {
+ rest::http_status(rest::CREATED);
+ rest::http_location(url::site("albums/$album->id"));
+ } else {
+ url::redirect("albums/$album->id");
+ }
break;
case "photo":
@@ -72,21 +78,28 @@ class Items_Controller extends REST_Controller {
for ($i = 0; $i < $count - 1; $i++) {
if ($_FILES["file"]["error"][$i] == 0) {
$photo = photo::create(
- $item->id,
+ $item,
$_FILES["file"]["tmp_name"][$i],
$_FILES["file"]["name"][$i],
$_FILES["file"]["name"][$i],
"", $owner_id);
} else {
- throw new Exception("@todo ERROR_IN_UPLOAD_FILE");
+ log::add("content", "Error uploading photo", log::WARNING);
+ message::add(sprintf(_("Error uploading photo %s"),
+ html::specialchars($_FILES["file"]["name"][$i])));
}
}
log::add("content", "Added $count photos", log::INFO,
html::anchor("albums/$item->id", "view album"));
- url::redirect("albums/$item->id");
+ if (request::is_ajax()) {
+ rest::http_status(rest::CREATED);
+ rest::http_location(url::site("albums/$item->id"));
+ } else {
+ url::redirect("albums/$item->id");
+ }
} else {
$photo = photo::create(
- $item->id,
+ $item,
$_FILES["file"]["tmp_name"],
$_FILES["file"]["name"],
$this->input->post("title", $this->input->post("name")),
@@ -94,14 +107,20 @@ class Items_Controller extends REST_Controller {
$owner_id);
log::add("content", "Added a photo", log::INFO,
html::anchor("photos/$photo->id", "view photo"));
- url::redirect("photos/$photo->id");
+ message::add(_("Successfully added photo"));
+ if (request::is_ajax()) {
+ rest::http_status(rest::CREATED);
+ rest::http_location(url::site("photos/$photo->id"));
+ } else {
+ url::redirect("photos/$photo->id");
+ }
}
break;
}
}
public function _delete($item) {
- // @todo Production this code
+ // @todo Productionize this code
// 1) Add security checks
$parent = $item->parent();
if ($parent->id) {
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index d8fc2595..e5ed2b22 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -95,8 +95,7 @@ class photo_Core {
}
static function get_add_form($parent) {
- $form = new Forge("albums/{$parent->id}", "", "post",
- array("id" => "gAddPhotoForm", "enctype" => "multipart/form-data"));
+ $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gAddPhotoForm"));
$group = $form->group("add_photo")->label(sprintf(_("Add Photo to %s"), $parent->title));
$group->input("name")->label(_("Name"));
$group->input("title")->label(_("Title"));