use of db.column.BooleanColumn 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;
}
Aggregations