diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-07-31 21:16:17 -0700 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-07-31 21:16:17 -0700 |
commit | 7607e1f932dda53144792d0b7e8674a34fbc7f9a (patch) | |
tree | 5b312e8a82d19c05928d22165545d0adf13ebff1 /modules/gallery/controllers | |
parent | be4ad8e96d53f04a8f975aedde625a1f3e17dafd (diff) |
Full pass over all the JSON encoding and JS dialog code. We now abide
by the following rules:
1) An initial dialog or panel load can take either HTML or JSON, but
the mime type must accurately reflect its payload.
2) dialog form submits can handle a pure HTML response, but the mime
type must also be correct. This properly resolves the problem
where the reauth code gets a JSON response first from the reauth
code, and then an HTML response when you reauth and continue on to
a given form -- try it out with Admin > Settings > Advanced.
3) All JSON replies must set the mime type correctly. The json::reply
convenience function does this for us.
4) By default, any HTML content sent back in the JSON response should be
in the "html" field, no longer the "form" field.
The combination of these allows us to stop doing boilerplate code like
this in our controllers:
// Print our view, JSON encoded
json::reply(array("form" => (string) $view));
instead, controllers can just return HTML, eg:
// Print our view
print $view;
That's much more intuitive for developers.
Diffstat (limited to 'modules/gallery/controllers')
-rw-r--r-- | modules/gallery/controllers/admin_advanced_settings.php | 2 | ||||
-rw-r--r-- | modules/gallery/controllers/admin_maintenance.php | 24 | ||||
-rw-r--r-- | modules/gallery/controllers/admin_themes.php | 2 | ||||
-rw-r--r-- | modules/gallery/controllers/albums.php | 8 | ||||
-rw-r--r-- | modules/gallery/controllers/login.php | 4 | ||||
-rw-r--r-- | modules/gallery/controllers/move.php | 2 | ||||
-rw-r--r-- | modules/gallery/controllers/movies.php | 4 | ||||
-rw-r--r-- | modules/gallery/controllers/permissions.php | 2 | ||||
-rw-r--r-- | modules/gallery/controllers/photos.php | 4 | ||||
-rw-r--r-- | modules/gallery/controllers/quick.php | 7 | ||||
-rw-r--r-- | modules/gallery/controllers/reauthenticate.php | 6 | ||||
-rw-r--r-- | modules/gallery/controllers/uploader.php | 3 | ||||
-rw-r--r-- | modules/gallery/controllers/user_profile.php | 4 |
13 files changed, 35 insertions, 37 deletions
diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php index 086f7603..cf197743 100644 --- a/modules/gallery/controllers/admin_advanced_settings.php +++ b/modules/gallery/controllers/admin_advanced_settings.php @@ -39,7 +39,7 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller { $group->input("var_name")->label(t("Setting"))->value($var_name)->disabled(1); $group->textarea("value")->label(t("Value"))->value($value); $group->submit("")->value(t("Save")); - json::reply(array("form" => (string) $form)); + print $form; } public function save($module_name, $var_name) { diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 5d06d224..3567b4f0 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -64,7 +64,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { log::info("tasks", t("Task %task_name started (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); - json::reply(array("form" => (string) $view)); + print $view; } /** @@ -86,7 +86,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { log::info("tasks", t("Task %task_name resumed (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); - json::reply(array("form" => (string) $view)); + print $view; } /** @@ -103,7 +103,7 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view = new View("admin_maintenance_show_log.html"); $view->task = $task; - json::reply(array("form" => (string) $view)); + print $view; } /** @@ -212,18 +212,18 @@ class Admin_Maintenance_Controller extends Admin_Controller { } // Using sprintf("%F") to avoid comma as decimal separator. json::reply(array("result" => "success", - "task" => array( - "percent_complete" => sprintf("%F", $task->percent_complete), - "status" => (string) $task->status, - "done" => (bool) $task->done), - "location" => url::site("admin/maintenance"))); + "task" => array( + "percent_complete" => sprintf("%F", $task->percent_complete), + "status" => (string) $task->status, + "done" => (bool) $task->done), + "location" => url::site("admin/maintenance"))); } else { json::reply(array("result" => "in_progress", - "task" => array( - "percent_complete" => sprintf("%F", $task->percent_complete), - "status" => (string) $task->status, - "done" => (bool) $task->done))); + "task" => array( + "percent_complete" => sprintf("%F", $task->percent_complete), + "status" => (string) $task->status, + "done" => (bool) $task->done))); } } } diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php index 18a4d2ae..e59eadaf 100644 --- a/modules/gallery/controllers/admin_themes.php +++ b/modules/gallery/controllers/admin_themes.php @@ -52,7 +52,7 @@ class Admin_Themes_Controller extends Admin_Controller { } else { $view->url = item::root()->url("theme=$theme_name"); } - json::reply(array("form" => (string) $view)); + print $view; } public function choose($type, $theme_name) { diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 584e4f15..f3f5dee3 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -115,7 +115,7 @@ class Albums_Controller extends Items_Controller { json::reply(array("result" => "success", "location" => $album->url())); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + print $form; } } @@ -159,7 +159,7 @@ class Albums_Controller extends Items_Controller { json::reply(array("result" => "success")); } } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -168,7 +168,7 @@ class Albums_Controller extends Items_Controller { access::required("view", $album); access::required("add", $album); - json::reply(array("form" => (string) album::get_add_form($album))); + print album::get_add_form($album); } public function form_edit($album_id) { @@ -176,6 +176,6 @@ class Albums_Controller extends Items_Controller { access::required("view", $album); access::required("edit", $album); - json::reply(array("form" => (string) album::get_edit_form($album))); + print album::get_edit_form($album); } } diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index d7ab399f..62d33345 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -22,7 +22,7 @@ class Login_Controller extends Controller { public function ajax() { $view = new View("login_ajax.html"); $view->form = auth::get_login_form("login/auth_ajax"); - json::reply(array("form" => (string) $view)); + print $view; } public function auth_ajax() { @@ -34,7 +34,7 @@ class Login_Controller extends Controller { } else { $view = new View("login_ajax.html"); $view->form = $form; - json::reply(array("result" => "error", "form" => (string) $view)); + json::reply(array("result" => "error", "html" => (string)$view)); } } diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index c47cdd95..7b2d6165 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -26,7 +26,7 @@ class Move_Controller extends Controller { $view = new View("move_browse.html"); $view->source = $source; $view->tree = $this->_get_tree_html($source, ORM::factory("item", 1)); - json::reply(array("form" => (string) $view)); + print $view; } public function save($source_id) { diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index fe6669e6..02d2a497 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -93,7 +93,7 @@ class Movies_Controller extends Items_Controller { json::reply(array("result" => "success")); } } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } } @@ -102,6 +102,6 @@ class Movies_Controller extends Items_Controller { access::required("view", $movie); access::required("edit", $movie); - json::reply(array("form" => (string) movie::get_edit_form($movie))); + print movie::get_edit_form($movie); } } diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php index 57f5ccb6..fc06cb44 100644 --- a/modules/gallery/controllers/permissions.php +++ b/modules/gallery/controllers/permissions.php @@ -33,7 +33,7 @@ class Permissions_Controller extends Controller { $view->parents = $item->parents(); $view->form = $this->_get_form($item); - json::reply(array("form" => (string) $view)); + print $view; } function form($id) { diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 7c834e64..8377e6c7 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -93,7 +93,7 @@ class Photos_Controller extends Items_Controller { json::reply(array("result" => "success")); } } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -102,6 +102,6 @@ class Photos_Controller extends Items_Controller { access::required("view", $photo); access::required("edit", $photo); - json::reply(array("form" => (string) photo::get_edit_form($photo))); + print photo::get_edit_form($photo); } } diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 1d9194c7..fee601d9 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -94,7 +94,7 @@ class Quick_Controller extends Controller { $v = new View("quick_delete_confirm.html"); $v->item = $item; $v->form = item::get_delete_form($item); - json::reply(array("form" => (string) $v)); + print $v; } public function delete($id) { @@ -127,8 +127,7 @@ class Quick_Controller extends Controller { $from_id != $id /* deleted the item we were viewing */) { json::reply(array("result" => "success", "reload" => 1)); } else { - json::reply(array("result" => "success", - "location" => $parent->url())); + json::reply(array("result" => "success", "location" => $parent->url())); } } @@ -154,6 +153,6 @@ class Quick_Controller extends Controller { // Pass on the source item where this form was generated, so we have an idea where to return to. $form->hidden("from_id")->value((int)Input::instance()->get("from_id", 0)); - json::reply(array("form" => (string) $form)); + print $form; } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 7f9e5edc..0486c0fe 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Reauthenticate_Controller extends Controller { - public function index($share_translations_form=null) { + public function index() { if (!identity::active_user()->admin) { access::forbidden(); } @@ -29,7 +29,7 @@ class Reauthenticate_Controller extends Controller { $v = new View("reauthenticate.html"); $v->form = self::_form(); $v->user_name = identity::active_user()->name; - json::reply(array("form" => (string) $v)); + print $v; } else { self::_show_form(self::_form()); } @@ -58,7 +58,7 @@ class Reauthenticate_Controller extends Controller { $v = new View("reauthenticate.html"); $v->form = $form; $v->user_name = identity::active_user()->name; - json::reply(array("form" => (string) $v)); + json::reply(array("html" => (string)$v)); } else { self::_show_form($form); } diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php index c686c787..87520032 100644 --- a/modules/gallery/controllers/uploader.php +++ b/modules/gallery/controllers/uploader.php @@ -26,8 +26,7 @@ class Uploader_Controller extends Controller { $item = $item->parent(); } - json::reply(array("form" => (string)$this->_get_add_form($item))); - //print $this->_get_add_form($item); + print $this->_get_add_form($item); } public function start() { diff --git a/modules/gallery/controllers/user_profile.php b/modules/gallery/controllers/user_profile.php index 113be1fa..726d3e51 100644 --- a/modules/gallery/controllers/user_profile.php +++ b/modules/gallery/controllers/user_profile.php @@ -44,7 +44,7 @@ class User_Profile_Controller extends Controller { public function contact($id) { $user = identity::lookup_user($id); - json::reply(array("form" => (string) user_profile::get_contact_form($user))); + print user_profile::get_contact_form($user); } public function send($id) { @@ -63,7 +63,7 @@ class User_Profile_Controller extends Controller { message::success(t("Sent message to %user_name", array("user_name" => $user->display_name()))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string)$form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } } |