Add default texts for input fields with AJAX.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 21 Oct 2010 10:24:26 +0000 (12:24 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 21 Oct 2010 10:24:26 +0000 (12:24 +0200)
src/main/resources/i18n/sone.en.properties
src/main/resources/static/javascript/sone.js
src/main/resources/templates/include/createSone.html
src/main/resources/templates/include/head.html
src/main/resources/templates/index.html
src/main/resources/templates/knownSones.html

index 9d819a7..bdb95f4 100644 (file)
@@ -158,3 +158,11 @@ View.Sone.Status.Inserting=This Sone is currently being inserted.
 View.Post.DeleteLink=Delete
 View.Post.SendReply=Post Reply!
 View.Post.Reply.DeleteLink=Delete
+
+WebInterface.DefaultText.StatusUpdate=What’s on your mind?
+WebInterface.DefaultText.CreateSoneName=The name of your Sone
+WebInterface.DefaultText.CreateSoneDocumentName=The document name of your Sone (e.g. the “foo” in USK@…/foo/0)
+WebInterface.DefaultText.CreateSoneInsertURI=The Insert Key of your Sone
+WebInterface.DefaultText.CreateSoneRequestURI=The Request Key of your Sone
+WebInterface.DefaultText.Reply=Write a Reply…
+WebInterface.DefaultText.SoneRequestURI=Sone Request Key
index 200c870..5d75952 100644 (file)
@@ -1,6 +1,6 @@
 /* Sone JavaScript functions. */
 
-function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName) {
+function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName, optional) {
        $(inputSelector).each(function() {
                textarea = $("<textarea name=\"" + inputFieldName + "\"></textarea>").blur(function() {
                        if ($(this).val() == "") {
@@ -13,9 +13,14 @@ function registerInputTextareaSwap(inputSelector, defaultText, inputFieldName) {
                        $(inputField).focus(function() {
                                $(this).hide().attr("disabled", "disabled");
                                textarea.show().focus();
-                       }).addClass("default").val(defaultText);
+                       }).addClass("default");
+                       (function(inputField) {
+                               $.getJSON("ajax/getTranslation.ajax", {"key": defaultText}, function(data, textStatus) {
+                                       $(inputField).val(data.value);
+                               });
+                       })(inputField);
                        $(inputField.form).submit(function() {
-                               if (textarea.val() == "") {
+                               if (!optional && (textarea.val() == "")) {
                                        return false;
                                }
                        });
index 9666b27..f2777c3 100644 (file)
@@ -1,9 +1,9 @@
 <script language="javascript">
        $(document).ready(function() {
-               registerInputTextareaSwap("#sone #create-sone input[name=name]", "The name of your Sone", "name");
-               registerInputTextareaSwap("#sone #create-sone input[name=document-name]", "The document name of your Sone", "document-name");
-               registerInputTextareaSwap("#sone #create-sone input[name=insert-uri]", "The insert URI of your Sone", "insert-uri");
-               registerInputTextareaSwap("#sone #create-sone input[name=request-uri]", "The request URI of your Sone", "request-uri");
+               registerInputTextareaSwap("#sone #create-sone input[name=name]", "WebInterface.DefaultText.CreateSoneName", "name", false);
+               registerInputTextareaSwap("#sone #create-sone input[name=document-name]", "WebInterface.DefaultText.CreateSoneDocumentName", "document-name", false);
+               registerInputTextareaSwap("#sone #create-sone input[name=insert-uri]", "WebInterface.DefaultText.CreateSoneInsertURI", "insert-uri", true);
+               registerInputTextareaSwap("#sone #create-sone input[name=request-uri]", "WebInterface.DefaultText.CreateSoneRequestURI", "request-uri", true);
 
                /* hide all the labels. */
                $("#sone #create-sone label").hide();
index 6cd2cbc..6909bb4 100644 (file)
@@ -5,7 +5,7 @@
 
        <script language="javascript">
                $(document).ready(function() {
-                       registerInputTextareaSwap("#sone #update-status .status-input", "What are you doing?", "text");
+                       registerInputTextareaSwap("#sone #update-status .status-input", "WebInterface.DefaultText.StatusUpdate", "text", false);
                });
        </script>
 
index 5dcda5a..8f18974 100644 (file)
@@ -3,7 +3,7 @@
        <script language="javascript">
                /* register input field/textarea swap. */
                $(document).ready(function() {
-                       registerInputTextareaSwap("#sone input.reply-input", "Write a Reply…", "text");
+                       registerInputTextareaSwap("#sone input.reply-input", "WebInterface.DefaultText.Reply", "text", false);
                        addCommentLinks();
                });
        </script>
index 3f55a58..862c01e 100644 (file)
@@ -2,7 +2,7 @@
 
        <script language="javascript">
                $(document).ready(function() {
-                       registerInputTextareaSwap("#add-sone input[name=request-uri]", "Sone Request Key", "request-uri");
+                       registerInputTextareaSwap("#add-sone input[name=request-uri]", "WebInterface.DefaultText.SoneRequestURI", "request-uri", false);
                })
        </script>