Search in sources :

Example 41 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class MonthView method write.

// --------------------------------------------------------------------------
@Override
public void write(int year, int month, int date, String category, String location, Request request) throws IOException {
    java.util.Calendar c = request.site.newCalendar();
    c.set(year, month, date);
    java.util.Calendar c2;
    java.util.Calendar today = request.site.newCalendar();
    HTMLWriter writer = request.writer;
    c.set(java.util.Calendar.DAY_OF_MONTH, 1);
    c2 = (java.util.Calendar) c.clone();
    c2.add(java.util.Calendar.MONTH, 1);
    int first_day_of_week = c.getFirstDayOfWeek();
    int num_days_before = c.get(java.util.Calendar.DAY_OF_WEEK) - first_day_of_week;
    if (num_days_before > 0)
        c.add(java.util.Calendar.DATE, -num_days_before);
    while (c2.get(Calendar.DAY_OF_WEEK) != first_day_of_week) c2.add(Calendar.DATE, 1);
    TreeSet<Event> events = new TreeSet<Event>();
    m_event_provider.addCalendarsEvents(events, c, c2, category, location, request);
    writer.write("<table class=\"month_view\"");
    if (m_event_provider.oneEventPerDay())
        writer.write(" data-one-per-day=\"true\"");
    writer.write("><tr>");
    // if (allowViewSwitching())
    // writer.write("<td class=\"week\" style=\"width:10px\"><font size=\"-1\">week</font></td>");
    String[] weekdays = request.date_time_formatter.date_format_symbols.getWeekdays();
    for (int i = 1; i <= 7; i++) writer.tag("th", weekdays[i]);
    writer.write("</tr>");
    boolean show_add = request.getUser() != null && m_event_provider.showAddButton(request);
    if (num_days_before > 0) {
        weekRowOpen(c, request);
        for (int i = 0; i < num_days_before; i++) {
            writeDay(events, c, today, false, show_add, request);
            c.add(java.util.Calendar.DATE, 1);
        }
    }
    int m = c.get(java.util.Calendar.MONTH);
    do {
        if (c.get(java.util.Calendar.DAY_OF_WEEK) == java.util.Calendar.SUNDAY)
            weekRowOpen(c, request);
        writeDay(events, c, today, true, show_add, request);
        if (c.get(java.util.Calendar.DAY_OF_WEEK) == java.util.Calendar.SATURDAY)
            writer.tagClose();
        c.add(java.util.Calendar.DATE, 1);
    } while (m == c.get(java.util.Calendar.MONTH));
    if (c.get(Calendar.DAY_OF_WEEK) != first_day_of_week) {
        while (c.get(Calendar.DAY_OF_WEEK) != first_day_of_week) {
            writeDay(events, c, today, false, show_add, request);
            c.add(java.util.Calendar.DATE, 1);
        }
        writer.tagClose();
    }
    writer.write("</table>");
}
Also used : Calendar(java.util.Calendar) HTMLWriter(web.HTMLWriter) TreeSet(java.util.TreeSet)

Example 42 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Design method write.

