From 52c8d049af6c0963b63dd1e70f66128527a7cba5 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Wed, 7 Nov 2012 16:36:17 +0700 Subject: JS local time auto-expand comments --- src/java/User.properties | 5 + src/java/User_ru.properties | 5 + src/java/com/juick/http/www/PageTemplates.java | 40 ++-- src/java/com/juick/http/www/User.java | 14 +- src/java/com/juick/http/www/UserThread.java | 280 +++++++++++++------------ web/scripts3.js | 6 +- web/style3.css | 33 +-- 7 files changed, 205 insertions(+), 178 deletions(-) diff --git a/src/java/User.properties b/src/java/User.properties index f3b563db..3ed6bfa7 100644 --- a/src/java/User.properties +++ b/src/java/User.properties @@ -17,3 +17,8 @@ View\ as\ list=View as list View\ as\ tree=View as tree all=all Search=Search +(UToolbar)\ Subcribe=Subscribe +(UToolbar)\ Subcribed=Subscribed +(UToolbar)\ Block=Block user +(UToolbar)\ Unblock=Unblock user +(UToolbar)\ Private=Send a private message diff --git a/src/java/User_ru.properties b/src/java/User_ru.properties index fd38d0d5..fab91ceb 100644 --- a/src/java/User_ru.properties +++ b/src/java/User_ru.properties @@ -17,3 +17,8 @@ View\ as\ list=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043f\u04 View\ as\ tree=\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0435\u0440\u0435\u0432\u043e\u043c all=\u0432\u0441\u0435 Search=\u041f\u043e\u0438\u0441\u043a +(UToolbar)\ Subcribe=\u041f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f +(UToolbar)\ Subcribed=\u041f\u043e\u0434\u043f\u0438\u0441\u0430\u043d +(UToolbar)\ Block=\u0417\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f +(UToolbar)\ Unblock=\u0420\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f +(UToolbar)\ Private=\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 41646e30..2ec42e42 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -48,17 +48,18 @@ public class PageTemplates { private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM"); private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy"); + private static SimpleDateFormat sdfJS = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss"); public static void pageHead(PrintWriter out, String title, String headers) { out.println(""); out.println(""); out.println(""); out.println(" " + title + ""); - out.println(" "); + out.println(" "); out.println(" "); out.println(" "); out.println(" "); - out.println(" "); + out.println(" "); if (headers != null) { out.println(headers); } @@ -77,14 +78,12 @@ public class PageTemplates { out.println(" "); out.println(" "); out.println(""); @@ -205,6 +204,19 @@ public class PageTemplates { } } + public static String formatJSLocalTime(String ts) { + try { + Date date = sdfSQL.parse(ts); + return ""; + } catch (ParseException e) { + System.err.print(e); + } + return ""; + } + public static String formatReplies(int replies, Locale loc) { return replies + " repl" + (replies % 10 == 1 ? "y" : "ies"); } @@ -280,10 +292,12 @@ public class PageTemplates { ArrayList msgs = MessagesQueries.getMessages(sql, mids); ArrayList blUIDs = new ArrayList(20); - for (int i = 0; i < mids.size(); i++) { - blUIDs.add(msgs.get(i).User.UID); + if (visitor != null) { + for (int i = 0; i < mids.size(); i++) { + blUIDs.add(msgs.get(i).User.UID); + } + blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs); } - blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs); for (int i = 0; i < msgs.size(); i++) { com.juick.Message msg = msgs.get(i); @@ -306,7 +320,7 @@ public class PageTemplates { out.println("
  • "); out.println("
    \""
    "); - out.println(" "); + out.println(" "); out.println(" "); if (msg.Place != null) { out.println("
    " + msg.Place.name + "
    "); diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index f1896837..de0375f3 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -145,7 +145,7 @@ public class User { try { PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Menu) Tags"), null); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + //PageTemplates.pageUserTitle(out, sql, locale, user, visitor); out.println("
    "); out.println("
    "); @@ -172,7 +172,7 @@ public class User { try { PageTemplates.pageHead(out, "@" + user.UName + ": " + rb.getString("(Stats) I read"), null); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + //PageTemplates.pageUserTitle(out, sql, locale, user, visitor); out.println("
    "); out.println("
    "); @@ -270,17 +270,17 @@ public class User { if (visitor != null && visitor.UID > 0 && visitor.UID != user.UID) { out.println("
      "); if (UserQueries.isSubscribed(sql, visitor.UID, user.UID)) { - out.println("
    • "); + out.println("
    • "); } else { - out.println("
    • "); + out.println("
    • "); } if (UserQueries.isInBL(sql, visitor.UID, user.UID)) { - out.println("
    • "); + out.println("
    • "); } else { - out.println("
    • "); + out.println("
    • "); } if (!UserQueries.isInBL(sql, user.UID, visitor.UID)) { - out.println("
    • "); + out.println("
    • "); } out.println("
    "); } else { diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java index ec3412f3..a0bb3a86 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -22,11 +22,7 @@ import com.juick.server.UserQueries; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Locale; import java.util.ResourceBundle; import javax.servlet.ServletException; @@ -70,14 +66,14 @@ public class UserThread { try { PageTemplates.pageHead(out, title, null); PageTemplates.pageNavigation(out, locale, visitor); - PageTemplates.pageUserTitle(out, sql, locale, user, visitor); + //PageTemplates.pageUserTitle(out, sql, locale, user, visitor); out.println("
    "); out.println("
    "); out.println("
    "); - printMessage(out, sql, MID, visitor, locale); - printReplies(out, sql, MID, visitor, locale, listview); + com.juick.Message msg = printMessage(out, sql, MID, visitor, locale); + printReplies(out, sql, msg, visitor, locale, listview); out.println("
    "); out.println("
    "); @@ -89,154 +85,163 @@ public class UserThread { } } - public static void printMessage(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale) { + public static com.juick.Message printMessage(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale) { ResourceBundle rb = ResourceBundle.getBundle("Global", locale); ResourceBundle rbthread = ResourceBundle.getBundle("UserThread", locale); - PreparedStatement stmt = null; - ResultSet rs = null; - try { - stmt = sql.prepareStatement("SELECT STRAIGHT_JOIN messages.message_id,messages.user_id,users.nick,messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt,TIMESTAMPDIFF(MINUTE,messages.ts,NOW()),messages.ts,messages.replies,messages.attach,messages.place_id,places.name,messages.lat,messages.lon FROM ((messages INNER JOIN messages_txt ON messages.message_id=messages_txt.message_id) INNER JOIN users ON messages.user_id=users.id) LEFT JOIN places ON messages.place_id=places.place_id WHERE messages.message_id=?"); - stmt.setInt(1, mid); - rs = stmt.executeQuery(); - if (rs.first()) { - int uid = rs.getInt(2); - String uname = rs.getString(3); - String tags = rs.getString(4); - String txt = rs.getString(7); - // timediff - // timestamp - // replies - // attach - // pid - // pname - // lat - // lon - - boolean cancomment = visitor != null; - - tags = (tags != null) ? PageTemplates.formatTags(new ArrayList(Arrays.asList(tags.split(" ")))) : ""; - if (rs.getInt(5) == 1) { - tags += " *readonly"; - cancomment = false; - } - switch (rs.getInt(6)) { - case 2: - tags += " *public"; - break; - case -1: - tags += " *friends"; - break; - case -2: - tags += " *private"; - break; - } + com.juick.Message msg = MessagesQueries.getMessage(sql, mid); - txt = PageTemplates.formatMessage(txt); + msg.VisitorCanComment = visitor != null; - out.println("
      "); - out.println("
    • "); - - out.println("
      \""
      "); - out.println(" "); - out.println("
      @" + uname + ":" + tags + "
      "); - if (rs.getString(13) != null) { - out.println("
      " + rs.getString(14) + "
      "); - } - out.println("
      " + txt + "
      "); + String tags = (msg.Tags.isEmpty()) ? "" : PageTemplates.formatTags(msg.Tags); + if (msg.ReadOnly) { + tags += " *readonly"; + msg.VisitorCanComment = false; + } + switch (msg.Privacy) { + case 2: + tags += " *public"; + break; + case -1: + tags += " *friends"; + break; + case -2: + tags += " *private"; + break; + } - if (rs.getString(11) != null) { - if (rs.getString(11).equals("jpg")) { - out.println("
      \"\"/
      "); - } else { - out.println("
      \"\"/
      "); - } - } + out.println("
        "); + out.println("
      • "); + out.println("
        \""
        "); + out.println("
        " + PageTemplates.formatJSLocalTime(msg.TimestampString) + "
        "); + out.println(" "); + if (msg.Place != null && msg.Place.pid > 0) { + out.println("
        " + msg.Place.name + "
        "); + } + out.println("
        " + PageTemplates.formatMessage(msg.Text) + "
        "); - boolean visitorInBL = UserQueries.isInBL(sql, uid, visitor.UID); + if (msg.AttachmentType != null) { + if (msg.AttachmentType.equals("jpg")) { + out.println("
        \"\"/
        "); + } else { + out.println("
        \"\"/
        "); + } + } + boolean visitorInBL = false; + if (visitor != null) { + if (visitor.UID == msg.User.UID) { + msg.VisitorCanComment = true; + } else { + visitorInBL = UserQueries.isInBL(sql, msg.User.UID, visitor.UID); if (visitorInBL) { - cancomment = false; - } - if (visitor != null && visitor.UID == uid) { - cancomment = true; + msg.VisitorCanComment = false; } + } + } - if (cancomment) { - out.println("
        "); - out.println("
        "); - out.println("
        "); - } + if (msg.VisitorCanComment) { + out.println("
        "); + out.println("
        "); + out.println("
        "); + } - ArrayList recomm = MessagesQueries.getMessageRecommendations(sql, mid); - if (!recomm.isEmpty()) { - out.print("
        " + rb.getString("Recommended by") + " (" + recomm.size() + "): "); - for (int i = 0; i < recomm.size(); i++) { - if (i > 0) { - out.print(", "); - } - out.print("@" + recomm.get(i) + ""); - } + ArrayList recomm = MessagesQueries.getMessageRecommendations(sql, mid); + if (!recomm.isEmpty()) { + out.print("
        " + rb.getString("Recommended by") + " (" + recomm.size() + "): "); + for (int i = 0; i < recomm.size(); i++) { + if (i > 0) { + out.print(", "); } + out.print("@" + recomm.get(i) + ""); + } + } - out.println("
      • "); - out.println("
      • "); + } else { + out.println("
      • " + rbthread.getString("(MToolbar) Delete") + "
      • "); } - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(rs, stmt); } + out.println("
    • "); + out.println("
    "); + return msg; } - public static void printReplies(PrintWriter out, Connection sql, int mid, com.juick.User visitor, Locale locale, boolean listview) { + public static void printReplies(PrintWriter out, Connection sql, com.juick.Message msg, com.juick.User visitor, Locale locale, boolean listview) { ResourceBundle rbuser = ResourceBundle.getBundle("User", locale); - ArrayList replies = MessagesQueries.getReplies(sql, mid); + ArrayList replies = MessagesQueries.getReplies(sql, msg.MID); + ArrayList blUIDs = new ArrayList(); for (int i = 0; i < replies.size(); i++) { - com.juick.Message msg = replies.get(i); - if (msg.ReplyTo > 0) { + com.juick.Message reply = replies.get(i); + if (reply.User.UID != msg.User.UID && !blUIDs.contains(reply.User.UID)) { + blUIDs.add(reply.User.UID); + } + if (reply.ReplyTo > 0) { boolean added = false; for (int n = 0; n < replies.size(); n++) { - if (replies.get(n).RID == msg.ReplyTo) { - replies.get(n).childs.add(msg); + if (replies.get(n).RID == reply.ReplyTo) { + replies.get(n).childs.add(reply); added = true; break; } } if (!added) { - msg.ReplyTo = 0; + reply.ReplyTo = 0; } } } if (!replies.isEmpty()) { + if (visitor != null && msg.User.UID == visitor.UID) { + for (int i = 0; i < replies.size(); i++) { + replies.get(i).VisitorCanComment = true; + } + } else if (visitor != null && msg.VisitorCanComment) { + blUIDs = UserQueries.checkBL(sql, visitor.UID, blUIDs); + for (int i = 0; i < replies.size(); i++) { + com.juick.Message reply = replies.get(i); + reply.VisitorCanComment = reply.User.UID == visitor.UID || !blUIDs.contains(reply.User.UID); + } + } else { + for (int i = 0; i < replies.size(); i++) { + replies.get(i).VisitorCanComment = false; + } + } + + boolean foldable = false; + if (replies.size() > 10) { + for (int i = 0; i < replies.size() - 1; i++) { + if (replies.get(i).getChildsCount() > 1) { + foldable = true; + break; + } + } + } out.println("
    "); out.print(" "); out.println("

    " + rbuser.getString("Replies") + " (" + replies.size() + ")

    "); @@ -246,18 +251,18 @@ public class UserThread { if (listview) { printList(out, replies, locale); } else { - printTree(out, replies, 0, 0, locale); + printTree(out, replies, 0, 0, false, locale); } out.println(""); - } - for (int i = 0; i < replies.size(); i++) { - replies.get(i).cleanupChilds(); + for (int i = 0; i < replies.size(); i++) { + replies.get(i).cleanupChilds(); + } + replies.clear(); } - replies.clear(); } - public static void printTree(PrintWriter out, ArrayList replies, int ReplyTo, int margin, Locale locale) { + public static void printTree(PrintWriter out, ArrayList replies, int ReplyTo, int margin, boolean hidden, Locale locale) { ResourceBundle rb = ResourceBundle.getBundle("Global", locale); if (margin > 420) { @@ -273,7 +278,10 @@ public class UserThread { out.print("border: 0;"); } if (margin > 0) { - out.print("margin-left: " + margin + "px;display:none;"); + out.print("margin-left: " + margin + "px;"); + } + if (hidden) { + out.print("display:none;"); } out.println("\">"); if (msg.AttachmentType != null) { @@ -284,20 +292,26 @@ public class UserThread { } } out.println("
    \""
    "); - out.println(" "); + out.println(" "); out.println(" "); out.println("
    " + PageTemplates.formatMessage(msg.Text) + "
    "); - out.println(" "); - out.println("
    "); - if (ReplyTo == 0) { - int childs = msg.getChildsCount() - 1; - if (childs > 0) { - out.println(" "); - } + if (msg.VisitorCanComment) { + out.println(" "); + out.println("
    "); + } + + int childs = msg.getChildsCount(); + if (ReplyTo == 0 && childs > 1 && replies.size() > 10) { + out.println(" "); + } out.println("
  • "); - printTree(out, replies, msg.RID, margin + 20, locale); + if (ReplyTo == 0 && childs > 1 && replies.size() > 10) { + printTree(out, msg.childs, msg.RID, margin + 20, true, locale); + } else if (childs > 0) { + printTree(out, msg.childs, msg.RID, margin + 20, hidden, locale); + } } } } @@ -317,15 +331,17 @@ public class UserThread { } } out.println("
    "); - out.println(" "); + out.println(" "); out.println(" "); out.println("
    " + PageTemplates.formatMessage(msg.Text) + "
    "); out.print("
    /" + msg.RID); if (msg.ReplyTo > 0) { out.print(" " + rb.getString("in reply to") + " /" + msg.ReplyTo + ""); } - out.println(" · " + rb.getString("Comment") + "
    "); - out.println("
    "); + if (msg.VisitorCanComment) { + out.println(" · " + rb.getString("Comment") + ""); + out.println("
    "); + } out.println(" "); } } diff --git a/web/scripts3.js b/web/scripts3.js index c0de7757..1a5ffd66 100644 --- a/web/scripts3.js +++ b/web/scripts3.js @@ -1,8 +1,8 @@ function inlinevideo(mid) { var flashvars={ - file:'//i.juick.com/video/'+mid+'.mp4', - image:'//i.juick.com/thumbs/'+mid+'.jpg', - skin:'//static.juick.com/glow.zip', + file:'http://i.juick.com/video/'+mid+'.mp4', + image:'http://i.juick.com/thumbs/'+mid+'.jpg', + skin:'http://static.juick.com/glow.zip', autostart:'true' }; var params={ diff --git a/web/style3.css b/web/style3.css index 9612d0fa..2649de77 100644 --- a/web/style3.css +++ b/web/style3.css @@ -14,26 +14,15 @@ img { border: none; } #logo { float: left; margin: 3px 0 0 30px; } #header a { text-decoration: none; font-size: 18px; } -#search { float: left; margin: 10px 0 0 33px; } +#search { float: left; margin: 10px 0 0 51px; } #search .text { width: 285px; padding: 4px; border-radius: 2px; } #nav-right { float: right; } #nav-right li { float: left; } - -#header ul a { display: block; line-height: 48px; padding: 0 20px 0 20px; } -#nav-right img { vertical-align: middle; margin: 0 4px 0 0; } -#nav-menu { display: none; position: absolute; z-index: 1; } -#nav-menu li { float: none; } - -/********/ - -#title { display: none; clear: both; width: 100%; } -#title>h1 { margin: 20px auto; font-size: 28px; } -#title-av { width: 100px; height: 100px; margin-left: 20px; float: left; } -#title-av img { vertical-align: top; padding: 2px; } -#title-stats { width: 200px; float: right; border-left: 1px solid; } -#title-stats ul { margin: 10px 0 10px 20px; } -#title-username { margin: 0 220px 0 140px; } +#nav-right a { display: block; line-height: 48px; padding: 0 15px; } +#nav-right .wide { padding: 0 20px; } +#nav-right img { max-width: 32px; max-height: 32px; vertical-align: middle; margin: 0 4px 0 0; } +#nav-right .ico24 { width: 24px; height: 24px; background: url(//static.juick.com/icons24.png) no-repeat; padding: 12px 0; } /********/ @@ -55,11 +44,10 @@ img { border: none; } #content .msgthread { margin-bottom: 0; } #content .msg-avatar { float: left; } #content .msg-avatar img { width: 48px; height: 48px; vertical-align: top; } -#content .msg-ts { float: right; } -#content .msg-ts>a { font-size: small; vertical-align: top; } +#content .msg-ts { float: right; font-size: small; vertical-align: top; } #content .msg-header { margin-left: 58px; overflow: hidden; } #content .msg-place { font-size: small; margin: 8px 0 8px 58px; } -#content .msg-txt { margin: 8px 0 8px 58px; } +#content .msg-txt { margin: 8px 0 8px 58px; overflow: hidden; } #content .msg-media { text-align: center; margin: 8px 0 0px 58px; } #content .msg-links { font-size: small; margin: 8px 0 0 68px; } #content .msg-comments { margin: 10px 0 0 58px; padding: 5px 0 0 10px; overflow: hidden; font-size: small; border-top: 1px solid; } @@ -117,10 +105,9 @@ table.users img { width: 32px; height: 32px; vertical-align: middle; margin-righ html { background: #EEEEE5; color: #000; } a { color: #069; } #hwrapper { background: #333; } -#header a { color: #AAA; } -#header li a:hover { background: #444; } +#nav-right a { color: #AAA; } +#nav-right a:hover { background: #444; } #title { background: #F0F0F0; } -#nav-menu { background: #DDD; } #title-stats { border-color: #CCC; } #search .text { border: none; background-color: #EEE; } @@ -130,7 +117,7 @@ a { color: #069; } #content .msgthread { border-bottom-color: #CCC; } #content .msg-place { color: #999; } #content .msg-comments { color: #AAA; border-color: #DDD; } -#content .msg-ts>a { color: #999; } +#content .msg-ts, .msg-ts>a { color: #999; } #content .msg-links { color: #999; } #content .msg-comment textarea { border-color: #DDD; } #content .msg-comment input { border-color: #CCC; background-color: #EEE; color: #999; } -- cgit v1.2.3