use of db.access.AccessPolicy in project common by zenlunatics.
the class View method writeTable.
// --------------------------------------------------------------------------
public void writeTable(boolean sort_links, boolean show_find) 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);
if (m_printer_friendly)
m_writer.setAttribute("border", "1");
writeTableOpen();
if (m_view_def.showColumnHeads() && m_row_template == null && m_view_def.getRowTemplate() == null && m_mode != Mode.READ_ONLY_LIST)
writeColumnHeadsRow(sort_links);
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) {
int mark = writeSpanRowOpen("info");
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;
}
}
writeRow(columns);
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);
}
writeTableClose(columns);
}
use of db.access.AccessPolicy in project common by zenlunatics.
the class SelectRenderer method writeInput.
// --------------------------------------------------------------------------
@Override
public boolean writeInput(View view, Form form, ColumnBase<?> column, View.Mode mode, String default_value, Request request) throws IOException {
String name = column.getName();
Select select;
if (m_options != null) {
select = new Select(name, m_options).setType(m_type);
if (mode == View.Mode.ADD_FORM)
select.setSelectedOption(null, default_value);
else if (mode != View.Mode.FILTER_FORM) {
Iterator<? extends SelectOption> i = m_options.iterator();
if (i.hasNext())
if (i.next().getValue() == null)
select.setSelectedOption(view.data().getString(name), null);
else
select.setSelectedOption(null, view.data().getString(name));
}
} else if (m_query != null) {
select = new RowsSelect(name, m_query.toString(), m_option_column, m_value_col, request).setType(m_type);
if (m_filter != null)
((RowsSelect) select).setFilter(m_filter);
if (m_option_renderer != null)
((RowsSelect) select).setOptionRenderer(m_option_renderer);
if (mode == View.Mode.ADD_FORM)
select.setSelectedOption(null, default_value);
else if (mode != View.Mode.FILTER_FORM)
select.setSelectedOption(null, view.data().getString(name));
} else {
select = new Select(name, m_options_texts, m_option_values).setType(m_type);
if (mode == View.Mode.ADD_FORM)
select.setSelectedOption(default_value, null);
else if (mode == View.Mode.EDIT_FORM)
if (m_option_values == null)
select.setSelectedOption(view.data().getString(name), null);
else
select.setSelectedOption(null, view.data().getString(name));
}
HTMLWriter writer = request.writer;
if (m_is_required) {
select.setIsRequired(true);
writer.setAttribute("required", "yes");
writer.setAttribute("title", column.getDisplayName(false));
}
if (m_first_option_text != null)
select.addFirstOption(m_first_option_text, m_first_option_value);
if (m_allow_no_selection || mode == View.Mode.FILTER_FORM)
select.setAllowNoSelection(true);
if (m_on_change != null)
select.setOnChange(m_on_change);
select.write(request);
if (m_edit_view_def != null && mode != View.Mode.FILTER_FORM) {
AccessPolicy access_policy = request.site.getViewDef(m_edit_view_def, request.db).getAccessPolicy();
if (access_policy == null || access_policy.showEditButtons(view, request)) {
writer.space();
StringBuilder options = new StringBuilder("column:'");
options.append(column.getName());
options.append("',db_view_def:'");
options.append(view.getViewDef().getName());
options.append('\'');
if (mode == View.Mode.EDIT_FORM) {
options.append(",db_key_value:");
options.append(view.data().getString("id"));
}
String title = "Edit " + request.site.getViewDef(m_query.getFirstTable(), request.db).getRecordNamePlural();
writer.setAttribute("style", "vertical-align:baseline;");
writer.setAttribute("title", title);
writer.buttonIconOnClick("pencil", "new Dialog({title:'" + HTMLWriter.escapeJSString(title) + "',width:'auto',url:context+'/Views/" + m_edit_view_def + "/component'," + options.toString() + "})");
}
}
return true;
}
Aggregations