Search in sources :

Example 26 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class RatingInputRenderer method writeInput.

// ----------------------------------------------------------------------
@Override
public boolean writeInput(View view, Form form, ColumnBase<?> column, View.Mode mode, String defaultValue, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.write(m_low_text);
    writer.nbsp();
    for (int i = m_low; i <= m_high; i++) {
        String num = Integer.toString(i);
        writer.radioButtonInline(column.getName(), num, num, false, null);
    }
    writer.nbsp();
    writer.write(m_high_text);
    return true;
}
Also used : HTMLWriter(web.HTMLWriter)

Example 27 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Survey method writeCSV.

// ----------------------------------------------------------------------
public void writeCSV(Request request) throws IOException {
    request.response.setContentType("text/csv");
    try {
        ArrayList<Integer> question_ids = new ArrayList<Integer>();
        ResultSet questions = request.db.select("SELECT id,answer_type FROM survey_questions WHERE surveys_id=" + m_id + " ORDER BY _order_");
        while (questions.next()) {
            String type = questions.getString(2);
            if (type.equals("Divider") || type.equals("HTML") || type.equals("Page Break"))
                continue;
            question_ids.add(new Integer(questions.getInt(1)));
        }
        questions.getStatement().close();
        ResultSet answers = request.db.select("SELECT * FROM survey_answers" + m_id);
        JDBCTable answer_table = request.db.getTable("survey_answers" + m_id);
        HTMLWriter writer = request.writer;
        while (answers.next()) {
            boolean first = true;
            for (int i : question_ids) {
                if (first)
                    first = false;
                else
                    writer.write(',');
                String column_name = "a" + i;
                if (answer_table.getColumn(column_name).isNumber())
                    writer.write(answers.getInt(column_name));
                else {
                    String answer = answers.getString(column_name);
                    if (answer != null) {
                        writer.write('"');
                        writer.write(Util.escapeDoubleQuotes(answer));
                        writer.write('"');
                    }
                }
            }
            writer.write('\n');
        }
        answers.getStatement().close();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) SQLException(java.sql.SQLException) JDBCTable(db.JDBCTable) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 28 with HTMLWriter

use of web.HTMLWriter 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 29 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class CalendarView method writeHead.

// --------------------------------------------------------------------------
private void writeHead(Request request) throws IOException {
    CalendarPicker calendar_picker = m_event_provider.getCalendarPicker();
    if (calendar_picker != null || allowViewSwitching() || !(this instanceof ListView)) {
        HTMLWriter writer = request.writer;
        writer.write("<div style=\"margin-bottom:20px;text-align:center;\">");
        if (calendar_picker != null)
            calendar_picker.write(request);
        if (allowViewSwitching()) {
            writer.write("<div id=\"calendar_view_switcher\" style=\"float:right;\" class=\"btn-group\" data-active=0>");
            writer.setAttribute("class", "btn btn-default active");
            writer.aOnClick("month", "$('calendar').calendar.set_view(0)");
            writer.setAttribute("class", "btn btn-default");
            writer.aOnClick("week", "$('calendar').calendar.set_view(1)");
            writer.setAttribute("class", "btn btn-default");
            writer.aOnClick("day", "$('calendar').calendar.set_view(2)");
            writer.setAttribute("class", "btn btn-default");
            writer.aOnClick("list", "$('calendar').calendar.set_view(3)");
            writer.write("</div>");
        }
        if (!(this instanceof ListView)) {
            writer.write("<div id=\"calendar_nav\">");
            writer.write("<h1 style=\"display:inline;margin:0 20px;vertical-align:middle;\"></h1>");
            writer.write("<div class=\"btn-group\" style=\"margin-right:10px;vertical-align:middle;\">");
            writer.buttonIconOnClick("arrow-left", "$('calendar').calendar.move(-1)");
            writer.buttonIconOnClick("arrow-right", "$('calendar').calendar.move(1)");
            writer.write("</div>");
            writer.setAttribute("id", "calendar_today");
            writer.setAttribute("style", "vertical-align:middle;");
            writer.aButtonOnClick("today", "$('calendar').calendar.today()");
            writer.write("</div>");
        }
        writer.write("</div>");
    }
}
Also used : HTMLWriter(web.HTMLWriter)

Example 30 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class DaysView method write.

// --------------------------------------------------------------------------
@Override
public void write(int year, int month, int date, String category, String location, Request request) throws IOException {
    java.util.Calendar from = request.site.newCalendar();
    from.set(year, month, date);
    java.util.Calendar today = request.site.newCalendar();
    java.util.Calendar to;
    HTMLWriter writer = request.writer;
    if (m_num_days != 1)
        from.add(java.util.Calendar.DATE, -(from.get(java.util.Calendar.DAY_OF_WEEK) - 1));
    to = (java.util.Calendar) from.clone();
    to.add(java.util.Calendar.DATE, m_num_days);
    TreeSet<Event> events = new TreeSet<Event>();
    m_event_provider.addCalendarsEvents(events, from, to, category, location, request);
    List<List<Event>> days_events = new ArrayList<List<Event>>();
    boolean has_all_day_events = false;
    if (events.size() > 0) {
        for (int i = 0; i < m_num_days; i++) {
            List<Event> event_list = new ArrayList<Event>();
            has_all_day_events |= gather(from, to, events, event_list);
            days_events.add(event_list);
            from.add(java.util.Calendar.DATE, 1);
        }
        from.add(java.util.Calendar.DATE, -m_num_days);
    }
    writer.setAttribute("style", "margin:0 auto;");
    int mark = writer.tagOpen("table");
    writer.write("<tr><td>");
    if (events.size() > 0) {
        int[] start_end = getMinuteBounds(events, from, to);
        int height = start_end[1] - start_end[0];
        Table table = new Table(writer).addClass("days_view");
        if (m_num_days != 1) {
            SimpleDateFormat df = new SimpleDateFormat("EEEEE d");
            table.td("&nbsp;");
            for (int i = 0; i < m_num_days; i++) {
                writer.setAttribute("style", "text-align:center");
                table.td();
                writer.aOnClickOpen("$('calendar').calendar.go(" + from.get(Calendar.YEAR) + "," + from.get(Calendar.MONTH) + "," + from.get(Calendar.DATE) + ",'DAY')");
                writer.write(df.format(from.getTime()));
                writer.tagClose();
                from.add(java.util.Calendar.DATE, 1);
            }
            from.add(java.util.Calendar.DATE, -m_num_days);
        }
        if (has_all_day_events) {
            table.tr();
            writer.setAttribute("style", "text-align:right;padding-right:5px;");
            table.td("all day");
            for (List<Event> day_events : days_events) {
                writer.setAttribute("valign", "top");
                writer.setAttribute("class", Util.dateCompare(from, today) == 0 ? "all_day today" : "all_day");
                table.td();
                writeAllDayEvents(from, day_events, request);
                from.add(java.util.Calendar.DATE, 1);
            }
            from.add(java.util.Calendar.DATE, -m_num_days);
        }
        table.tr();
        writer.setAttribute("valign", "top");
        table.td();
        writeTimes(start_end[0], start_end[1], height, request);
        for (List<Event> day_events : days_events) {
            writer.setAttribute("valign", "top");
            table.td();
            writeDayEvents(from, day_events, start_end[0], start_end[1], height, m_num_days == 1 ? 300 : 150, /*m_state.splitByLocation() ? new ArrayList<String>(locations) :*/
            null, Util.dateCompare(from, today) == 0, request);
            from.add(java.util.Calendar.DATE, 1);
        }
        table.close();
    }
    writer.write("</td></tr>");
    writer.tagsCloseTo(mark);
}
Also used : HTMLWriter(web.HTMLWriter) Table(web.Table) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) TreeSet(java.util.TreeSet) List(java.util.List) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat)

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