use of db.ViewState in project common by zenlunatics.
the class ReminderWhenColumn method writeInput.
// --------------------------------------------------------------------------
@Override
protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
HTMLWriter writer = request.writer;
boolean can_repeat = m_always_can_repeat;
if (m_events_can_repeat && !can_repeat) {
int one_id;
if (mode == Mode.ADD_FORM) {
ViewState state = (ViewState) request.getState(ViewState.class, m_event_provider_name);
one_id = Integer.parseInt(state.key_value);
} else
one_id = view.data().getInt(m_event_table + "_id");
String repeat = request.db.lookupString(new db.Select("repeat").from(m_event_table).whereIdEquals(one_id));
can_repeat = repeat != null && !repeat.equals("never");
}
int num = 0;
if (mode != Mode.ADD_FORM)
num = view.data().getInt("num");
boolean on_the_day = mode == Mode.ADD_FORM || "day".equals(view.data().getString("unit")) && num == 0;
String id = UUID.randomUUID().toString();
writer.setAttribute("id", id);
writer.select("num", (String[]) null, null).space();
if (m_events_have_time)
new Select("unit", num == 1 ? new String[] { "day", "hour", "minute", "week" } : new String[] { "days", "hours", "minutes", "weeks" }, new String[] { "day", "hour", "minute", "week" }).setSelectedOption(null, mode == Mode.ADD_FORM ? "day" : view.data().getString("unit")).write(request);
else
new Select("unit", num == 1 ? new String[] { "day", "week" } : new String[] { "days", "weeks" }, new String[] { "day", "week" }).setSelectedOption(null, mode == Mode.ADD_FORM ? "day" : view.data().getString("unit")).write(request);
writer.space();
String on_the_day_label = can_repeat ? "on the day of" : "on the day";
new Select("before", new String[] { on_the_day_label, "before", "after" }, new String[] { on_the_day_label, "true", "false" }).setSelectedOption(on_the_day ? on_the_day_label : mode == Mode.ADD_FORM ? "before" : view.data().getBoolean("before") ? "before" : "after", null).write(request);
if (can_repeat)
writer.space().select("repeat_days", new String[] { "each event", "first event", "last event" }, mode == Mode.ADD_FORM ? "each event" : view.data().getString("repeat_days"));
writer.js("new ReminderWhen('" + id + "'," + (mode == Mode.ADD_FORM ? 0 : view.data().getInt("num")) + ");");
}
Aggregations