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/watermark/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/watermark/controllers')
-rw-r--r-- | modules/watermark/controllers/admin_watermarks.php | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/modules/watermark/controllers/admin_watermarks.php b/modules/watermark/controllers/admin_watermarks.php index 922b050b..0652b13c 100644 --- a/modules/watermark/controllers/admin_watermarks.php +++ b/modules/watermark/controllers/admin_watermarks.php @@ -35,7 +35,7 @@ class Admin_Watermarks_Controller extends Admin_Controller { } public function form_edit() { - json::reply(array("form" => (string) watermark::get_edit_form())); + print watermark::get_edit_form(); } public function edit() { @@ -53,12 +53,12 @@ class Admin_Watermarks_Controller extends Admin_Controller { array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } public function form_delete() { - json::reply(array("form" => (string) watermark::get_delete_form())); + print watermark::get_delete_form(); } public function delete() { @@ -81,12 +81,12 @@ class Admin_Watermarks_Controller extends Admin_Controller { } json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } public function form_add() { - json::reply(array("form" => (string) watermark::get_add_form())); + print watermark::get_add_form(); } public function add() { @@ -120,7 +120,10 @@ class Admin_Watermarks_Controller extends Admin_Controller { log::success("watermark", t("Watermark saved")); json::reply(array("result" => "success", "location" => url::site("admin/watermarks"))); } else { - json::reply(array("result" => "error", "form" => rawurlencode((string) $form))); + // rawurlencode the results because the JS code that uploads the file buffers it in an + // iframe which entitizes the HTML and makes it difficult for the JS to process. If we url + // encode it now, it passes through cleanly. See ticket #797. + json::reply(array("result" => "error", "html" => rawurlencode((string)$form))); } } |