Move user update javascript out of template file
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Aug 2010 20:07:48 +0000 (14:07 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Aug 2010 20:07:59 +0000 (14:07 -0600)
horde/admin/user.php
horde/js/userupdate.js [new file with mode: 0644]
horde/templates/admin/user/update.inc

index eb9bd5b..d85db6e 100644 (file)
@@ -210,8 +210,15 @@ case 'removequeued':
     break;
 }
 
-$title = _("User Administration");
 Horde::addScriptFile('stripe.js', 'horde');
+if (isset($update_form) && $auth->hasCapability('list')) {
+    Horde::addScriptFile('userupdate.js', 'horde');
+    Horde::addInlineScript(array(
+        'HordeAdminUserUpdate.pass_error = ' . Horde_Serialize::serialize(_("Passwords must match."), Horde_Serialize::JSON, $registry->getCharset())
+    ));
+}
+
+$title = _("User Administration");
 require HORDE_TEMPLATES . '/common-header.inc';
 require HORDE_TEMPLATES . '/admin/menu.inc';
 
diff --git a/horde/js/userupdate.js b/horde/js/userupdate.js
new file mode 100644 (file)
index 0000000..7987fc0
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * Provides the javascript for the admin user update page.
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ */
+
+var HordeAdminUserUpdate = {
+
+    // Set in admin/user.php: pass_error
+
+    onSubmit: function(e)
+    {
+        if ($('user_pass_1') &&
+            $F('user_pass_1') != $F('user_pass_2')) {
+            $('user_pass_1', 'user_pass_2').invoke('setValue', '');
+            window.alert(this.pass_error);
+            e.stop();
+        }
+    },
+
+    onDomLoad: function()
+    {
+        $('updateuser').observe('submit', this.onSubmit.bindAsEventListener(this));
+    }
+
+};
+
+document.observe('dom:loaded', HordeAdminUserUpdate.onDomLoad.bind(HordeAdminUserUpdate));
index c60bdcd..7a45f4a 100644 (file)
@@ -1,28 +1,4 @@
-<script type="text/javascript">
-<!--
-
-function validate_update()
-{
-    if (document.updateuser.user_name.value == "") {
-        document.updateuser.user_name.focus();
-        alert('<?php echo addslashes(_("You must specify the username to add.")) ?>');
-        return false;
-    } else if (document.updateuser.user_pass_1 &&
-               document.updateuser.user_pass_1.value != document.updateuser.user_pass_2.value) {
-        document.updateuser.user_pass_1.value = "";
-        document.updateuser.user_pass_2.value = "";
-        document.updateuser.user_pass_1.focus();
-        alert('<?php echo addslashes(_("Passwords must match.")) ?>');
-        return false;
-    }
-
-    return true;
-}
-
-//-->
-</script>
-
-<form name="updateuser" method="post" action="user.php">
+<form id="updateuser" name="updateuser" method="post" action="user.php">
 <?php Horde_Util::pformInput() ?>
 <input type="hidden" name="form" value="update" />
 <input type="hidden" name="user_name" value="<?php echo htmlspecialchars($f_user_name) ?>" />
@@ -74,7 +50,7 @@ function validate_update()
  </tr>
  <tr>
   <td class="control leftAlign" colspan="2">
-   <input type="submit" class="button" name="submit" onclick="return validate_update();" value="<?php echo _("Update user") ?>" />
+   <input type="submit" class="button" name="submit" value="<?php echo _("Update user") ?>" />
    <input type="reset" class="button" name="reset" value="<?php echo _("Reset") ?>" />
   </td>
  </tr>