use of db.SectionDef in project common by zenlunatics.
the class Admin method columnAdd.
static void columnAdd(Request request) {
String column = request.getParameter("column");
String table = request.getParameter("table");
String reftable = request.getParameter("reftable");
request.db.addColumn(table, column, request.getParameter("type"), request.getParameter("size"), reftable == null || reftable.length() == 0 ? null : request.getParameter("reftable"));
request.releaseViewDef(table);
if (column.equals("_order_")) {
ViewDef view_def = request.site.getViewDef(table, request.db);
SectionDef section_def = view_def.getSectionDef();
String section_value = null;
ResultSet rs;
if (section_def != null)
rs = request.db.select("SELECT id," + section_def.columnName() + " FROM " + table + " ORDER BY " + section_def.columnName() + "," + view_def.getDefaultOrderBy());
else
rs = request.db.select("SELECT id FROM " + table + " ORDER BY " + view_def.getDefaultOrderBy());
int order = 1;
try {
while (rs.next()) {
if (section_def != null) {
String value = section_def.getValue(rs, request);
if (section_value == null || !section_value.equals(value)) {
section_value = value;
order = 1;
}
}
request.db.update(table, "_order_=" + order++, rs.getInt(1));
}
rs.getStatement().close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
use of db.SectionDef in project common by zenlunatics.
the class ToDos method _newViewDef.
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals("todos")) {
ViewDef view_def = new ViewDef(name);
view_def.setDefaultOrderBy("task");
view_def.setRecordName("Task");
ArrayList<String> column_names_form = new ArrayList<String>();
column_names_form.add("task");
column_names_form.add("notes");
if (m_group_by_project) {
column_names_form.add("project");
view_def.setColumn(new Column("project").setPostText("(optional)"));
view_def.setSectionDef(new SectionDef("project", Type.SEPARATOR_ROWS, new OrderBy("project")));
}
if (m_prioritize) {
view_def.setDefaultOrderBy("priority");
column_names_form.add("priority");
view_def.setColumn(new Column("priority").setInputRenderer(new SelectRenderer(new String[] { "1 - high", "2 - medium", "3 - low" })));
}
if (m_assign_tasks) {
column_names_form.add("assigned_to");
view_def.setColumn(new LookupColumn("assigned_to", "people", "first,last").setFilter(this).setDefaultToUserId());
}
if (m_one_table != null) {
column_names_form.add(m_one_table + "_id");
view_def.setColumn(new Column(m_one_table + "_id").setDefaultToSessionAttribute().setIsHidden(true));
}
view_def.setColumnNamesForm(column_names_form.toArray(new String[column_names_form.size()]));
view_def.setColumnNamesTable(new String[] { "task" });
view_def.setColumn(new Column("task") {
@Override
public boolean writeValue(View view, Map<String, Object> data, Request p) throws IOException {
String notes = view.data().getString("notes");
if (notes.length() > 0)
p.writer.write("<div onmouseover=\"if(!this.f){var e=$(this.lastChild);this.f=new Fx.Slide(e,{link:'cancel'});this.f.hide();e.setStyle('display','');$(this).addEvent('mouseout',function(e){if(!this.isAncestor(e.relatedTarget))this.f.slideOut()}.bind(this))}this.f.slideIn()\">");
p.writer.write(view.data().getString("task"));
if (notes.length() > 0) {
p.writer.write("<div style=\"background-color:white;padding:5px;font-size:smaller;display:none\">");
view.writeColumnHTML("notes");
p.writer.write("</div></div>");
}
return true;
}
});
return view_def;
}
return null;
}
Aggregations