Search in sources :

Example 46 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class People method writeRolesPane.

// --------------------------------------------------------------------
@SuppressWarnings("unchecked")
private void writeRolesPane(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.setAttribute("style", "margin-bottom:20px;");
    writer.aButtonOnClick("add", "dialog_prompt('Role',function(r){XHR_post(context+'/People/Roles/'+r+'/add',null,function(){$('EditSite').replace()})},{title:'Add Role'})");
    List<SelectOption> roles = (List<SelectOption>) request.site.getObjects("_roles_").getObjects();
    for (SelectOption role : roles) {
        String text = role.getText();
        writer.write("<div class=\"panel panel-default\"><div class=\"panel-heading\" style=\"display:flex;justify-content:space-between\">");
        writer.write(text);
        if (!"admin".equals(text) && !"coho".equals(text))
            writer.aButtonOnClick("delete", "dialog_confirm('Delete " + text + " role?' ,function(){XHR_post(context+'/People/Roles/" + text + "/delete',null,function(){$('EditSite').replace()})})");
        writer.write("</div><div class=\"panel-body\">");
        List<String> people = request.db.readValues(new Select("first || ' ' || last").from("people").join("people", "user_roles").where("role='" + text + "'"));
        writer.write(Util.join(", ", people));
        writer.write("</div></div>");
    }
}
Also used : HTMLWriter(web.HTMLWriter) SelectOption(web.SelectOption) Select(db.Select) ArrayList(java.util.ArrayList) List(java.util.List)

Example 47 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Site method writeLoginForm.

// --------------------------------------------------------------------------
public void writeLoginForm(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.write("<table style=\"margin:20px auto;\"><tr><td>").write("<form method=\"post\" action=\"j_security_check\">").write("<table><tr>").write("<td style=\"padding-right:10px;vertical-align:middle;\">user name</td>").write("<td style=\"padding-right:10px;vertical-align:middle;\"><div class=\"input-group input-group-sm\" style=\"margin-bottom:0\"><span class=\"input-group-addon\">").icon("user").write("</span><input id=\"user_name\" type=\"text\" name=\"j_username\" class=\"form-control\" autofocus autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\"/></div></td>").write("<td style=\"padding-right:10px;vertical-align:middle;\" id=\"label\">password</td>").write("<td style=\"padding-right:10px;vertical-align:middle;\" id=\"pw\"><div class=\"input-group input-group-sm\" style=\"margin-bottom:0\"><span class=\"input-group-addon\">").icon("lock").write("</span><input type=\"password\" name=\"j_password\" class=\"form-control\"/></div></td>").write("<td style=\"padding-right:10px;vertical-align:middle;\" id=\"login\"><input class=\"btn btn-default btn-sm\" type=\"submit\" value=\"login\" /></td>").write("<td style=\"vertical-align:middle;\"><a id=\"link\" href=\"#\" onclick=\"$('label').style.display='none';$('pw').style.display='none';$('login').style.display='none';$('link').style.display='none';$('senddiv').style.display='table';return false\" style=\"font-size: smaller\">forgot password?</a></td>").write("</tr></table></form></td><td>").write("<table id=\"senddiv\" style=\"display: none\"><tr>").write("<td style=\"padding-right:10px;vertical-align:middle;\">enter your user name and click reset</td>").write("<td style=\"padding-right:10px;vertical-align:middle;\"><input class=\"btn btn-default btn-sm\" type=\"button\" value=\"reset\" onclick=\"new Request({method:'post',url:context+'/resetpw',evalResponse:true}).send('user_name='+$('user_name').value);\" />").write("<td style=\"padding-right:10px;vertical-align:middle;\"><input class=\"btn btn-default btn-sm\" type=\"button\" value=\"cancel\" onclick=\"$('link').style.display='';$('label').style.display='';$('pw').style.display='';$('login').style.display='';$('senddiv').style.display='none';return false\" />").write("</td></tr></table></td></tr></table>");
    if (m_settings.getString("allow create accounts") != null) {
        writer.write("<p>");
        writer.setAttribute("id", "createa");
        writer.aOnClick("create a new account", "document.getElementById('creatediv').style.display='block';document.getElementById('createa').style.display='none'");
        writer.write("<div id=\"creatediv\" style=\"display:none\">");
        writer.jsFunction("go_back", null, "document.getElementById('creatediv').style.display='none';dialog_alert('','account added')");
        ViewState.setShowReturnLink("people", false, request);
        request.site.newView("people", request).writeAddForm();
        writer.write("</div></p>");
    }
}
Also used : HTMLWriter(web.HTMLWriter)

