Changeset 141ad67


Ignore:
Timestamp:
Feb 23, 2012 5:41:06 PM (8 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
87da4b7
Parents:
a288fc5
Message:

ajaxify the refresh

Location:
apps/i2psnark
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/build.xml

    ra288fc5 r141ad67  
    9999            <fileset dir="../icons/" />
    100100        </copy>
     101        <copy todir="build/js/.js" >
     102            <fileset dir="../js/" />
     103        </copy>
    101104        <war destfile="../i2psnark.war" webxml="../web.xml" >
    102105          <!-- include only the web stuff, as of 0.7.12 the router will add i2psnark.jar to the classpath for the war -->
    103106          <classes dir="./build/obj" includes="**/web/*.class" />
    104107            <fileset dir="build/icons/" />
     108            <fileset dir="build/js/" />
    105109            <manifest>
    106110                <attribute name="Implementation-Version" value="${full.version}" />
     
    114118    <target name="warUpToDate">
    115119        <uptodate property="war.uptodate" targetfile="../i2psnark.war" >
    116             <srcfiles dir= "." includes="build/obj/org/klomp/snark/web/*.class ../icons/* ../web.xml" />
     120            <srcfiles dir= "." includes="build/obj/org/klomp/snark/web/*.class ../icons/* ../js/* ../web.xml" />
    117121        </uptodate>
    118122    </target>
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    ra288fc5 r141ad67  
    103103    {
    104104        if (pathInContext == null || pathInContext.equals("/") || pathInContext.equals("/index.jsp") ||
    105             pathInContext.equals("/index.html") || pathInContext.startsWith("/.icons/"))
     105            pathInContext.equals("/index.html") || pathInContext.startsWith("/.icons/") ||
     106            pathInContext.startsWith("/.js/") || pathInContext.startsWith("/.ajax/"))
    106107            return super.getResource(pathInContext);
    107108        // files in the i2psnark/ directory
     
    152153        // this is the part after /i2psnark
    153154        String path = req.getServletPath();
     155
     156        // AJAX for mainsection
     157        if ("/.ajax/xhr1.html".equals(path)) {
     158            resp.setCharacterEncoding("UTF-8");
     159            resp.setContentType("text/html; charset=UTF-8");
     160            PrintWriter out = resp.getWriter();
     161            writeMessages(out);
     162            writeTorrents(out, req);
     163            return;
     164        }
     165
    154166        boolean isConfigure = "/configure".equals(path);
    155167        // index.jsp doesn't work, it is grabbed by the war handler before here
     
    209221                                         
    210222        // we want it to go to the base URI so we don't refresh with some funky action= value
     223        int delay = 0;
    211224        if (!isConfigure) {
    212             int delay = _manager.getRefreshDelaySeconds();
     225            delay = _manager.getRefreshDelaySeconds();
    213226            if (delay > 0)
    214                 out.write("<meta http-equiv=\"refresh\" content=\"" + delay + ";/i2psnark/" + peerString + "\">\n");
    215         }
    216         out.write(HEADER_A + _themePath + HEADER_B);
    217         out.write("</head><body>");
     227                //out.write("<meta http-equiv=\"refresh\" content=\"" + delay + ";/i2psnark/" + peerString + "\">\n");
     228                out.write("<script src=\"/i2psnark/.js/i2psnark.js\" type=\"text/javascript\"></script>\n");
     229        }
     230        out.write(HEADER_A + _themePath + HEADER_B + "</head>\n");
     231        if (isConfigure || delay <= 0)
     232            out.write("<body>");
     233        else
     234            out.write("<body onload=\"initAjax(" + (delay * 1000) + ")\">");
    218235        out.write("<center>");
    219236        if (isConfigure) {
     
    250267        if (newURL != null && newURL.trim().length() > 0 && req.getMethod().equals("GET"))
    251268            _manager.addMessage(_("Click \"Add torrent\" button to fetch torrent"));
    252         out.write("<div class=\"page\"><div class=\"mainsection\"><div class=\"snarkMessages\"><table><tr><td align=\"left\"><pre>");
    253         List msgs = _manager.getMessages();
    254         for (int i = msgs.size()-1; i >= 0; i--) {
    255             String msg = (String)msgs.get(i);
    256             out.write(msg + "\n");
    257         }
    258         out.write("</pre></td></tr></table></div>");
     269        out.write("<div class=\"page\"><div id=\"mainsection\" class=\"mainsection\">");
     270
     271        writeMessages(out);
    259272
    260273        if (isConfigure) {
     274            // end of mainsection div
    261275            out.write("<div class=\"logshim\"></div></div>\n");
    262276            writeConfigForm(out, req);
     
    264278        } else {
    265279            writeTorrents(out, req);
    266             out.write("</div>\n");
     280            // end of mainsection div
     281            out.write("</div><div id=\"lowersection\">\n");
    267282            writeAddForm(out, req);
    268283            writeSeedForm(out, req);
    269284            writeConfigLink(out);
     285            // end of lowersection div
     286            out.write("</div>\n");
    270287        }
    271288        out.write(FOOTER);
     289    }
     290
     291    private void writeMessages(PrintWriter out) throws IOException {
     292        out.write("<div class=\"snarkMessages\"><table><tr><td align=\"left\"><pre>");
     293        List msgs = _manager.getMessages();
     294        for (int i = msgs.size()-1; i >= 0; i--) {
     295            String msg = (String)msgs.get(i);
     296            out.write(msg + "\n");
     297        }
     298        out.write("</pre></td></tr></table></div>");
    272299    }
    273300
     
    13571384    }
    13581385   
    1359     private static final int[] times = { 30, 60, 2*60, 5*60, 10*60, 30*60, -1 };
     1386    private static final int[] times = { 5, 15, 30, 60, 2*60, 5*60, 10*60, 30*60, -1 };
    13601387
    13611388    private void writeConfigForm(PrintWriter out, HttpServletRequest req) throws IOException {
Note: See TracChangeset for help on using the changeset viewer.