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/user | |
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/user')
-rw-r--r-- | modules/user/controllers/admin_users.php | 28 | ||||
-rw-r--r-- | modules/user/controllers/password.php | 4 | ||||
-rw-r--r-- | modules/user/controllers/users.php | 14 |
3 files changed, 23 insertions, 23 deletions
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php index 64365f2b..b8487e01 100644 --- a/modules/user/controllers/admin_users.php +++ b/modules/user/controllers/admin_users.php @@ -56,12 +56,12 @@ class Admin_Users_Controller extends Admin_Controller { message::success(t("Created user %user_name", array("user_name" => $user->name))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + print json::reply(array("result" => "error", "html" => (string)$form)); } } public function add_user_form() { - json::reply(array("form" => (string) $this->_get_user_add_form_admin())); + print $this->_get_user_add_form_admin(); } public function delete_user($id) { @@ -81,7 +81,7 @@ class Admin_Users_Controller extends Admin_Controller { $name = $user->name; $user->delete(); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } $message = t("Deleted user %user_name", array("user_name" => $name)); @@ -95,7 +95,7 @@ class Admin_Users_Controller extends Admin_Controller { if (empty($user)) { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_user_delete_form_admin($user))); + print $this->_get_user_delete_form_admin($user); } public function edit_user($id) { @@ -136,7 +136,7 @@ class Admin_Users_Controller extends Admin_Controller { message::success(t("Changed user %user_name", array("user_name" => $user->name))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } } @@ -146,7 +146,7 @@ class Admin_Users_Controller extends Admin_Controller { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_user_edit_form_admin($user))); + print $this->_get_user_edit_form_admin($user); } public function add_user_to_group($user_id, $group_id) { @@ -194,12 +194,12 @@ class Admin_Users_Controller extends Admin_Controller { t("Created group %group_name", array("group_name" => $group->name))); json::reply(array("result" => "success")); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } public function add_group_form() { - json::reply(array("form" => (string) $this->_get_group_add_form_admin())); + print $this->_get_group_add_form_admin(); } public function delete_group($id) { @@ -215,7 +215,7 @@ class Admin_Users_Controller extends Admin_Controller { $name = $group->name; $group->delete(); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } $message = t("Deleted group %group_name", array("group_name" => $name)); @@ -230,7 +230,7 @@ class Admin_Users_Controller extends Admin_Controller { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_group_delete_form_admin($group))); + print $this->_get_group_delete_form_admin($group); } public function edit_group($id) { @@ -263,7 +263,7 @@ class Admin_Users_Controller extends Admin_Controller { $group->reload(); message::error( t("Failed to change group %group_name", array("group_name" => $group->name))); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string) $form)); } } @@ -273,7 +273,7 @@ class Admin_Users_Controller extends Admin_Controller { throw new Kohana_404_Exception(); } - json::reply(array("form" => (string) $this->_get_group_edit_form_admin($group))); + print $this->_get_group_edit_form_admin($group); } /* User Form Definitions */ @@ -309,7 +309,7 @@ class Admin_Users_Controller extends Admin_Controller { } module::event("user_edit_form_admin", $user, $form); - $group->submit("")->value(t("Modify User")); + $group->submit("")->value(t("Modify user")); return $form; } @@ -354,7 +354,7 @@ class Admin_Users_Controller extends Admin_Controller { $locales = array_merge(array("" => t("« none »")), $locales); $selected_locale = ($user && $user->locale) ? $user->locale : ""; $form->dropdown("locale") - ->label(t("Language Preference")) + ->label(t("Language preference")) ->options($locales) ->selected($selected_locale); } diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index 4058ef50..575720a8 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -27,10 +27,10 @@ class Password_Controller extends Controller { if ($form->validate()) { $this->_send_reset($form); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } else { - json::reply(array("form" => (string) $form)); + print $form; } } diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index e98ab341..d13cccb2 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -57,7 +57,7 @@ class Users_Controller extends Controller { json::reply(array("result" => "success", "resource" => url::site("users/{$user->id}"))); } else { - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -92,7 +92,7 @@ class Users_Controller extends Controller { log::warning("user", t("Failed password change for %name", array("name" => $user->name))); $name = $user->name; module::event("user_auth_failed", $name); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -126,7 +126,7 @@ class Users_Controller extends Controller { log::warning("user", t("Failed email change for %name", array("name" => $user->name))); $name = $user->name; module::event("user_auth_failed", $name); - json::reply(array("result" => "error", "form" => (string) $form)); + json::reply(array("result" => "error", "html" => (string)$form)); } } @@ -136,7 +136,7 @@ class Users_Controller extends Controller { access::forbidden(); } - json::reply(array("form" => (string) $this->_get_edit_form($user))); + print $this->_get_edit_form($user); } public function form_change_password($id) { @@ -145,7 +145,7 @@ class Users_Controller extends Controller { access::forbidden(); } - json::reply(array("form" => (string) $this->_get_change_password_form($user))); + print $this->_get_change_password_form($user); } public function form_change_email($id) { @@ -154,7 +154,7 @@ class Users_Controller extends Controller { access::forbidden(); } - json::reply(array("form" => (string) $this->_get_change_email_form($user))); + print $this->_get_change_email_form($user); } private function _get_change_password_form($user) { @@ -231,7 +231,7 @@ class Users_Controller extends Controller { $locales = array_merge(array("" => t("« none »")), $locales); $selected_locale = ($user && $user->locale) ? $user->locale : ""; $form->dropdown("locale") - ->label(t("Language Preference")) + ->label(t("Language preference")) ->options($locales) ->selected($selected_locale); } |