Implement moving the profile fields with Javascript.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 15 Jan 2011 14:39:16 +0000 (15:39 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 15 Jan 2011 14:39:16 +0000 (15:39 +0100)
src/main/resources/templates/editProfile.html

index 12cbd74..8a1b7d7 100644 (file)
@@ -1,6 +1,13 @@
 <%include include/head.html>
 
        <script language="javascript">
+               function recheckMoveButtons() {
+                       $("#sone .profile-field").each(function() {
+                               $(".move-up-field", this).toggleClass("hidden", $(this).prev(".profile-field").length == 0);
+                               $(".move-down-field", this).toggleClass("hidden", $(this).next(".profile-field").length == 0);
+                       });
+               }
+
                $(function() {
                        getTranslation("WebInterface.DefaultText.FirstName", function(firstNameDefaultText) {
                                registerInputTextareaSwap("#sone #edit-profile input[name=first-name]", firstNameDefaultText, "first-name", true, true);
@@ -55,6 +62,7 @@
                                                        buttonName = confirmButton.attr("name");
                                                        fieldId = buttonName.substring("delete-field-".length);
                                                        deleteProfileField(fieldId);
+                                                       recheckMoveButtons();
                                                        return false;
                                                });
                                        })($(this), confirmButton);
                                        });
                                })($(this), inputField, confirmButton, cancelButton, fieldNameElement);
                        });
+
+                       /* ajaxify “move up” and “move down” buttons. */
+                       $("#sone .profile-field .move-down-field button").click(function() {
+                               profileField = $(this).parents(".profile-field");
+                               moveProfileFieldDown(profileField.attr("id"), function() {
+                                       next = profileField.next();
+                                       current = profileField.insertAfter(next);
+                                       recheckMoveButtons();
+                               });
+                               return false;
+                       });
+                       $("#sone .profile-field .move-up-field button").click(function() {
+                               profileField = $(this).parents(".profile-field");
+                               moveProfileFieldUp(profileField.attr("id"), function() {
+                                       previous = profileField.prev();
+                                       current = profileField.insertBefore(previous);
+                                       recheckMoveButtons();
+                               });
+                               return false;
+                       });
                });
        </script>