Search in sources :

Example 6 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Documents method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals("documents")) {
        ViewDef view_def = new ViewDef(name);
        view_def.setAccessPolicy(new RoleAccessPolicy("docs").add().delete().edit());
        view_def.setCenter(false);
        view_def.setDefaultOrderBy("title");
        view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM);
        view_def.setRecordName("Document");
        view_def.setRichTextEditId("db_filename_text");
        view_def.setShowDoneLink(true);
        view_def.setTimestampRecords(true);
        ArrayList<String> column_names = new ArrayList<String>();
        column_names.add("title");
        column_names.add("type");
        column_names.add("filename");
        if (m_extra_columns != null)
            for (JDBCColumn column : m_extra_columns) column_names.add(column.name);
        view_def.setColumnNamesForm(column_names.toArray(new String[column_names.size()]));
        view_def.setColumnNamesTable(new String[] { "filename" });
        FileColumn file_column = new FileColumn("filename", view_def, "documents").setTitleColumn("title");
        if (m_dir_column != null)
            file_column.setDirColumn(m_dir_column);
        view_def.setColumn(file_column.setDisplayName("document").setPrintUrl("/Documents?db_key_value="));
        view_def.setColumn(new Column("title").setIsRequired(true).setOrderBy("lower(title)"));
        view_def.setColumn(((Options) site.getObjects("documents_types")).newColumn("type"));
        return addHooks(view_def);
    }
    if (name.equals("documents_types"))
        return site.getObjects(name).newViewDef(name, site).setRecordName("Type").setShowNumRecords(false).setColumn(new Column("text").setIsRequired(true));
    return null;
}
Also used : FileColumn(db.column.FileColumn) JDBCColumn(db.JDBCColumn) Column(db.column.Column) ArrayList(java.util.ArrayList) JDBCColumn(db.JDBCColumn) ViewDef(db.ViewDef) RoleAccessPolicy(db.access.RoleAccessPolicy) FileColumn(db.column.FileColumn)

Example 7 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Minutes method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("date", Types.DATE)).add(new JDBCColumn("summary", Types.VARCHAR)).add(new JDBCColumn("text", Types.VARCHAR)).add(new JDBCColumn("_timestamp_", Types.TIMESTAMP)).add(new JDBCColumn("_owner_", "people"));
    for (JDBCColumn column : m_columns) table_def.add(column);
    addColumns(table_def);
    db.getTable(m_table, true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    db.createManyTable(m_table, m_table + "_attachments", "filename VARCHAR");
    m_site.addModule(new Comments(m_table, m_site, db), db);
}
Also used : JDBCTable(db.JDBCTable) Comments(social.Comments) JDBCColumn(db.JDBCColumn)

