use of app.Request 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 app.Request in project common by zenlunatics.
the class MailLists method _newViewDef.
// --------------------------------------------------------------------------
// @AdminTask
// public static void
// moveAllMessagesToDisk(Request request)
// {
// try {
// List<String> lists = request.db.readValues(new Select("name").from("mail_lists").where("NOT store_on_disk"));
// for (String list : lists) {
// request.writer.write("writing " + list + "<br />");
// System.out.println("writing " + list);
// new MailList(list, request.site, request.db).moveMessagesToDisk(request);
// }
// } catch (IOException e) {
// request.abort(e);
// }
// }
// --------------------------------------------------------------------------
// @AdminTask({"list name"})
// public static void
// moveMessagesToDisk(String list_name, Request request)
// {
// try {
// new MailList(list_name, request.site, request.db).moveMessagesToDisk(request);
// } catch (IOException e) {
// request.abort(e);
// }
// }
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals("additional_emails"))
return new ViewDef(name).setDefaultOrderBy("email").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setRecordName("Additional email");
if (name.equals("mail_lists"))
return new ViewDef(name) {
@Override
public boolean beforeUpdate(int id, NameValuePairs name_value_pairs, Map<String, Object> previous_values, Request request) {
if (!name_value_pairs.getBoolean("active") && request.db.lookupBoolean(new Select("active").from("mail_lists").whereIdEquals(id)))
request.db.delete("mail_lists_people", "mail_lists_id=" + id);
return super.beforeUpdate(id, name_value_pairs, previous_values, request);
}
}.addDeleteHook(this).addInsertHook(this).addUpdateHook(this).setDefaultOrderBy("name").setRecordName("Mail List").setColumnNamesForm(new String[] { "name", "send_to", "active", "announce_only", "archive", "archives_public", "footer", "allow_from_outside", "allow_from_outside_subscribers", "subscribers", "username", "host", "password", "store_on_disk" }).setColumnNamesFormTable(new String[] { "name" }).setColumnNamesTable(new String[] { "name", "send_to", "active" }).setColumn(new Column("allow_from_outside").setDisplayName("accept posts from outside non-subscribers (i.e. anyone)")).setColumn(new Column("allow_from_outside_subscribers").setDisplayName("accept posts from outside subscribers")).setColumn(new Column("announce_only").setTitle("If this is checked, replies to posts from this list will be ignored.")).setColumn(new Column("footer").setTitle("Optional text that will be added to the bottom of every post to this list")).setColumn(new Column("host").setIsHidden(true)).setColumn(new Column("name").setPostText("@" + site.getDomain()).setDisplayName("address").setIsRequired(true)).setColumn(new Column("password").setDefaultToUUID().setIsHidden(true)).setColumn(new Column("send_to") {
@Override
protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
String value = null;
if (mode == Mode.EDIT_FORM)
value = view.data().getString("send_to");
HTMLWriter writer = request.writer;
writer.write("<select name=\"send_to\"><option value=\"Subscribers\">Subscribers</options>");
for (MailHandlerFactory mail_handler_factory : m_mail_handler_factories) mail_handler_factory.writeSendToOptions(value, request.db, writer);
writer.write("</select>");
}
@Override
public boolean writeValue(View view, Map<String, Object> data, Request request) throws IOException {
String send_to = view.data().getString("send_to");
if ("Subscribers".equals(send_to))
request.writer.write(send_to);
else {
MailHandler mail_handler = getMailHandler(view.data().getString("name"), request.db);
if (mail_handler != null)
request.writer.write(mail_handler.getDisplayName());
}
return true;
}
}).setColumn(new Column("store_on_disk").setIsHidden(true)).setColumn(new Column("username").setIsHidden(true)).addRelationshipDef(new ManyToMany("people", "mail_lists_people", "first,last").setViewRole("administrator")).addRelationshipDef(new OneToMany("subscribers").setSpanFormCols(false));
if (name.equals("mail_lists_people"))
return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setColumn(new LookupColumn("mail_lists_id", "mail_lists", "name", new Select("id,name,send_to,active").from("mail_lists").orderBy("name"), "name").setFilter(new Filter() {
@Override
public boolean accept(ResultSet rs, Request request) {
try {
return rs.getBoolean("active") && "Subscribers".equals(rs.getString("send_to"));
} catch (SQLException e) {
request.abort(e);
}
return false;
}
}).setDisplayName("mail list")).setColumn(new LookupColumn("people_id", "people", "first,last").setFilter(site.getPeopleFilter()));
if (name.startsWith("ml_"))
return new ViewDef(name).setAccessPolicy(new RoleAccessPolicy("admin").delete()).setDefaultOrderBy("arrived DESC").setRecordName("Message").setRowWindowSize(0).setShowFilterLink(false).setShowHead(false).setColumnNamesTable(new String[] { "arrived", "sender", "subject" }).setColumn(new Column("subject") {
@Override
public boolean writeValue(View view, Map<String, Object> data, Request request) throws IOException {
String subject = view.data().getString("subject");
if (subject == null || subject.length() == 0)
subject = "(no subject)";
request.writer.aOnClick(subject, "new Dialog({url:context+'/MailLists?list=" + view.getViewDef().getName() + "&cmd=get_message&db_key_value=" + view.data().getString("id") + "',title:'" + HTMLWriter.escapeJSString(subject) + "'});");
return true;
}
});
if (name.equals("people mail_lists"))
return new ViewDef(name).setAccessPolicy(new AccessPolicy().add().delete()).setAddButtonText("subscribe").setDeleteButtonText("unsubscribe").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setFrom("mail_lists").setRecordName("Mail List").setColumnNamesTable(new String[] { "name" });
if (name.equals("subscribers"))
return new ViewDef(name).setDefaultOrderBy("email").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setRecordName("Outside Subscriber");
return null;
}
use of app.Request 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 app.Request in project common by zenlunatics.
the class Documents method init.
// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
JDBCTable table_def = new JDBCTable().add(new JDBCColumn("filename", Types.VARCHAR, 60)).add(new JDBCColumn("title", Types.VARCHAR, 60)).add(new JDBCColumn("type", Types.VARCHAR)).add(new JDBCColumn("url", Types.BOOLEAN)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP));
if (m_extra_columns != null)
for (JDBCColumn column : m_extra_columns) table_def.add(column);
addColumns(table_def);
db.getTable("documents", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
db.createTable("documents_types", "text VARCHAR");
m_site.addObjects(new Options(new Select("text").from("documents_types").orderBy("text"), true, m_site).setAllowEditing(true));
Roles.add("docs", m_site, db);
m_site.addUserDropdownItem(new Page("Edit Documents", m_site) {
@Override
public void write(Request request) throws IOException {
request.site.writePageOpen("Edit Documents", request);
request.site.newView("edit documents", request).writeComponent();
request.writer.br();
request.close();
}
}.setRole("docs"), db);
}
use of app.Request in project common by zenlunatics.
the class ColumnBase method _new_view_def_.
// --------------------------------------------------------------------------
public static ViewDef _new_view_def_(String name) {
if (name.equals("_columns_")) {
ViewDef view_def = new ViewDef(name) {
@Override
public boolean beforeDelete(StringBuilder where, Request p) {
p.releaseViewDef(p.db.lookupString(new Select("name").from("_views_").whereIdEquals(p.db.lookupInt(new Select("_views__id").from("_columns_").where(where.toString()), 0))));
return true;
}
@Override
public boolean beforeInsert(NameValuePairs name_value_pairs, Request p) {
String table = p.getParameter("db_table");
if (table != null)
name_value_pairs.set("type_args", table + "\t" + p.getParameter("db_column"));
return true;
}
@Override
public boolean beforeUpdate(int id, NameValuePairs name_value_pairs, Map<String, Object> previous_values, Request p) {
String table = p.getParameter("db_table");
if (table != null)
name_value_pairs.set("type_args", table + "\t" + p.getParameter("db_column"));
p.releaseViewDef(p.db.lookupString(new Select("name").from("_views_").whereIdEquals(p.db.lookupInt(new Select("_views__id").from("_columns_").whereIdEquals(id), 0))));
return true;
}
};
view_def.setAllowQuickEdit(true);
view_def.setDefaultOrderBy("name");
List<String> names = DBObject.getFieldNames(ColumnBase.class);
Collections.sort(names);
view_def.setColumnNamesForm(names.toArray(new String[names.size()]));
view_def.setColumnNamesTable(new String[] { "type", "name" });
view_def.setRecordName("Column");
view_def.setColumn(new Column("name").setIsRequired(true));
view_def.setColumn(new Column("type_args").setIsHidden(true));
return view_def;
}
return null;
}
Aggregations