Example 48 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailList method search.

// --------------------------------------------------------------------------
void search(String search, boolean all, boolean subject, boolean message, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.write("messages that contain");
    String[] tokens = search.split(" ");
    if (tokens.length > 1) {
        writer.write(all ? " all" : " any");
        writer.write(" of the following words: ");
    } else
        writer.write(": ");
    writer.write(search);
    writer.write("<br />");
    search = DBConnection.escape(search);
    StringBuilder filter = new StringBuilder();
    if (subject) {
        filter.append('(');
        int num_tokens = 0;
        for (String token : tokens) if (token.length() > 0) {
            if (num_tokens != 0)
                filter.append(all ? " AND " : " OR ");
            filter.append("subject ILIKE ");
            token = DBConnection.escape(token);
            if (token.indexOf('%') != -1) {
                filter.append("E'%");
                filter.append(token.replace("%", "\\\\%"));
            } else {
                filter.append("'%");
                filter.append(token);
            }
            filter.append("%'");
            ++num_tokens;
        }
        filter.append(')');
    }
    if (message)
        if (m_store_on_disk) {
            String ids = searchOnDisk(tokens, all);
            if (ids.length() > 0) {
                filter.append(filter.length() == 0 ? '(' : " OR (");
                filter.append("id IN (" + ids + ")");
                filter.append(')');
            }
        } else {
            filter.append(filter.length() == 0 ? '(' : " OR (");
            int num_tokens = 0;
            for (String token : tokens) if (token.length() > 0) {
                if (num_tokens != 0)
                    filter.append(all ? " AND " : " OR ");
                filter.append("message ILIKE ");
                token = DBConnection.escape(token);
                if (token.indexOf('%') != -1) {
                    filter.append("E'%");
                    filter.append(token.replace("%", "\\\\%"));
                } else {
                    filter.append("'%");
                    filter.append(token);
                }
                filter.append("%'");
                ++num_tokens;
            }
            filter.append(')');
        }
    ViewState.setFilter("ml_" + m_id, filter.toString(), request);
    request.site.newView("ml_" + m_id, request).setSelectColumnNamesTable().writeComponent();
}
Also used : HTMLWriter(web.HTMLWriter)

Example 49 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method _newViewDef.

