use of web.HTMLWriter in project common by zenlunatics.
the class Comments method writeComment.
// --------------------------------------------------------------------------
private static void writeComment(String table, Object[] values, List<Object[]> rows, int depth, Calendar now, Request request) throws IOException {
HTMLWriter writer = request.writer;
writer.write("<div class=\"comment");
if (values[0].equals(request.getParameter("db_comment_id")))
writer.write(" comments_hilite");
writer.write('"');
if (depth > 0)
writer.write(" style=\"padding-left:").write(depth * 15).write("px;\"");
writer.write('>');
Person user = request.getUser();
boolean can_delete = ((Integer) values[3]).intValue() == user.getId() || request.userIsAdmin();
boolean can_edit = ((Integer) values[3]).intValue() == user.getId();
if (can_edit || can_delete)
writer.setAttribute("onclick", "comment_popup(this,'" + table + "_comments'," + values[0] + "," + (can_edit ? "true" : "false") + "," + (can_delete ? "true" : "false") + ");return false;").icon("chevron-down");
if (values[8] != null)
writer.write("<div style=\"float:left;\"><img src=\"").write(request.getContext()).write("/people/").write(values[5]).write("/").write(values[8]).write("\" onclick=\"new Dialog({url:context+'/People/").write(values[5]).write("'});return false;\" style=\"cursor:pointer\"/></div>");
writer.write("<div class=\"comment_text\">");
writer.write("<span class=\"comment_person\" onclick=\"new Dialog({url:context+'/People/").write(values[5]).write("'});return false;\" style=\"cursor:pointer\">").write(Util.join(" ", (String) values[6], (String) values[7])).write("</span> ");
writer.writeWithLinks(values[1].toString());
writer.write("<div class=\"comment_time\">");
writer.write(request.date_time_formatter.getTimeAgo((Timestamp) values[4], now));
writer.write("</div></div></div>");
Integer id = (Integer) values[0];
for (Object[] row_values : rows) if (id.equals(row_values[2]))
writeComment(table, row_values, rows, depth + 1, now, request);
}
use of web.HTMLWriter in project common by zenlunatics.
the class Comments method writeComments.
// --------------------------------------------------------------------------
public static void writeComments(String table, int id, Request request) throws IOException {
HTMLWriter writer = request.writer;
writer.write("<div class=\"comments_divider\"></div>");
writer.setAttribute("class", "comments");
String uuid = UUID.randomUUID().toString();
writer.componentOpen(uuid, request.getContext() + "/" + table + "_comments?id=" + id, null);
writeComments2(table, id, request);
writer.tagClose();
}
use of web.HTMLWriter in project common by zenlunatics.
the class Comments method after.
// --------------------------------------------------------------------------
// FormHook
@Override
public void after(View view, View.Mode mode, boolean printer_friendly, Request request) throws IOException {
if (mode == View.Mode.ADD_FORM || mode == View.Mode.FILTER_FORM)
return;
HTMLWriter writer = request.writer;
writer.write("<tr><td>");
if (m_provider != null) {
Likes.write(m_provider, view.data().getInt("id"), request);
writer.write("</td></tr><tr><td>");
}
Comments.writeComments(view.getViewDef().getFrom(), view.data().getInt("id"), request);
writer.write("</td></tr>");
}
use of web.HTMLWriter in project common by zenlunatics.
the class Comments method writeEditForm.
// --------------------------------------------------------------------------
public void writeEditForm(String comment_id, Request request) throws IOException {
HTMLWriter writer = request.writer;
writer.write("<div class=\"status\">");
writer.setAttribute("rows", "2");
writer.textAreaExpanding("post", "width:100%", request.db.lookupString(new Select("comment").from(m_name).whereIdEquals(comment_id)), false);
writer.scriptOpen();
writer.write("Dialog.top().add_ok('Save',function(){" + "var v=$('post').value;if(!v)return;XHR_post(context+'/").write(m_name).write("/").write(comment_id).write("/update','comment='+encodeURIComponent(v)");
if (m_provider != null) {
int item_id = request.db.lookupInt(new Select(m_items_table + "_id").from(m_name).whereIdEquals(comment_id), -1);
int news_id = request.db.lookupInt(new Select("id").from("news").where("provider='" + m_provider.getName() + "' AND item_id=" + item_id), -1);
writer.write(",function(){replace_news_item(").write(news_id).write(")}");
}
writer.write(")});");
writer.scriptClose();
}
use of web.HTMLWriter in project common by zenlunatics.
the class Likes method write.
// --------------------------------------------------------------------------
public static void write(NewsProvider provider, int item_id, Request request) throws IOException {
HTMLWriter writer = request.writer;
StringBuilder people = null;
boolean user_likes = false;
String likes = request.db.lookupString("likes", provider.getTable(), item_id);
if (likes != null) {
String[] ids = likes.split(",");
Person user = request.getUser();
String user_id = user == null ? null : Integer.toString(user.getId());
people = new StringBuilder();
for (String id : ids) if (user_id != null && id.equals(user_id)) {
if (people.length() > 0)
people.insert(0, ", ");
people.insert(0, "You");
user_likes = true;
} else {
if (people.length() > 0)
people.append(", ");
people.append(request.site.lookupName(Integer.parseInt(id), request.db));
}
}
writer.write("<div class=\"likes\"><a href=\"#\" title=\"").write(user_likes ? "Unlike" : "Like").write(" this\" onclick=\"return ").write(user_likes ? "unlike" : "like").write("(this,'").write(provider.getName()).write("',").write(item_id).write(")\">").write(user_likes ? "Unlike" : "Like").write("</a>");
if (people != null) {
writer.write(" ยท ");
int comma = people.lastIndexOf(",");
if (comma == -1)
writer.write(people.toString()).write("You".equals(people.toString()) ? " like this." : " likes this.");
else
writer.write(people.substring(0, comma)).write(" and").write(people.substring(comma + 1)).write(" like this.");
}
writer.write("</div>");
}
Aggregations