Example 8 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Pictures method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals(m_table)) {
        ViewDef view_def = new ViewDef(name) {

            @Override
            public View newView(Request p) {
                return new PicturesView(this, m_where, p);
            }

            @Override
            public void afterInsert(NameValuePairs name_value_pairs, int row_id, Request request) {
                ViewState.setFilter(m_name, null, request);
                super.afterInsert(name_value_pairs, row_id, request);
            }
        };
        view_def.setAccessPolicy(new RecordOwnerAccessPolicy().add().delete().edit());
        view_def.setCenter(false);
        view_def.setDefaultOrderBy("_timestamp_ DESC");
        view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM);
        view_def.setOnDelete("document.location=document.location");
        view_def.setOnSuccessAfter("XHR_post(context+'/db','db_cmd=clear_filter&db_view_def=pictures',function(){var p=$('c_pictures');if(p)p.replace();}.bind(this))");
        view_def.setRecordName("Picture");
        view_def.setRowWindowSize(25);
        view_def.setTimestampRecords(true);
        ArrayList<String> columns = new ArrayList<String>();
        columns.add("file");
        columns.add("caption");
        columns.add("tags");
        for (JDBCColumn column : m_additional_columns) columns.add(column.name);
        view_def.setColumnNamesForm(columns.toArray(new String[columns.size()]));
        view_def.setColumnNamesFormTable(new String[] { "caption" });
        PictureColumn picture_column = new PictureColumn("file", view_def, m_table, m_thumb_size, 1024).setSizeIsMaxSide(false);
        if (m_base_file_path != null)
            picture_column.setBaseFilePath(m_base_file_path);
        view_def.setColumn(picture_column.setGenerateFileNames(true).setIsRequired(true));
        view_def.setColumn(new TagsColumn("tags", "pictures", view_def));
        view_def.setColumn(new LookupColumn("_owner_", "people", "first,last").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=_owner_=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');Gallery.close();})"));
        view_def.addRelationshipDef(new ManyToMany(m_table + "_tags", m_table + "_" + m_table + "_tags", "tag").setManyTableColumn("tag").setShowOnForm(false));
        view_def.getViewTheme().setDeleteImg("delete.png").setEditImg("pencil.png");
        return addHooks(view_def);
    }
    if (name.equals(m_table + " add"))
        return _newViewDef(m_table, site).setFrom(m_table).setName(m_table + " add").setOnSuccessAfter(null);
    if (name.equals(m_table + " owners"))
        return new ViewDef(name).setAccessPolicy(new AccessPolicy()).setFrom(m_table + " JOIN people ON people.id=" + m_table + "._owner_").setDefaultOrderBy("first,last").setShowColumnHeads(false).setShowHead(false).setCenter(false).setColumnNamesTable(new String[] { "_owner_" }).setColumn(new Column("_owner_").setValueRenderer(new LinkValueRenderer().setHrefColumn("_owner_").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=_owner_=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');})").setValueRenderer(new MultiColumnRenderer(new String[] { "first", "last" }, true, false)), false));
    if (// for nav list
    name.equals(m_table + " tags"))
        return new ViewDef(name) {

            @Override
            public View newView(Request request) {
                return super.newView(request).setSelectDistinct(true, "tag");
            }
        }.setAccessPolicy(new AccessPolicy()).setDefaultOrderBy("lower(tag)").setFrom(m_table + "_tags").setRecordName("Tag").setShowColumnHeads(false).setShowHead(false).setCenter(false).setColumnNamesTable(new String[] { "tag" }).setColumn(new Column("tag").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=pictures_tags_id=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');})").setTextColumn("tag"), false));
    if (name.equals(m_table + "_tags"))
        return new ViewDef(name).setDefaultOrderBy("lower(tag)").setRecordName("Tag").setColumn(new Column("tag").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=pictures_tags_id=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');Gallery.close();})").setTextColumn("tag"), false));
    return null;
}
Also used : LinkValueRenderer(db.LinkValueRenderer) NameValuePairs(db.NameValuePairs) Request(app.Request) ArrayList(java.util.ArrayList) ManyToMany(db.ManyToMany) JDBCColumn(db.JDBCColumn) ViewDef(db.ViewDef) AccessPolicy(db.access.AccessPolicy) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) LookupColumn(db.column.LookupColumn) JDBCColumn(db.JDBCColumn) LookupColumn(db.column.LookupColumn) PictureColumn(db.column.PictureColumn) Column(db.column.Column) PictureColumn(db.column.PictureColumn) MultiColumnRenderer(db.column.MultiColumnRenderer)

Example 9 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class News method rebuild.

// --------------------------------------------------------------------------
@AdminTask
public void rebuild(String provider_name, Request request) throws IOException {
    NewsProvider provider = getProvider(provider_name);
    if (provider == null) {
        request.writer.write("provider " + provider_name + " not found");
        return;
    }
    request.db.delete("news", "provider='" + provider_name + "'");
    try {
        ResultSet rs = request.db.select(new Select("*").from(provider.getTable()));
        NameValuePairs name_value_pairs = new NameValuePairs();
        while (rs.next()) {
            name_value_pairs.clear();
            name_value_pairs.set("provider", provider_name);
            name_value_pairs.set("item_id", rs.getInt("id"));
            name_value_pairs.set("_owner_", rs.getInt("_owner_"));
            String timestamp = rs.getString("_timestamp_");
            name_value_pairs.set("_timestamp_", timestamp);
            name_value_pairs.set("last_update", timestamp);
            for (JDBCColumn column : provider.m_duplicate_columns) name_value_pairs.set(column.name, rs.getString(column.name));
            request.db.insert("news", name_value_pairs);
        }
        rs.getStatement().close();
    } catch (SQLException e) {
        request.abort(e);
    }
}
Also used : NameValuePairs(db.NameValuePairs) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Select(db.Select) JDBCColumn(db.JDBCColumn) AdminTask(web.AdminTask)

Example 10 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class SiteMenu method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable jdbc_table = new JDBCTable().add(new JDBCColumn("name", Types.VARCHAR, 30)).add(new JDBCColumn("_order_", Types.INTEGER));
    db.getTable("menu").dropExtraColumns(jdbc_table, db).createMissingColumns(jdbc_table, db);
    jdbc_table = new JDBCTable().add(new JDBCColumn("people")).add(new JDBCColumn("name", Types.VARCHAR, 30)).add(new JDBCColumn("_order_", Types.INTEGER));
    db.getTable("menu_items").dropExtraColumns(jdbc_table, db).createMissingColumns(jdbc_table, db);
    m_menu = new DBObjects<MenuItem>(new Select("*").from("menu").orderBy("_order_"), MenuItem.class, m_site);
    // so that the UpdateHook calls get called on reorder
    m_site.addObjects(m_menu);
    Pages pages = (Pages) m_site.getModule("Pages");
    pages.add(new Page("Other", "Other"), db);
    ViewDef view_def = m_site.getViewDef("pages", db);
    view_def.addDeleteHook(this).addUpdateHook(this);
}
Also used : Pages(app.Pages) JDBCTable(db.JDBCTable) Select(db.Select) JDBCColumn(db.JDBCColumn) Page(app.Page) ViewDef(db.ViewDef)

Aggregations

JDBCColumn (db.JDBCColumn)20 JDBCTable (db.JDBCTable)14 Select (db.Select)5 HTMLWriter (web.HTMLWriter)4 Page (app.Page)3 Request (app.Request)3 ViewDef (db.ViewDef)3 NameValuePairs (db.NameValuePairs)2 Options (db.Options)2 RoleAccessPolicy (db.access.RoleAccessPolicy)2 Column (db.column.Column)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Pages (app.Pages)1 LinkValueRenderer (db.LinkValueRenderer)1 ManyToMany (db.ManyToMany)1 AccessPolicy (db.access.AccessPolicy)1 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)1 FileColumn (db.column.FileColumn)1