// --------------------------------------------------------------------------
public void write(Page page, Request request) throws IOException {
    getHead(request).close();
    HTMLWriter writer = request.writer;
    ResultSet rs = request.db.select(new Select("*").from("designs_items").where("designs_id=" + m_id).orderBy("_order_"));
    try {
        while (rs.next()) {
            String type = rs.getString("type");
            if ("html".equals(type))
                writer.write(rs.getString("data"));
            else if ("page".equals(type))
                page.write(request);
        }
    } catch (SQLException e) {
    } finally {
        try {
            rs.getStatement().close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    request.close();
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Select(db.Select)

Example 43 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class FileManager method writeDirectory.

// --------------------------------------------------------------------------
private void writeDirectory(String path, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.write("<ul class=\"breadcrumb\" style=\"background-color:#eee\">");
    if (path.length() > 0) {
        String[] dirs = path.split("/");
        String p = "";
        writer.write("<li><a href=\"#\" onclick=\"change_dir('')\">/</a></li>");
        for (int i = 0; i < dirs.length - 1; i++) {
            if (i > 0)
                p += "/";
            p += dirs[i];
            writer.write("<li><a href=\"#\" onclick=\"change_dir('").write(p).write("')\">").write(dirs[i]).write("</a></li>");
        }
        writer.write("<li>").write(dirs[dirs.length - 1]).write("</li>");
    } else
        writer.write("<li>/</li>");
    writer.write("</ul>");
    Table table = new Table(request.writer);
    table.tr();
    writer.setAttribute("valign", "top");
    table.td();
    FilePathStringBuilder baseFilePath = getRoot(request);
    if (path.length() > 0)
        baseFilePath.append(path);
    File[] files = new File(baseFilePath.toString()).listFiles();
    Arrays.sort(files, new Comparator<File>() {

        @Override
        public int compare(File o1, File o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
        }
    });
    Table table2 = new Table(writer);
    Date date = new Date();
    DateFormat df = DateFormat.getDateTimeInstance();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    for (File file : files) {
        String name = file.getName();
        if (name.charAt(0) != '.' && !name.equals("CVS") && !name.equals("WEB-INF")) {
            table2.tr().td();
            if (file.isDirectory()) {
                writer.setAttribute("style", "color:black;");
                writer.aOnClickOpen("change_dir('" + (path.length() > 0 ? path + "/" + name : name) + "')");
                writer.setAttribute("style", "padding-right:3px;margin-bottom:-2px;");
                writer.img("folder.png");
                writer.write(name);
                writer.tagClose();
            } else if (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".gif") || name.endsWith(".pdf")) {
                writer.setAttribute("style", "color:black;");
                String src = request.getContext();
                if (path.length() > 0)
                    src += "/" + path.replaceAll("\\\\", "/");
                writer.aOnClickOpen("$('file').set('html','<img src=&quot;" + src + "/" + name + "&quot; />')");
                writer.setAttribute("style", "padding-right:3px;margin-bottom:-2px;");
                writer.img("page_white.png");
                writer.write(name);
                writer.tagClose();
            // } else if (name.endsWith(".jsp") || name.endsWith(".htm") || name.endsWith(".html") || name.endsWith(".js") || name.endsWith(".css")) {
            // writer.setAttribute("style", "color:black;");
            // writer.aOnClickOpen("$('file').replace(context+'/FileManager'+(fm_dir==''?'':'/'+fm_dir)+'?action=edit&file=" + name + "')");
            // writer.setAttribute("style", "padding-right:3px;margin-bottom:-2px;");
            // writer.img("page_white.png");
            // writer.write(name);
            // writer.tagClose();
            } else {
                writer.setAttribute("style", "padding-right:3px;margin-bottom:-2px;");
                writer.img("page_white.png");
                writer.write(name);
            }
            date.setTime(file.lastModified());
            long length = file.length();
            writer.setAttribute("style", "padding:0 20px;text-align:right;");
            table2.td(length < 1024 ? Long.toString(length) : length < 1048576 ? nf.format((double) length / 1024) + " k" : length < 1073741824 ? nf.format((double) length / 1048576) + " M" : nf.format((double) length / 1073741824) + " G");
            table2.td(df.format(date));
        }
    }
    table2.close();
    writer.setAttribute("valign", "top");
    writer.setAttribute("id", "file");
    table.td();
    table.close();
}
Also used : HTMLWriter(web.HTMLWriter) Table(web.Table) Date(java.util.Date) DateFormat(java.text.DateFormat) FilePathStringBuilder(web.FilePathStringBuilder) File(java.io.File) NumberFormat(java.text.NumberFormat)

Example 44 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Page method write.

// --------------------------------------------------------------------------
public void write(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    if (m_embed) {
        request.site.newHead(request).close();
        writer.write("<style>html,body{height:100%}</style><div style=\"height:100%;display:flex;flex-direction:column;\">");
        request.site.writePageOpen(m_name, null, request);
        writer.write("<iframe src=\"").write(m_url).write("\" style=\"border-width:0;flex-grow:1;\"></iframe>");
    }
    ResultSet rs = request.db.select("SELECT * FROM pages_items WHERE pages_id=" + m_id + " ORDER BY _order_");
    try {
        while (rs.next()) {
            String type = rs.getString("type");
            if ("html".equals(type))
                writer.write(rs.getString("data"));
            else if ("view".equals(type))
                request.site.newView(rs.getString("data"), request).writeComponent();
        }
    } catch (SQLException e) {
    } finally {
        try {
            rs.getStatement().close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 45 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Pages method writeAdminPane.

// --------------------------------------------------------------------------
@Override
public void writeAdminPane(String[] column_names, boolean show_tasks, boolean show_object, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    Table table = new Table(writer);
    table.tr();
    writer.setAttribute("valign", "top");
    table.td();
    super.writeAdminPane(column_names, show_tasks, show_object, request);
    writer.setAttribute("valign", "top");
    table.td();
    writer.h3("Designs");
    request.site.newView("designs", request).writeComponent();
    writer.setAttribute("valign", "top");
    table.td();
    writer.h3("Pages");
    request.site.newView("pages", request).writeComponent();
    table.close();
}
Also used : HTMLWriter(web.HTMLWriter) Table(web.Table) JDBCTable(db.JDBCTable)

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