Ajaxify the profile field delete button.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 14 Jan 2011 21:14:50 +0000 (22:14 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 14 Jan 2011 21:14:50 +0000 (22:14 +0100)
src/main/resources/i18n/sone.en.properties
src/main/resources/templates/editProfile.html

index 86270b8..ccedff0 100644 (file)
@@ -76,6 +76,7 @@ Page.EditProfile.Fields.Button.Edit=edit
 Page.EditProfile.Fields.Button.MoveUp=move up
 Page.EditProfile.Fields.Button.MoveDown=move down
 Page.EditProfile.Fields.Button.Delete=delete
+Page.EditProfile.Fields.Button.ReallyDelete=really delete
 Page.EditProfile.Fields.AddField.Title=Add Field
 Page.EditProfile.Fields.AddField.Label.Name=Name:
 Page.EditProfile.Fields.AddField.Button.AddField=Add Field
index 189488e..2ad1faa 100644 (file)
 
                        /* hide all the labels. */
                        $("#sone #edit-profile label, #sone #add-profile-field label").hide();
+
+                       getTranslation("Page.EditProfile.Fields.Button.ReallyDelete", function(reallyDeleteText) {
+                               $("#sone #edit-profile .delete-field-name button").each(function() {
+                                       confirmButton = $(this).clone().addClass("hidden").addClass("confirm").text(reallyDeleteText).insertAfter(this);
+                                       (function(deleteButton, confirmButton) {
+                                               deleteButton.click(function() {
+                                                       deleteButton.fadeOut("slow", function() {
+                                                               confirmButton.fadeIn("slow");
+                                                               $(document).one("click", function() {
+                                                                       if (this != confirmButton.get(0)) {
+                                                                               confirmButton.fadeOut("slow", function() {
+                                                                                       deleteButton.fadeIn("slow");
+                                                                               });
+                                                                       }
+                                                                       return false;
+                                                               });
+                                                       });
+                                                       return false;
+                                               });
+                                               confirmButton.click(function() {
+                                                       confirmButton.fadeOut("slow");
+                                                       buttonName = confirmButton.attr("name");
+                                                       fieldId = buttonName.substring("delete-field-".length);
+                                                       deleteProfileField(fieldId);
+                                                       return false;
+                                               });
+                                       })($(this), confirmButton);
+                               });
+                       });
                });
        </script>