Search in sources :

Example 1 with JSONWriter

use of web.JSONWriter in project common by zenlunatics.

the class View method writeJSON.

// --------------------------------------------------------------------------
private void writeJSON() throws IOException {
    if (m_data == null) {
        select();
        if (!next())
            return;
    }
    if (!skip())
        return;
    if (0 == m_data.getRow())
        return;
    AccessPolicy access_policy = m_view_def.getAccessPolicy();
    String[] columns = getColumnNamesTable();
    SectionDef section_def = m_view_def.getSectionDef();
    if (section_def != null)
        if (m_previous_section_value == null && section_def.type() != SectionDef.Type.SEPARATOR_ROWS)
            m_previous_section_value = section_def.getValue(this, m_request);
    initTotals(columns);
    JSONWriter w = new JSONWriter(m_writer.getWriter());
    w.startObject();
    w.write("columns", getColumnNamesTable());
    w.startPair("rows");
    w.startArray();
    // writeColumnHeadsRow(m_view_def.allowSorting());
    do {
        if (access_policy != null && !access_policy.showRow(this, m_request))
            continue;
        if (section_def != null) {
            String s = section_def.getValue(this, m_request);
            if (!s.equals(m_previous_section_value)) {
                if (section_def.type() == SectionDef.Type.SEPARATOR_ROWS && m_totals != null && m_previous_section_value != null)
                    writeTotalsRow("Total", m_totals);
                m_previous_section_value = s;
                if (section_def.type() == SectionDef.Type.SEPARATOR_ROWS) {
                    // "info");
                    int mark = writeSpanRowOpen(null);
                    m_writer.write("<a name=\"").write(s).write("\" style=\"text-decoration:none\"></a>").write(s);
                    if (section_def.firstCharOnly()) {
                        m_writer.setAttribute("id", "fc");
                        m_writer.tag("span", null);
                        m_first_characters.add(s);
                    }
                    m_writer.tagsCloseTo(mark);
                } else
                    break;
            }
        }
        w.startArray();
        w.write(m_data.getString("id"));
        for (int i = 0; i < columns.length; i++) {
            ColumnBase<?> column = getColumn(columns[i]);
            if (!canViewColumn(column))
                continue;
            if (column != null && column.total())
                m_totals[i] += column.getDouble(this, m_request);
            w.write(getColumnHTML(columns[i]));
        }
        w.endArray();
        if (m_show_related_rows_depth_zero)
            writeRelationsTableRows(m_style_base + "formlabel", 0);
        ++m_num_rows;
        if (isRowWindowLast())
            break;
        if (m_grouping_column == null)
            next();
    } while (!m_data.isAfterLast());
    if (m_totals != null) {
        writeTotalsRow("Total", m_totals);
        if (m_num_totals_written > 1 && m_view_def.showGrandTotals())
            writeTotalsRow("Grand Total", m_grand_totals);
    }
    w.endArray();
    w.endPair();
    w.endObject();
}
Also used : JSONWriter(web.JSONWriter) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) AccessPolicy(db.access.AccessPolicy)

Aggregations

AccessPolicy (db.access.AccessPolicy)1 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)1 JSONWriter (web.JSONWriter)1