use of db.Reorderable in project common by zenlunatics.
the class Surveys method _newViewDef.
// ----------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.startsWith("survey_answers"))
return newAnswersViewDef(name, site);
if (name.equals("survey_questions")) {
ViewDef view_def = new ViewDef(name) {
@Override
public int insert(NameValuePairs name_value_pairs, Request request) {
combineValues(name_value_pairs);
int id = super.insert(name_value_pairs, request);
String answer_table = "survey_answers" + name_value_pairs.getString("surveys_id");
if (request.db.tableExists(answer_table)) {
addAnswerTableColumn(answer_table, Integer.toString(id), name_value_pairs.getString("answer_type"), name_value_pairs.getString("type_data"), request.db);
request.releaseViewDef(answer_table);
}
return id;
}
@Override
public void update(int id, NameValuePairs name_value_pairs, Request request) {
request.releaseViewDef("survey_answers" + request.db.lookupString("surveys_id", "survey_questions", id));
combineValues(name_value_pairs);
super.update(id, name_value_pairs, request);
}
};
view_def.addFormHook(new FormHook() {
@Override
public void after(View view, View.Mode mode, boolean printer_friendly, Request p) throws IOException {
p.writer.js("update_answer_type();");
}
});
view_def.setReorderable(new Reorderable());
view_def.setRecordName("Question");
view_def.setColumnNamesForm(new String[] { "answer_type", "question", "pre_text", "post_text", "required" });
view_def.setColumnNamesTable(new String[] { "answer_type", "question", "required" });
view_def.setColumn(new Column("answer_type").setInputAndValueRenderers(new AnswerTypeRenderer(), false));
view_def.setColumn(new Column("pre_text").setDisplayName("text before input"));
view_def.setColumn(new Column("post_text").setDisplayName("text after input"));
view_def.setColumn(new Column("question").setDisplayName("question text"));
return view_def;
}
if (name.equals("surveys"))
return new ViewDef(name).setAccessPolicy(new RecordOwnerAccessPolicy().add().delete().edit()).setDefaultOrderBy("title").setRecordName(m_record_name).setColumnNamesForm(new String[] { "title", "description", "number_questions", "one_answer", "show_answers", "show_names", "show_title" }).setColumnNamesTable(new String[] { "title" }).setColumn(new BooleanColumn("number_questions", true)).setColumn(new BooleanColumn("one_answer", true).setDisplayName("one answer per participant")).setColumn(new BooleanColumn("show_answers", true).setDisplayName("allow participants to see each other's answers").setValueRenderer(new LinkValueRenderer().setNamesAndValuesColumns(new String[] { "view" }, new String[] { "id" }).setShowIfSetColumn("show_answers").setText("view answers"), false)).setColumn(new BooleanColumn("show_names", true).setDisplayName("show participant's names with their answers")).setColumn(new BooleanColumn("show_title", true)).setColumn(new Column("take").setValueRenderer(new LinkValueRenderer().setNamesAndValuesColumns(new String[] { "take" }, new String[] { "id" }).setText("answer questions"), false)).setColumn(new Column("title").setIsRequired(true)).addRelationshipDef(new OneToMany("survey_questions"));
return null;
}
use of db.Reorderable 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;
}
Aggregations