use of db.View in project common by zenlunatics.
the class FileColumn method writeInput.
// --------------------------------------------------------------------------
@Override
public void writeInput(String default_value, boolean printer_friendly, View view, Form form, Request request) throws IOException {
View.Mode mode = view.getMode();
String dir_column_value = getDirColumnValue(view, mode);
HTMLWriter writer = request.writer;
writer.write("<span>");
String filename = null;
if (mode != View.Mode.ADD_FORM)
filename = view.data().getString(m_name);
if (mode == View.Mode.ADD_FORM || filename.length() == 0)
if (m_allow_choosing || m_allow_editing) {
writer.write("action: ");
writeActionSelect(view.getViewDef(), mode, dir_column_value, request);
writer.write("<div style=\"height:5px;\"></div>");
} else {
if (m_is_required) {
writer.setAttribute("required", "yes");
writer.setAttribute("title", getDisplayName(false));
}
writer.fileInput(m_name);
}
else if (mode == View.Mode.EDIT_FORM && Util.fileIsViewable(filename)) {
writer.hiddenInput(m_name, filename);
if (m_dir_column != null)
writer.hiddenInput(m_dir_column, dir_column_value);
writer.setAttribute("id", "db_" + m_name + "_text");
writer.textAreaOpen("db_" + m_name + "_text", "5", "80");
List<String> a = Util.readFile(getDirectory(dir_column_value, request.site).toString() + "/" + filename);
for (int i = 0; i < a.size(); i++) {
if (i > 0)
writer.write('\n');
writer.write(WriterBase.encode(a.get(i)));
}
writer.tagClose();
writer.js("rich_text('db_" + m_name + "_text');");
} else if (view.getMode() == View.Mode.EDIT_FORM) {
view.writeColumnHTML(m_name);
writeReplaceLink(view, this, mode, writer);
if (m_dir_column != null && mode == View.Mode.EDIT_FORM)
writer.hiddenInput(m_dir_column, dir_column_value);
}
if (m_post_text != null) {
writer.space();
writer.write(m_post_text);
}
writer.write("</span>");
}
use of db.View 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.View in project common by zenlunatics.
the class EventProvider method _newViewDef.
// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
if (name.equals(m_name)) {
ViewDef view_def = new EventViewDef(m_name, m_support_registrations);
view_def.addFormHook(new FormHook() {
@Override
public void after(View view, View.Mode mode, boolean printer_friendly, Request request) throws IOException {
writeAutomaticReminders(view, request);
}
});
if (m_access_policy != null)
view_def.setAccessPolicy(m_access_policy);
view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM);
view_def.setFrom(m_events_table);
view_def.setRecordName("Event");
ArrayList<String> column_names_form = new ArrayList<String>();
DBConnection db = new DBConnection(site);
for (int i = 0; i < m_filter_columns.size(); i += 2) {
column_names_form.add(m_filter_columns.get(i));
view_def.setColumn(new Column(m_filter_columns.get(i)).setDefaultValue(m_filter_columns.get(i + 1)).setIsHidden(true));
}
db.close();
column_names_form.add("date");
view_def.setColumn(new Column("date").setDisplayName(m_start_date_label).setIsRequired(true));
if (m_events_have_start_time) {
column_names_form.add("start_time");
column_names_form.add("end_time");
}
if (m_events_have_event) {
column_names_form.add("event");
view_def.setColumn(new Column("event").setIsRequired(true));
}
column_names_form.add("notes");
if (m_events_can_repeat) {
column_names_form.add("repeat");
view_def.setColumn(new Column("repeat").setInputAndValueRenderers(new SelectRenderer(s_repeat_periods).setOnChange("var i=this.selectedIndex;var d=document.querySelector('#date_row input');var ed=document.querySelector('#end_date_row input');if(i==0)ed.value='';else if(i==1){if(ed.value=='')ed.value=d.value;}else if(ed.value==d.value)ed.value='';$('end_date_row').style.display=i==0?'none':null;return false"), true));
column_names_form.add("end_date");
view_def.setColumn(new Column("end_date").setDisplayName(m_end_date_label));
}
if (m_events_have_category) {
column_names_form.add(m_events_table + "_categories_id");
m_categories.setAllowEditing(!m_only_admins_can_edit_categories);
view_def.setColumn(m_categories.newColumn(m_events_table + "_categories_id").setDisplayName("category"));
}
if (m_events_have_location) {
String locations_table = getLocationsTable();
column_names_form.add(locations_table + "_id");
m_locations.setAllowEditing(!m_only_admins_can_edit_locations);
view_def.setColumn(m_locations.newColumn(locations_table + "_id").setDisplayName("location"));
}
if (m_events_have_color) {
column_names_form.add("color");
view_def.setColumn(new ColorColumn("color"));
}
if (m_support_reminders)
view_def.addRelationshipDef(new OneToMany(m_name + "_reminders").setSpanFormCols(false));
if (m_support_registrations) {
column_names_form.add("register_people");
view_def.setColumn(new Column("register_people").setDisplayName("allow people to register for this " + getEventCrumb()));
}
if (m_events_are_owned) {
if (m_access_policy == null)
view_def.setAccessPolicy(new Or(new RecordOwnerAccessPolicy().add().delete().edit(), new RoleAccessPolicy("calendar editor")));
column_names_form.add("_owner_");
LookupColumn owner_column = new PersonColumn("_owner_", false, site.getPeopleFilter()).setDefaultToUserId().setDisplayName("posted by");
if (m_role == null)
owner_column.setIsReadOnly(true);
view_def.setColumn(owner_column);
}
column_names_form.add("_timestamp_");
view_def.setColumn(new Column("_timestamp_").setDisplayName("added").setIsReadOnly(true).setShowOnAddForm(false));
view_def.setColumnNamesForm(column_names_form.toArray(new String[column_names_form.size()]));
return view_def;
}
if (name.equals(getCategoriesTable()))
return m_categories.addHooks(new ViewDef(name).setColumn(new ColorColumn("color")));
if (name.equals(getLocationsTable()))
return m_locations.newViewDef(name, site).setDefaultOrderBy("lower(text)").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setRecordName("Location").setColumn(new Column("text").setDisplayName("location").setIsRequired(true));
if (name.equals(m_name + "_registrations"))
return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setFrom(m_events_table + "_registrations").setRecordName("Registration").setColumnNamesTableAndForm(new String[] { "person", "note" }).setColumn(new LookupColumn("person", "people", "first,last").setDefaultToUserId().setFilter(site.getPeopleFilter()));
if (name.equals(m_name + "_reminders")) {
RecordOwnerAccessPolicy access_policy = (RecordOwnerAccessPolicy) new RecordOwnerAccessPolicy().add().delete().edit();
return new ViewDef(name).setAccessPolicy(access_policy).setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setFrom(m_events_table + "_reminders").setRecordName("Reminder").setColumnNamesForm(new String[] { "before", "note", "email" }).setColumnNamesTable(new String[] { "email", "before" }).setColumn(new EmailColumn("email") {
@Override
public String getDefaultValue(Request request) {
return request.getUser().getEmail();
}
@Override
public String validate(String table, String value, int id, Request request) {
if ("poster".equals(value))
return null;
return super.validate(table, value, id, request);
}
}.setDisplayName("send to").setIsRequired(true)).setColumn(new ReminderWhenColumn("before", m_name, m_events_table, m_events_have_start_time, m_events_can_repeat, false).setDisplayName("when")).setColumn(access_policy.getColumn("person", site));
}
if (name.equals(m_name + "_reminders auto"))
return new ViewDef(name).setBaseFilter(m_events_table + "_id IS NULL").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM).setFrom(m_events_table + "_reminders").setRecordName("Reminder").setColumnNamesForm(new String[] { "before", "note", "email" }).setColumnNamesTable(new String[] { "email", "before" }).setColumn(new EmailColumn("email") {
@Override
public String validate(String table, String value, int id, Request request) {
if ("poster".equals(value))
return null;
return super.validate(table, value, id, request);
}
}.setDisplayName("send to").setIsRequired(true).setTitle("Enter the special value \"poster\" to send to the event poster")).setColumn(new ReminderWhenColumn("before", m_name, m_events_table, m_events_have_start_time, m_events_can_repeat, true).setDisplayName("when"));
return null;
}
use of db.View in project common by zenlunatics.
the class EventProvider method doGet.
// //--------------------------------------------------------------------------
//
// @AdminTask({"table","date"})
// public static void
// deleteEventsBefore(String events_table, String date, Request request)
// {
// boolean supports_repeat = request.db.getTable(events_table).getColumn("repeat") != null;
//
// StringBuilder where = new StringBuilder();
// if (supports_repeat)
// where.append("(repeat='never' AND ");
// where.append("date<'");
// where.append(date);
// where.append("'");
// if (supports_repeat) {
// where.append(") OR (repeat<>'never' AND ");
// where.append("end_date<'");
// where.append(date);
// where.append("')");
// }
//
// request.db.delete(events_table, where.toString());
// }
// --------------------------------------------------------------------------
@Override
public boolean doGet(Request request) throws IOException {
View.Mode mode = request.getEnum("db_mode", View.Mode.class);
if (mode != null && mode != View.Mode.LIST) {
writeEventForm(request);
return true;
}
if (request.getPathSegment(2) == null) {
String segment_one = request.getPathSegment(1);
if ("after_view".equals(segment_one)) {
writeAfterView(request);
return true;
}
if ("filters".equals(segment_one)) {
writeFilters(request);
return true;
}
}
if ("public".equals(request.getPathSegment(1))) {
String theme = ((Themes) request.site.getModule("Themes")).getTheme(request);
new Head(request, request.site.getDisplayName()).styleSheet("/themes/" + theme + "/" + theme).close();
LocalDate now = request.site.newLocalDate();
new MonthView(this, request).write(now.getYear(), now.getMonthValue() - 1, now.getDayOfMonth(), request.getParameter("category"), request.getParameter("location"), request);
return true;
}
int year = request.getPathSegmentInt(1);
int month = request.getPathSegmentInt(2);
int date = request.getPathSegmentInt(3);
CalendarView.View view = request.getPathSegmentEnum(4, CalendarView.View.class);
CalendarView calendar_view;
if (view == CalendarView.View.LIST)
calendar_view = new ListView(this, request);
else if (view == CalendarView.View.DAY)
calendar_view = new DaysView(this, 1, request);
else if (view == CalendarView.View.WEEK)
calendar_view = new DaysView(this, 7, request);
else
calendar_view = new MonthView(this, request);
calendar_view.write(year, month, date, request.getParameter("category"), request.getParameter("location"), request);
return true;
}
use of db.View in project common by zenlunatics.
the class EventViewDef method newView.
// --------------------------------------------------------------------------
@Override
public View newView(Request request) {
View view = super.newView(request);
String id = view.getKeyValue();
if (m_support_registrations && view.getMode() != View.Mode.ADD_FORM && id != null && request.db.lookupBoolean(new Select("register_people").from(m_from).whereIdEquals(id)))
view.addRelationship(new OneToMany(m_name + "_registrations"));
return view;
}
Aggregations