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/tag/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/tag/controllers')
-rw-r--r-- | modules/tag/controllers/admin_tags.php | 8 | ||||
-rw-r--r-- | modules/tag/controllers/tags.php | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php index 32c54945..0c82579b 100644 --- a/modules/tag/controllers/admin_tags.php +++ b/modules/tag/controllers/admin_tags.php @@ -37,7 +37,7 @@ class Admin_Tags_Controller extends Admin_Controller { public function form_delete($id) { $tag = ORM::factory("tag", $id); if ($tag->loaded()) { - json::reply(array("form" => (string) tag::get_delete_form($tag))); + print tag::get_delete_form($tag); } } @@ -59,7 +59,7 @@ class Admin_Tags_Controller extends Admin_Controller { json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + print $form; } } @@ -91,14 +91,14 @@ class Admin_Tags_Controller extends Admin_Controller { $tag->name = $in_place_edit->value(); $tag->save(); - $message = t("Renamed tag %old_name to %new_name", + $message = t("Renamed tag <b>%old_name</b> to <b>%new_name</b>", array("old_name" => $old_name, "new_name" => $tag->name)); message::success($message); log::success("tags", $message); json::reply(array("result" => "success", "location" => url::site("admin/tags"))); } else { - json::reply(array("result" => "error", "form" => $in_place_edit->render())); + json::reply(array("result" => "error", "form" => (string)$in_place_edit->render())); } } diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 7fa8534c..bc657644 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -69,7 +69,7 @@ class Tags_Controller extends Controller { json::reply(array("result" => "success", "cloud" => (string)tag::cloud(30))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } |