Search in sources :

Example 1 with Person

use of app.Person in project common by zenlunatics.

the class MailLists method writeLists.

// --------------------------------------------------------------------------
public void writeLists(Request request) throws IOException {
    Person user = request.getUser();
    int user_id = user.getId();
    Select query = new Select("mail_lists.id,mail_lists.name,mail_lists_people.mail_lists_id,mail_lists_digest.mail_lists_id").from("mail_lists LEFT JOIN mail_lists_people ON (mail_lists_people.mail_lists_id=mail_lists.id AND mail_lists_people.people_id=" + user_id + ") LEFT JOIN mail_lists_digest ON (mail_lists_digest.mail_lists_id=mail_lists.id AND mail_lists_digest.people_id=" + user_id + ")").where(request.testSessionFlag("show inactive lists") ? null : "mail_lists.active").orderBy("LOWER(mail_lists.name)");
    ResultSet rs = request.db.select(query);
    HTMLWriter writer = request.writer;
    writer.write("<table class=\"table table-hover\"><thead><tr><th>send email to list</th><th>archives</th><th>latest post</th><th>subscribed</th><th>nightly digest</th></tr></thead>");
    try {
        while (rs.next()) {
            int list_id = rs.getInt(1);
            String list = rs.getString(2);
            MailHandler mail_handler = getMailHandler(list, request.db);
            boolean subscribed = mail_handler != null ? mail_handler.isSubscribed(user, request) : rs.getString(3) != null;
            boolean archives_public = new MailList(list_id, request.site, request.db).archivesPublic();
            if (mail_handler != null && !archives_public && !subscribed)
                continue;
            writer.write("<tr class=\"lists\"><td>");
            String address = list + "@" + request.site.getSettings().getString("mail list domain");
            writer.a(m_show_full_address_on_email_page ? address : list, "mailto:" + address);
            writer.write("</td><td style=\"text-align:center\">");
            if (!archives_public && !subscribed)
                writer.setAttribute("style", "display:none");
            writer.setAttribute("id", "view" + list_id);
            writer.aButtonOnClick("view", "document.location=context+'/MailLists/" + list_id + "'");
            writer.write("</td><td>");
            if (!archives_public && !subscribed)
                writer.setAttribute("style", "display:none");
            writer.setAttribute("id", "date" + list_id);
            writer.tagOpen("span");
            writer.writeDate(request.db.lookupDate(new Select("max(arrived)").from("ml_" + list_id)));
            writer.tagClose();
            writer.write("</td><td style=\"text-align:center\">");
            if (mail_handler != null) {
                if (subscribed)
                    writer.write("&#10003;");
            } else {
                StringBuilder on_change = new StringBuilder("$('digest").append(list_id).append("').style.display=this.checked?'':'none';");
                if (!archives_public) {
                    on_change.append("$('view").append(list_id).append("').style.display=this.checked?'':'none';");
                    on_change.append("$('date").append(list_id).append("').style.display=this.checked?'':'none';");
                }
                on_change.append("toggle_subscription(this,").append(list_id).append(");return false");
                writer.setAttribute("onchange", on_change.toString());
                writer.checkbox(null, null, null, subscribed, true);
            }
            writer.write("</td><td style=\"text-align:center\">");
            writer.setAttribute("id", "digest" + list_id);
            writer.setAttribute("onchange", "toggle_digest(this," + list_id + ");return false");
            if (!subscribed)
                writer.setAttribute("style", "display:none");
            writer.checkbox(null, null, null, rs.getString(4) != null, true);
            writer.write("</td></tr>");
        }
        rs.getStatement().close();
    } catch (SQLException e) {
        request.abort(e);
    }
    writer.write("</table>");
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) Select(db.Select) ResultSet(java.sql.ResultSet) Person(app.Person)

Example 2 with Person

use of app.Person in project common by zenlunatics.

the class Comments method writeCommentInput.

// --------------------------------------------------------------------------
public static String writeCommentInput(String table, int item_id, Request request) throws IOException {
    Person user = request.getUser();
    if (user == null)
        return null;
    HTMLWriter writer = request.writer;
    writer.write("<div class=\"comment_input\"><table style=\"width:100%\"><tr>");
    String picture = user.getPicture(request);
    if (picture != null)
        writer.write("<td style=\"width:40px;\"><img src=\"" + picture + "\" /></td>");
    writer.write("<td><div>");
    String id = UUID.randomUUID().toString();
    writer.write("<input id=\"").write(id).write("\" type=\"text\" placeholder=\"Write a comment...\" style=\"width:100%\"/>");
    writer.js("$('" + id + "').addEvent('keypress',function(e){if(e.key==='enter'){if(!e.target.value)return;XHR_post(context+'/" + table + "_comments/add','item_id=" + item_id + "&comment='+encodeURIComponent(e.target.value),function(){c_(e.target).replace(null,{ignore:true});});e.stop();}});");
    writer.write("</div></td></tr></table></div>");
    return id;
}
Also used : HTMLWriter(web.HTMLWriter) Person(app.Person)

Example 3 with Person

use of app.Person in project common by zenlunatics.

the class EventProvider method getEventEditJS.

// --------------------------------------------------------------------------
protected String getEventEditJS(Event event, Request request) {
    Person user = request.getUser();
    if (user == null)
        return null;
    // if (m_access_policy != null && !m_access_policy.showEditButtons(null, request) && !request.userIsAdmin())
    // return null;
    boolean read_only = m_events_are_owned && user.getId() != event.getOwner() && !request.userHasRole("calendar editor") && !request.userIsAdmin();
    if (read_only && m_access_policy != null)
        read_only = !m_access_policy.canUpdateRow(m_events_table, event.getID(), request);
    return "$('calendar').calendar.edit('" + HTMLWriter.escapeJSString(m_name) + "','" + HTMLWriter.escapeJSString(m_display_name) + "'," + event.getID() + "," + (read_only ? "true" : "false") + ")";
}
Also used : Person(app.Person)

Example 4 with Person

use of app.Person in project common by zenlunatics.

the class News method deleteItem.

// --------------------------------------------------------------------------
private void deleteItem(int id, Request request) {
    Person user = request.getUser();
    String[] item = request.db.readRow(new Select("provider,item_id,_owner_").from("news").whereIdEquals(id));
    if (item == null)
        return;
    if (user.getId() == Integer.parseInt(item[2]) || request.userIsAdmin()) {
        request.db.deleteById("news", id);
        request.db.deleteById(m_providers.get(item[0]).getTable(), Integer.parseInt(item[1]));
    }
}
Also used : Select(db.Select) Person(app.Person)

Example 5 with Person

use of app.Person in project common by zenlunatics.

the class NewsItem method writeHeader.

// --------------------------------------------------------------------------
protected final void writeHeader(Calendar now, HTMLWriter writer) throws IOException {
    String[] person = m_request.db.readRow(new Select("first,last,picture").from("people").whereIdEquals(m_person_id));
    writer.write("<div class=\"news_item_header\">");
    if (person != null) {
        Person user = m_request.getUser();
        boolean can_delete = m_provider.canDelete() && user != null && (m_person_id == user.getId() || m_request.userIsAdmin());
        boolean can_edit = m_provider.canEdit() && user != null && m_person_id == user.getId();
        if (can_delete || can_edit)
            writer.setAttribute("onclick", "item_popup(this," + m_news_id + (can_edit ? ",true" : ",false") + (can_delete ? ",true" : ",false") + ");return false;").icon("chevron-down");
        if (person[2] != null)
            writer.write("<img src=\"" + m_request.getContext() + "/people/" + m_person_id + "/" + person[2] + "\" onclick=\"new Dialog({url:context+'/People/").write(m_person_id).write("'});return false;\" style=\"cursor:pointer\"/>");
    }
    writer.write("<div style=\"display:inline-block;vertical-align:middle;\">");
    writer.write("<h5 style=\"color:inherit;\">");
    if (person != null)
        writer.write("<span class=\"news_item_person\" onclick=\"new Dialog({url:context+'/People/").write(m_person_id).write("'});return false;\" style=\"cursor:pointer\">").write(Util.join(" ", person[0], person[1])).write("</span> ");
    String action = getAction();
    if (action != null)
        writer.write(action);
    writer.write("</h5>");
    writer.write(m_request.date_time_formatter.getTimeAgo(m_timestamp, now));
    writer.write("</div></div>");
}
Also used : Select(db.Select) Person(app.Person)

Aggregations

Person (app.Person)14 HTMLWriter (web.HTMLWriter)7 Select (db.Select)5 Page (app.Page)1 Pages (app.Pages)1 Request (app.Request)1 DBObjects (db.DBObjects)1 RowsSelect (db.RowsSelect)1 FileColumn (db.column.FileColumn)1 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1 Calendar (java.util.Calendar)1 Enumeration (java.util.Enumeration)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 NavBar (web.NavBar)1 Select (web.Select)1