use of db.column.LookupColumn 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;
}
use of db.column.LookupColumn in project common by zenlunatics.
the class Meetings method _newViewDef.
// ------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals("meetings")) {
ViewDef view_def = new ViewDef(name) {
@Override
public View newView(Request request) {
View view = new View(this, request);
if (request.getParameter("db_mode") == View.Mode.EDIT_FORM.toString())
if (request.db.lookupInt("_owner_", "meetings", Integer.parseInt(view.getKeyValue()), -1) != request.getUser().getId())
view.setColumn(new Column("title").setIsReadOnly(true));
return view;
}
}.addInsertHook(this).addUpdateHook(this).setAccessPolicy(new RecordOwnerAccessPolicy() {
@Override
public boolean canUpdateRow(String from, int id, Request request) {
return true;
}
@Override
public boolean showEditButtonForRow(View view, Request request) {
return true;
}
}.add().delete().edit()).setRecordName("Meeting").setColumnNamesForm(new String[] { "title", "days", "_owner_" }).setColumnNamesTable(new String[] { "title" }).setColumn(new Column("days").setInputRenderer(new MeetingInputRenderer()).setLabelRenderer(new AddButtonLabelRenderer("meeting.addDay()"))).setColumn(new Column("_owner_").setDefaultToUserId().setIsHidden(true)).setColumn(new Column("title").setIsRequired(true)).addRelationshipDef(new OneToManyLink("meeting_people", "people_id"));
view_def.getViewTheme().setEditText("set times");
return view_def;
}
if (name.equals("meeting_people"))
return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM).setRecordName("Person").setColumnNamesTable(new String[] { "color", "people_id" }).setColumn(new Column("color").setDisplayName("").setValueRenderer(new MeetingColorRenderer(), false)).setColumn(new Column("days").setInputRenderer(new MeetingInputRenderer()).setLabelRenderer(new AddButtonLabelRenderer("addDay()"))).setColumn(new LookupColumn("people_id", "people", "first,last").setDisplayName("Person"));
return null;
}
use of db.column.LookupColumn in project common by zenlunatics.
the class Admin method _newViewDef.
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.startsWith("admin__")) {
String table = name.substring(7);
ViewDef view_def = new ViewDef(name, table, null) {
@Override
public View newView(Request request) {
if (!request.getUser().isAdministrator())
return null;
return super.newView(request);
}
};
view_def.setAllowQuickEdit(true);
view_def.setRecordName(table);
view_def.setShowTableColumnPicker(true, null);
DBConnection db = new DBConnection(site);
JDBCTable jdbc_table = db.getTable(table);
if (jdbc_table.getColumn("_order_") != null)
view_def.setReorderable(new Reorderable());
for (String column_name : jdbc_table.getColumnNamesAll()) if (column_name.equals("_owner_"))
view_def.setColumn(new LookupColumn(column_name, "people", "first,last").setAllowNoSelection(true).setShowFormLink(true));
else if (column_name.endsWith("_id") && jdbc_table.getColumn(column_name).getType() == Types.INTEGER) {
String one_table = column_name.substring(0, column_name.length() - 3);
if (one_table.equals("people"))
view_def.setColumn(new LookupColumn(column_name, one_table, "first,last").setAllowNoSelection(true).setShowFormLink(true));
else if (db.getTable(one_table) != null) {
String[] column_names = db.getTable(one_table).getColumnNames();
if (column_names.length > 0)
view_def.setColumn(new LookupColumn(column_name, one_table, column_names[0]).setAllowNoSelection(true).setShowFormLink(true));
}
}
for (String[] foreign_key : db.getForeignKeys(table)) if (foreign_key[1].equals(table + "_id"))
view_def.addRelationshipDef(new OneToMany(foreign_key[0]));
db.close();
return view_def;
}
return null;
}
use of db.column.LookupColumn in project common by zenlunatics.
the class Form method writeBody.
// --------------------------------------------------------------------------
protected void writeBody() throws IOException {
if (m_mode == View.Mode.ADD_FORM && m_relationship != null && m_relationship.def instanceof OneToManyLink) {
m_writer.write("<tr><td>");
LookupColumn column = ((OneToManyLink) m_relationship.def).getManyLookupColumn(m_request);
writeColumnInput(column.getName(), column);
m_writer.write("</td></tr>");
return;
}
if (m_mode == View.Mode.ADD_FORM && m_relationship != null && m_relationship.def instanceof ManyToMany) {
LookupColumn column = ((ManyToMany) m_relationship.def).getManyLookupColumn(m_request);
if (column.hasOptions(m_request.db)) {
writeColumnRow(column.getName(), column);
String[] column_names_form = m_request.db.getTable(((ManyToMany) m_relationship.def).getManyManyTable()).getColumnNames();
for (int i = 2; i < column_names_form.length; i++) writeColumnRow(column_names_form[i], m_view.getColumn(column_names_form[i]));
} else
m_writer.write("No " + m_view_def.getRecordNamePlural() + " available");
return;
}
List<Relationship> relationships = m_view.getRelationships();
List<Relationship> relationships_written = new ArrayList<Relationship>();
for (String column_name : m_view.getColumnNamesForm()) {
boolean is_relationship = false;
for (Relationship relationship : relationships) if (column_name.equals(relationship.def.many_view_def_name)) {
is_relationship = true;
String view_role = relationship.def.getViewRole();
if (view_role == null || m_request.userHasRole(view_role))
relationship.writeManyTableRow(m_view.m_style_base + "formlabel", 1, m_request);
relationships_written.add(relationship);
break;
}
if (!is_relationship)
writeColumnRow(column_name, m_view.getColumn(column_name));
}
if (m_mode != View.Mode.FILTER_FORM)
for (Relationship relationship : relationships) if (relationship.def.showOnForm() && !relationships_written.contains(relationship)) {
String view_role = relationship.def.getViewRole();
if (view_role == null || m_request.userHasRole(view_role))
relationship.writeManyTableRow(m_view.m_style_base + "formlabel", 1, m_request);
}
}
use of db.column.LookupColumn in project common by zenlunatics.
the class ManyToMany method getManyLookupColumn.
// --------------------------------------------------------------------------
public LookupColumn getManyLookupColumn(Request request) {
ViewDef many_view_def = request.site.getViewDef(many_view_def_name, request.db);
ViewDef many_many_view_def = request.site.getViewDef(m_many_many_table, request.db);
String column_name = many_view_def.getFrom() + "_id";
LookupColumn lookup_column = (LookupColumn) many_many_view_def.getColumn(column_name);
if (lookup_column == null) {
lookup_column = new LookupColumn(column_name, many_view_def.getFrom(), m_many_lookup_display_column_name, new Select("id," + m_many_lookup_display_column_name).distinctOn(m_many_lookup_display_column_name).from(many_view_def.getFrom()).orderBy(m_many_lookup_display_column_name), m_many_lookup_display_column_name);
lookup_column.setDisplayName(many_view_def.getRecordName().toLowerCase());
if (m_mode != null)
lookup_column.setMode(m_mode);
many_many_view_def.setColumn(lookup_column);
}
return lookup_column;
}
Aggregations