// --------------------------------------------------------------------------
// @AdminTask
// public static void
// moveAllMessagesToDisk(Request request)
// {
// try {
// List<String> lists = request.db.readValues(new Select("name").from("mail_lists").where("NOT store_on_disk"));
// for (String list : lists) {
// request.writer.write("writing " + list + "<br />");
// System.out.println("writing " + list);
// new MailList(list, request.site, request.db).moveMessagesToDisk(request);
// }
// } catch (IOException e) {
// request.abort(e);
// }
// }
// --------------------------------------------------------------------------
// @AdminTask({"list name"})
// public static void
// moveMessagesToDisk(String list_name, Request request)
// {
// try {
// new MailList(list_name, request.site, request.db).moveMessagesToDisk(request);
// } catch (IOException e) {
// request.abort(e);
// }
// }
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals("additional_emails"))
        return new ViewDef(name).setDefaultOrderBy("email").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setRecordName("Additional email");
    if (name.equals("mail_lists"))
        return new ViewDef(name) {

            @Override
            public boolean beforeUpdate(int id, NameValuePairs name_value_pairs, Map<String, Object> previous_values, Request request) {
                if (!name_value_pairs.getBoolean("active") && request.db.lookupBoolean(new Select("active").from("mail_lists").whereIdEquals(id)))
                    request.db.delete("mail_lists_people", "mail_lists_id=" + id);
                return super.beforeUpdate(id, name_value_pairs, previous_values, request);
            }
        }.addDeleteHook(this).addInsertHook(this).addUpdateHook(this).setDefaultOrderBy("name").setRecordName("Mail List").setColumnNamesForm(new String[] { "name", "send_to", "active", "announce_only", "archive", "archives_public", "footer", "allow_from_outside", "allow_from_outside_subscribers", "subscribers", "username", "host", "password", "store_on_disk" }).setColumnNamesFormTable(new String[] { "name" }).setColumnNamesTable(new String[] { "name", "send_to", "active" }).setColumn(new Column("allow_from_outside").setDisplayName("accept posts from outside non-subscribers (i.e. anyone)")).setColumn(new Column("allow_from_outside_subscribers").setDisplayName("accept posts from outside subscribers")).setColumn(new Column("announce_only").setTitle("If this is checked, replies to posts from this list will be ignored.")).setColumn(new Column("footer").setTitle("Optional text that will be added to the bottom of every post to this list")).setColumn(new Column("host").setIsHidden(true)).setColumn(new Column("name").setPostText("@" + site.getDomain()).setDisplayName("address").setIsRequired(true)).setColumn(new Column("password").setDefaultToUUID().setIsHidden(true)).setColumn(new Column("send_to") {

            @Override
            protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
                String value = null;
                if (mode == Mode.EDIT_FORM)
                    value = view.data().getString("send_to");
                HTMLWriter writer = request.writer;
                writer.write("<select name=\"send_to\"><option value=\"Subscribers\">Subscribers</options>");
                for (MailHandlerFactory mail_handler_factory : m_mail_handler_factories) mail_handler_factory.writeSendToOptions(value, request.db, writer);
                writer.write("</select>");
            }

            @Override
            public boolean writeValue(View view, Map<String, Object> data, Request request) throws IOException {
                String send_to = view.data().getString("send_to");
                if ("Subscribers".equals(send_to))
                    request.writer.write(send_to);
                else {
                    MailHandler mail_handler = getMailHandler(view.data().getString("name"), request.db);
                    if (mail_handler != null)
                        request.writer.write(mail_handler.getDisplayName());
                }
                return true;
            }
        }).setColumn(new Column("store_on_disk").setIsHidden(true)).setColumn(new Column("username").setIsHidden(true)).addRelationshipDef(new ManyToMany("people", "mail_lists_people", "first,last").setViewRole("administrator")).addRelationshipDef(new OneToMany("subscribers").setSpanFormCols(false));
    if (name.equals("mail_lists_people"))
        return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setColumn(new LookupColumn("mail_lists_id", "mail_lists", "name", new Select("id,name,send_to,active").from("mail_lists").orderBy("name"), "name").setFilter(new Filter() {

            @Override
            public boolean accept(ResultSet rs, Request request) {
                try {
                    return rs.getBoolean("active") && "Subscribers".equals(rs.getString("send_to"));
                } catch (SQLException e) {
                    request.abort(e);
                }
                return false;
            }
        }).setDisplayName("mail list")).setColumn(new LookupColumn("people_id", "people", "first,last").setFilter(site.getPeopleFilter()));
    if (name.startsWith("ml_"))
        return new ViewDef(name).setAccessPolicy(new RoleAccessPolicy("admin").delete()).setDefaultOrderBy("arrived DESC").setRecordName("Message").setRowWindowSize(0).setShowFilterLink(false).setShowHead(false).setColumnNamesTable(new String[] { "arrived", "sender", "subject" }).setColumn(new Column("subject") {

            @Override
            public boolean writeValue(View view, Map<String, Object> data, Request request) throws IOException {
                String subject = view.data().getString("subject");
                if (subject == null || subject.length() == 0)
                    subject = "(no subject)";
                request.writer.aOnClick(subject, "new Dialog({url:context+'/MailLists?list=" + view.getViewDef().getName() + "&cmd=get_message&db_key_value=" + view.data().getString("id") + "',title:'" + HTMLWriter.escapeJSString(subject) + "'});");
                return true;
            }
        });
    if (name.equals("people mail_lists"))
        return new ViewDef(name).setAccessPolicy(new AccessPolicy().add().delete()).setAddButtonText("subscribe").setDeleteButtonText("unsubscribe").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setFrom("mail_lists").setRecordName("Mail List").setColumnNamesTable(new String[] { "name" });
    if (name.equals("subscribers"))
        return new ViewDef(name).setDefaultOrderBy("email").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setRecordName("Outside Subscriber");
    return null;
}
Also used : Form(db.Form) SQLException(java.sql.SQLException) ViewDef(db.ViewDef) AccessPolicy(db.access.AccessPolicy) RoleAccessPolicy(db.access.RoleAccessPolicy) JDBCColumn(db.JDBCColumn) LookupColumn(db.column.LookupColumn) Column(db.column.Column) ResultSet(java.sql.ResultSet) RoleAccessPolicy(db.access.RoleAccessPolicy) HTMLWriter(web.HTMLWriter) NameValuePairs(db.NameValuePairs) Mode(db.View.Mode) Request(app.Request) ManyToMany(db.ManyToMany) OneToMany(db.OneToMany) View(db.View) LookupColumn(db.column.LookupColumn) Filter(db.Filter) FileFilter(java.io.FileFilter) Select(db.Select) DBObject(db.DBObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 50 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MailLists method writeReplyForm.

// --------------------------------------------------------------------------
private void writeReplyForm(String list, int message_id, boolean reply_to_sender, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    try {
        ResultSet rs = request.db.select(new Select("subject,message").from(list).whereIdEquals(message_id));
        rs.next();
        String subject = rs.getString(1);
        MailList mail_list = new MailList(Integer.parseInt(list.substring(3)), request.site, request.db);
        String text = mail_list.loadMessage(message_id, rs);
        rs.getStatement().close();
        if (text == null) {
            writer.write("Message file not found.");
            return;
        }
        String to;
        if (reply_to_sender)
            try {
                MimeMessage message = new MimeMessage(getSession(), new ByteArrayInputStream(text.getBytes()));
                String[] header = message.getHeader("Return-Path");
                to = header[0];
                int index = to.indexOf('<');
                if (index != -1)
                    to = to.substring(index + 1, to.indexOf('>', index));
            } catch (MessagingException e) {
                sendError(list, "writeReplyForm", null, null, e);
                throw new RuntimeException(e);
            }
        else
            to = mail_list.getName() + "@" + m_site.getDomain();
        if (subject.length() > 2 && !subject.substring(0, 3).equalsIgnoreCase("Re:"))
            subject = "Re: " + subject;
        writer.write("<form method=\"POST\" action=\"" + request.getContext() + "/EMailForm\"><p><b>from: </b>");
        String from = request.getUser().getEmail();
        writer.write(from);
        writer.write("</p><p><b>to: </b>");
        writer.hiddenInput("cmd", "send");
        boolean send_from_local_domain = request.site.getSettings().getString("send from local domain") != null;
        writer.hiddenInput(send_from_local_domain ? "reply_to" : "from", from);
        writer.hiddenInput("email", to);
        writer.write(to);
        writer.write("</p><p><b>subject: </b>");
        writer.hiddenInput("subject", subject);
        writer.write(subject);
        writer.write("</p><p><textarea id=\"message_ta\" name=\"message\" style=\"width:100%;height:400px;\"><br /><br /><blockquote style=\"border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;\">");
        try {
            InputStream is = new ByteArrayInputStream(text.getBytes());
            MimeMessage message = new MimeMessage(getSession(), is);
            Object content = message.getContent();
            if (content instanceof MimeMultipart)
                WebMail.writePart(message, message_id, (MimeMultipart) content, new ArrayList<Integer>(), writer);
            else
                writer.write(content.toString());
        } catch (MessagingException e) {
            sendError(list, "writeReplyForm", null, null, e);
            throw new RuntimeException(e);
        }
        writer.write("</blockquote></textarea></p><p>");
        writer.aButtonOnClick("send", "send_form(this,function(t){rich_text_remove($('ml_message'));$('ml_message').set('html','message sent')})");
        writer.write("</p></form>");
        writer.js("rich_text('message_ta');");
    } catch (SQLException e) {
        sendError(list, "writeReplyForm", null, null, e);
        throw new RuntimeException(e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) MessagingException(javax.mail.MessagingException) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MimeMessage(javax.mail.internet.MimeMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) MimeMultipart(javax.mail.internet.MimeMultipart) ResultSet(java.sql.ResultSet) Select(db.Select) DBObject(db.DBObject)

Aggregations

HTMLWriter (web.HTMLWriter)109 Select (db.Select)18 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)14 Table (web.Table)12 JDBCTable (db.JDBCTable)10 Person (app.Person)7 Calendar (java.util.Calendar)7 ArrayList (java.util.ArrayList)6 JDBCColumn (db.JDBCColumn)5 View (db.View)5 DBObject (db.DBObject)4 Form (db.Form)4 File (java.io.File)4 AdminTask (web.AdminTask)4 FilePathStringBuilder (web.FilePathStringBuilder)4 Select (web.Select)4 Mode (db.View.Mode)3 IOException (java.io.IOException)3 NumberFormat (java.text.NumberFormat)3