use of db.NameValuePairs in project common by zenlunatics.
the class Comments method doPost.
// --------------------------------------------------------------------------
@Override
public boolean doPost(Request request) throws IOException {
if (super.doPost(request))
return true;
String action = request.getPathSegment(-1);
if ("add".equals(action)) {
NameValuePairs name_value_pairs = new NameValuePairs();
int item_id = request.getInt("item_id", 0);
name_value_pairs.set(m_items_table + "_id", item_id);
name_value_pairs.set("comment", request.getParameter("comment"));
name_value_pairs.set("_owner_", request.getUser().getId());
int id = request.db.insert(m_name, name_value_pairs);
if (m_provider != null) {
m_provider.updateNewsItem(item_id, false, name_value_pairs, request);
m_provider.commentAdded(id);
}
return true;
}
if ("delete".equals(action)) {
deleteItem(request.getPathSegmentInt(-2), request);
return true;
}
if ("update".equals(action)) {
NameValuePairs name_value_pairs = new NameValuePairs();
name_value_pairs.set("comment", request.getParameter("comment"));
name_value_pairs.set_timestamp_();
int id = request.getPathSegmentInt(-2);
request.db.update(m_name, name_value_pairs, id);
int item_id = request.db.lookupInt(new Select(m_items_table + "_id").from(m_name).whereIdEquals(id), 0);
if (m_provider != null)
m_provider.updateNewsItem(item_id, false, name_value_pairs, request);
return true;
}
return false;
}
use of db.NameValuePairs in project common by zenlunatics.
the class MailList method archive.
// --------------------------------------------------------------------------
int archive(String name, String subject, String text, DBConnection db) {
if (!m_archive)
return 0;
NameValuePairs name_value_pairs = new NameValuePairs();
name_value_pairs.set("sender", name);
if (subject != null)
name_value_pairs.set("subject", subject);
if (!m_store_on_disk)
name_value_pairs.set("message", "From \n" + text);
name_value_pairs.setDateTime("arrived", m_site.newCalendar());
int id = db.insert("ml_" + m_id, name_value_pairs);
if (m_store_on_disk)
storeMessage(text, id);
return id;
}
use of db.NameValuePairs 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 db.NameValuePairs in project common by zenlunatics.
the class NewsFeed method doPost.
// --------------------------------------------------------------------------
@Override
public boolean doPost(Request request) throws IOException {
if (super.doPost(request))
return true;
String action = request.getPathSegment(-1);
if ("add".equals(action)) {
NameValuePairs name_value_pairs = new NameValuePairs();
name_value_pairs.set("text", request.getParameter("text"));
name_value_pairs.set("_owner_", request.getUser().getId());
name_value_pairs.set_timestamp_();
setDuplicateColumnDefaults(name_value_pairs);
int id = request.db.insert(m_table, name_value_pairs);
addNewsItem(id, name_value_pairs, request);
return true;
}
if ("update".equals(action)) {
NameValuePairs name_value_pairs = new NameValuePairs();
name_value_pairs.set("text", request.getParameter("text"));
name_value_pairs.set_timestamp_();
int id = request.getPathSegmentInt(-2);
request.db.update(m_table, name_value_pairs, id);
updateNewsItem(id, true, name_value_pairs, request);
return true;
}
return false;
}
use of db.NameValuePairs in project common by zenlunatics.
the class NewsProvider method updateNewsItem.
// --------------------------------------------------------------------------
protected void updateNewsItem(int item_id, boolean update_timestamp, NameValuePairs name_value_pairs, Request request) {
if (request.db.exists("news", "provider='" + m_name + "' AND item_id=" + item_id)) {
NameValuePairs nvp = new NameValuePairs();
String timestamp = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a").format(new java.util.Date());
if (update_timestamp)
nvp.set("_timestamp_", timestamp);
nvp.set("last_update", timestamp);
duplicateColumns(name_value_pairs, nvp);
request.db.update("news", nvp, "provider='" + m_name + "' AND item_id=" + item_id);
}
}
Aggregations