Interesting. We can take this two ways:
- Use javascript to update the notes immediately or as close to
  immediately as possible.
- Ignore the selection boxes unless told to take them into account, for
  updating the text.

On Sun, Oct 29, 2006 at 08:13:31PM +0000, zothar at freenetproject.org wrote:
> Author: zothar
> Date: 2006-10-29 20:13:29 +0000 (Sun, 29 Oct 2006)
> New Revision: 10740
> 
> Modified:
>    trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
>    trunk/freenet/src/freenet/support/HTMLNode.java
> Log:
> Probably ugly hack \(Feel free to fix up to guru standards\) to make private 
> peer notes more user-friendly.  Rename the submit button on the /darknet/ 
> peers form so that the submit() method will work on the form.  More 
> human-readable HTML generation tweaking.
> 
> Modified: 
> trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
> ===================================================================
> --- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java     
> 2006-10-29 18:01:55 UTC (rev 10739)
> +++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java     
> 2006-10-29 20:13:29 UTC (rev 10740)
> @@ -302,6 +302,35 @@
>                       // END OVERVIEW TABLE
>  
>                       // BEGIN PEER TABLE
> +                     StringBuffer jsBuf = new StringBuffer();
> +                     // FIXME: There's probably some icky Javascript in here 
> (this is the first thing that worked for me); feel free to fix up to 
> Javascript guru standards
> +                     jsBuf.append( "  function peerNoteChange() {\n" );
> +                     jsBuf.append( "    var theobj = 
> document.getElementById( \"action\" );\n" );
> +                     jsBuf.append( "    var length = 
> theobj.options.length;\n" );
> +                     jsBuf.append( "    for (var i = 0; i < length; i++) 
> {\n" );
> +                     jsBuf.append( "      if(theobj.options[i] == 
> \"update_notes\") {\n" );
> +                     jsBuf.append( "        theobj.options[i].select = 
> true;\n" );
> +                     jsBuf.append( "      } else {\n" );
> +                     jsBuf.append( "        theobj.options[i].select = 
> false;\n" );
> +                     jsBuf.append( "      }\n" );
> +                     jsBuf.append( "    }\n" );
> +                     jsBuf.append( "    theobj.value=\"update_notes\";\n" );
> +                     //jsBuf.append( "    document.getElementById( 
> \"peersForm\" ).submit();\n" );
> +                     jsBuf.append( "    document.getElementById( 
> \"peersForm\" ).doAction.click();\n" );
> +                     jsBuf.append( "  }\n" );
> +                     jsBuf.append( "  function peerNoteBlur() {\n" );
> +                     jsBuf.append( "    var theobj = 
> document.getElementById( \"action\" );\n" );
> +                     jsBuf.append( "    var length = 
> theobj.options.length;\n" );
> +                     jsBuf.append( "    for (var i = 0; i < length; i++) 
> {\n" );
> +                     jsBuf.append( "      if(theobj.options[i] == 
> \"update_notes\") {\n" );
> +                     jsBuf.append( "        theobj.options[i].select = 
> true;\n" );
> +                     jsBuf.append( "      } else {\n" );
> +                     jsBuf.append( "        theobj.options[i].select = 
> false;\n" );
> +                     jsBuf.append( "      }\n" );
> +                     jsBuf.append( "    }\n" );
> +                     jsBuf.append( "    theobj.value=\"update_notes\";\n" );
> +                     jsBuf.append( "  }\n" );
> +                     contentNode.addChild("script", "type", 
> "text/javascript").addChild("%", jsBuf.toString());
>                       HTMLNode peerTableInfobox = contentNode.addChild("div", 
> "class", "infobox infobox-normal");
>                       HTMLNode peerTableInfoboxHeader = 
> peerTableInfobox.addChild("div", "class", "infobox-header");
>                       peerTableInfoboxHeader.addChild("#", "My peers");
> @@ -318,7 +347,7 @@
>                               peerTableInfoboxContent.addChild("a", "href", 
> "/", "node homepage");
>                               peerTableInfoboxContent.addChild("#", " and 
> read the top infobox to see how it is done.");
>                       } else {
> -                             HTMLNode peerForm = 
> peerTableInfoboxContent.addChild("form", new String[] { "action", "method", 
> "enctype" }, new String[] { ".", "post", "multipart/form-data" });
> +                             HTMLNode peerForm = 
> peerTableInfoboxContent.addChild("form", new String[] { "action", "method", 
> "enctype", "id", "name" }, new String[] { ".", "post", "multipart/form-data", 
> "peersForm", "peersForm" });
>                               peerForm.addChild("input", new String[] { 
> "type", "name", "value" }, new String[] { "hidden", "formPassword", 
> core.formPassword });
>                               HTMLNode peerTable = peerForm.addChild("table", 
> "class", "darknet_connections");
>                               HTMLNode peerTableHeaderRow = 
> peerTable.addChild("tr");
> @@ -412,7 +441,7 @@
>                                       }
>  
>                                       // private darknet node comment note 
> column
> -                                     peerRow.addChild("td", "class", 
> "peer-private-darknet-comment-note").addChild("input", new String[] { "type", 
> "name", "size", "maxlength", "value" }, new String[] { "text", 
> "peerPrivateNote_" + peerNodeStatus.hashCode(), "16", "250", 
> peerNodeStatus.getPrivateDarknetCommentNote() });
> +                                     peerRow.addChild("td", "class", 
> "peer-private-darknet-comment-note").addChild("input", new String[] { "type", 
> "name", "size", "maxlength", "onBlur", "onChange", "value" }, new String[] { 
> "text", "peerPrivateNote_" + peerNodeStatus.hashCode(), "16", "250", 
> "peerNoteBlur();", "peerNoteChange();", 
> peerNodeStatus.getPrivateDarknetCommentNote() });
>  
>                                       if(advancedEnabled) {
>                                               // percent of time connected 
> column
> @@ -467,7 +496,7 @@
>                                       }
>                               }
>  
> -                             HTMLNode actionSelect = 
> peerForm.addChild("select", "name", "action");
> +                             HTMLNode actionSelect = 
> peerForm.addChild("select", new String[] { "id", "name" }, new String[] { 
> "action", "action" });
>                               actionSelect.addChild("option", "value", "", 
> "-- Select action --");
>                               actionSelect.addChild("option", "value", 
> "send_n2ntm", "Send N2NTM to selected peers");
>                               actionSelect.addChild("option", "value", 
> "update_notes", "Update changed private notes");
> @@ -483,7 +512,7 @@
>                               }
>                               actionSelect.addChild("option", "value", "", 
> "-- -- --");
>                               actionSelect.addChild("option", "value", 
> "remove", "Remove selected peers");
> -                             peerForm.addChild("input", new String[] { 
> "type", "name", "value" }, new String[] { "submit", "submit", "Go" });
> +                             peerForm.addChild("input", new String[] { 
> "type", "name", "value" }, new String[] { "submit", "doAction", "Go" });
>                       }
>                       // END PEER TABLE
>  
> @@ -623,7 +652,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("send_n2ntm")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("send_n2ntm")) {
>                       HTMLNode pageNode = 
> ctx.getPageMaker().getPageNode("Send Node to Node Text Message");
>                       HTMLNode contentNode = 
> ctx.getPageMaker().getContentNode(pageNode);
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -647,7 +676,7 @@
>                       pageNode.generate(pageBuffer);
>                       this.writeReply(ctx, 200, "text/html", "OK", 
> pageBuffer.toString());
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("update_notes")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("update_notes")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -662,7 +691,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("enable")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("enable")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -675,7 +704,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("disable")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("disable")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -688,7 +717,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("set_burst_only")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("set_burst_only")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -701,7 +730,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("clear_burst_only")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("clear_burst_only")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -714,7 +743,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("set_listen_only")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("set_listen_only")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -727,7 +756,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("clear_listen_only")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("clear_listen_only")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -740,7 +769,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("set_allow_local")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("set_allow_local")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -753,7 +782,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("clear_allow_local")) {
> +             } else if (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("clear_allow_local")) {
>                       //int hashcode = 
> Integer.decode(request.getParam("node")).intValue();
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> @@ -766,7 +795,7 @@
>                       headers.put("Location", "/darknet/");
>                       ctx.sendReplyHeaders(302, "Found", headers, null, 0);
>                       return;
> -             } else if (request.isPartSet("remove") || 
> (request.isPartSet("submit") && 
> request.getPartAsString("action",25).equals("remove"))) {                     
> +             } else if (request.isPartSet("remove") || 
> (request.isPartSet("doAction") && 
> request.getPartAsString("action",25).equals("remove"))) {                   
>                       if(logMINOR) Logger.minor(this, "Remove node");
>                       
>                       PeerNode[] peerNodes = node.getDarknetConnections();
> 
> Modified: trunk/freenet/src/freenet/support/HTMLNode.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/HTMLNode.java   2006-10-29 18:01:55 UTC 
> (rev 10739)
> +++ trunk/freenet/src/freenet/support/HTMLNode.java   2006-10-29 20:13:29 UTC 
> (rev 10740)
> @@ -49,7 +49,7 @@
>                       }
>               }
>               if (content != null) {
> -                     if (!name.equals("#")) {
> +                     if (!name.equals("#") && !name.equals("%")) {
>                               addChild(new HTMLNode("#", content));
>                               this.content = null;
>                       } else {
> @@ -136,6 +136,12 @@
>                       tagBuffer.append(HTMLEncoder.encode(content));
>                       return tagBuffer;
>               }
> +             // Perhaps this should be something else, but since I don't 
> know if '#' was not just arbitrary chosen, I'll just pick '%'
> +             // This allows non-encoded text to be appended to the tag buffer
> +             if (name.equals("%")) {
> +                     tagBuffer.append(content);
> +                     return tagBuffer;
> +             }
>               tagBuffer.append("<").append(name);
>               Set attributeSet = attributes.entrySet();
>               for (Iterator attributeIterator = attributeSet.iterator(); 
> attributeIterator.hasNext();) {
> @@ -152,7 +158,7 @@
>                       }
>               } else {
>                       tagBuffer.append(">");
> -                     if(name.equals("div") || name.equals("table") || 
> name.equals("tr") || name.equals("td")) {
> +                     if(name.equals("div") || name.equals("form") || 
> name.equals("input") || name.equals("script") || name.equals("table") || 
> name.equals("tr") || name.equals("td")) {
>                               tagBuffer.append("\n");
>                       }
>                       for (int childIndex = 0, childCount = children.size(); 
> childIndex < childCount; childIndex++) {
> @@ -160,7 +166,7 @@
>                               childNode.generate(tagBuffer);
>                       }
>                       tagBuffer.append("</").append(name).append(">");
> -                     if(name.equals("div") || name.equals("li") || 
> name.equals("table") || name.equals("tr") || name.equals("td")) {
> +                     if(name.equals("div") || name.equals("form") || 
> name.equals("input") || name.equals("li") || name.equals("option") || 
> name.equals("script") || name.equals("table") || name.equals("tr") || 
> name.equals("td")) {
>                               tagBuffer.append("\n");
>                       }
>               }
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20061031/1595ba18/attachment.pgp>

Reply via email to