use of db.DBObjects in project common by zenlunatics.
the class MenuItemsViewDef method newView.
// --------------------------------------------------------------------------
@SuppressWarnings("unchecked")
@Override
public View newView(Request request) {
DBObjects<MenuItem> user_menu_items = (DBObjects<MenuItem>) request.getSessionAttribute("menu_items");
if (user_menu_items.getObjects().size() == 0) {
user_menu_items.copyObjects(((SiteMenu) request.site.getModule("SiteMenu")).getMenu());
List<MenuItem> menu_items = user_menu_items.getObjects();
NameValuePairs nvp = new NameValuePairs();
nvp.set("people_id", request.getUser().getId());
for (int i = 0; i < menu_items.size(); i++) {
nvp.set("_order_", i + 1);
nvp.set("name", menu_items.get(i).name);
request.db.insert("menu_items", nvp);
}
}
ViewState.setBaseFilter("menu_items", "people_id=" + request.getUser().getId(), request);
return super.newView(request);
}
use of db.DBObjects in project common by zenlunatics.
the class SiteMenu method write.
// --------------------------------------------------------------------------
public void write(String current_page, Request request) throws IOException {
String context = request.getContext();
NavBar nav_bar = new NavBar(request.writer).setActiveItem(current_page).setStaticTop(true);
@SuppressWarnings("unchecked") DBObjects<MenuItem> user_pages = (DBObjects<MenuItem>) request.getSessionAttribute("menu_items");
if (user_pages == null && request.getUser() != null) {
user_pages = new DBObjects<MenuItem>(new Select("name").from("menu_items").where("people_id=" + request.getUser().getId()).orderBy("_order_"), MenuItem.class, request.site);
request.setSessionAttribute("menu_items", user_pages);
}
List<MenuItem> menu_items = null;
if (user_pages != null)
menu_items = user_pages.getObjects();
if (menu_items == null || menu_items.size() == 0)
menu_items = m_menu.getObjects();
if (m_home_page != null && request.userHasRole("coho")) {
String label = request.site.getSettings().getString("home");
if (label == null)
label = "Home";
nav_bar.setBrand(label, context + "/" + m_home_page);
}
nav_bar.open();
Pages pages = request.site.getPages();
for (MenuItem menu_item : menu_items) {
Page page = pages.getPageByName(menu_item.name);
if (page != null)
if ("Other".equals(page.getURL())) {
boolean first = true;
for (Page p : pages.getPages()) if (p.onMainMenu() && !menu_items.contains(p) && p.canView(request)) {
if (first) {
nav_bar.dropdownOpen(page.getName());
first = false;
}
p.a(nav_bar, request);
}
if (!first)
nav_bar.dropdownClose();
} else if (page.canView(request))
page.a(nav_bar, request);
}
nav_bar.ulOpen(true);
if (request.userHasRole("coho")) {
String label = request.site.getSettings().getString("help");
if (label == null)
label = "Help";
nav_bar.a(label, context + "/Help");
}
request.site.writeUserDropdown(nav_bar, request);
nav_bar.close();
Person user = request.getUser();
if (user != null)
request.setSessionAttribute("current page", current_page);
}
use of db.DBObjects in project common by zenlunatics.
the class Admin method writeAccordion.
// --------------------------------------------------------------------------
private void writeAccordion(Request request) throws IOException {
Accordion accordion = new Accordion(request.writer);
accordion.open();
Collection<Module> modules_list = request.site.getModules();
accordion.heading("modules");
// accordion.aOnClick("- add module -", "new_tab('Add Module','get_add_module_form')");
for (Module module : modules_list) if (module.showOnAdminPage())
accordion.aOnClick(module.getName(), "new_tab('" + HTMLWriter.escapeJSString(module.getName()) + "','get_module&module=" + HTMLWriter.escapeJSString(module.getName()) + "')");
Collection<DBObjects<?>> objects_list = request.site.getAllObjects();
if (objects_list.size() > 0) {
accordion.heading("objects");
for (DBObjects<?> objects : objects_list) accordion.aOnClick(objects.getName(), "new_tab('" + HTMLWriter.escapeJSString(objects.getName()) + "','get_object&object=" + HTMLWriter.escapeJSString(objects.getName()) + "')");
}
accordion.heading("tables");
accordion.aOnClick("- create table -", "new_tab('Create Table','get_table_create_form')");
accordion.aOnClick("- create many to many link table -", "new_tab('Create Many To Many Link Table','get_many_to_many_link_table_create_form')");
String[] tables = request.db.getTableNames(false);
if (tables != null)
for (String table : tables) accordion.aOnClick(table, "new_tab('" + table + "','get_table&table=" + table + "')");
accordion.heading("table defs");
accordion.aOnClick("- create table def -", "create_table_def()");
View table_defs = request.site.newView("_tables_", request);
table_defs.select();
if (table_defs.data().isBeforeFirst()) {
table_defs.setColumn(new Column("name").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setTextColumn("name").setOnClick("new_tab('<%name%>','get_table_def&db_key_value=", "')"), false));
writeRows(accordion, table_defs, new String[] { "name" }, request.writer);
}
accordion.heading("views");
accordion.aOnClick("- create view -", "create_view()");
View views = request.site.newView("_views_", request);
views.select();
if (views.data().isBeforeFirst()) {
views.setColumn(new Column("name").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setTextColumn("name").setOnClick("new_tab('<%name%>','get_view&db_key_value=", "')"), false));
writeRows(accordion, views, new String[] { "name" }, request.writer);
}
writeAccordionItems(accordion, request.site.getDisplayName(), request.site.getClass());
Class<?>[] classes = request.site.getClasses();
if (classes != null)
for (Class<?> c : classes) writeAccordionItems(accordion, c.getSimpleName() + " tasks", c);
String display = request.getParameter("display");
if (display != null)
if (Character.isDigit(display.charAt(0)))
accordion.setActiveGroup(Integer.parseInt(display));
else
accordion.setActiveGroup(display);
accordion.close();
}
Aggregations