Search in sources :

Example 11 with ViewDef

use of db.ViewDef in project common by zenlunatics.

the class Discussions method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals("discussions")) {
        RecordOwnerAccessPolicy record_owner_access_policy = (RecordOwnerAccessPolicy) new RecordOwnerAccessPolicy().add().delete().edit().view();
        return addHooks(new ViewDef(name).setAccessPolicy(record_owner_access_policy).setDefaultOrderBy("_timestamp_ DESC").setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM).setRecordName("Discussion").setTimestampRecords(true).setColumnNamesForm(new String[] { "title", "text", "_owner_" }).setColumnNamesTable(new String[] { "title" }).setColumn(record_owner_access_policy.getColumn("posted by", site)).setColumn(new Column("_timestamp_").setDisplayName("when"))).addRelationshipDef(new OneToMany(name + "_attachments"));
    }
    if (name.equals(m_table + "_attachments")) {
        ViewDef view_def = new ViewDef(name);
        view_def.setRecordName("Attachment");
        view_def.setColumn(new FileColumn("filename", view_def, m_table + "/attachments").setAllowEditing(false).setDirColumn(m_table + "_id").setTitleColumn("filename"));
        return view_def;
    }
    return null;
}
Also used : RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) FileColumn(db.column.FileColumn) JDBCColumn(db.JDBCColumn) Column(db.column.Column) ViewDef(db.ViewDef) OneToMany(db.OneToMany) FileColumn(db.column.FileColumn)

Example 12 with ViewDef

use of db.ViewDef in project common by zenlunatics.

the class ColumnBase method _new_view_def_.

// --------------------------------------------------------------------------
public static ViewDef _new_view_def_(String name) {
    if (name.equals("_columns_")) {
        ViewDef view_def = new ViewDef(name) {

            @Override
            public boolean beforeDelete(StringBuilder where, Request p) {
                p.releaseViewDef(p.db.lookupString(new Select("name").from("_views_").whereIdEquals(p.db.lookupInt(new Select("_views__id").from("_columns_").where(where.toString()), 0))));
                return true;
            }

            @Override
            public boolean beforeInsert(NameValuePairs name_value_pairs, Request p) {
                String table = p.getParameter("db_table");
                if (table != null)
                    name_value_pairs.set("type_args", table + "\t" + p.getParameter("db_column"));
                return true;
            }

            @Override
            public boolean beforeUpdate(int id, NameValuePairs name_value_pairs, Map<String, Object> previous_values, Request p) {
                String table = p.getParameter("db_table");
                if (table != null)
                    name_value_pairs.set("type_args", table + "\t" + p.getParameter("db_column"));
                p.releaseViewDef(p.db.lookupString(new Select("name").from("_views_").whereIdEquals(p.db.lookupInt(new Select("_views__id").from("_columns_").whereIdEquals(id), 0))));
                return true;
            }
        };
        view_def.setAllowQuickEdit(true);
        view_def.setDefaultOrderBy("name");
        List<String> names = DBObject.getFieldNames(ColumnBase.class);
        Collections.sort(names);
        view_def.setColumnNamesForm(names.toArray(new String[names.size()]));
        view_def.setColumnNamesTable(new String[] { "type", "name" });
        view_def.setRecordName("Column");
        view_def.setColumn(new Column("name").setIsRequired(true));
        view_def.setColumn(new Column("type_args").setIsHidden(true));
        return view_def;
    }
    return null;
}
Also used : NameValuePairs(db.NameValuePairs) JDBCColumn(db.JDBCColumn) Request(app.Request) Select(db.Select) ViewDef(db.ViewDef) Map(java.util.Map)

Example 13 with ViewDef

use of db.ViewDef in project common by zenlunatics.

the class Meetings method _newViewDef.

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

            @Override
            public View newView(Request request) {
                View view = new View(this, request);
                if (request.getParameter("db_mode") == View.Mode.EDIT_FORM.toString())
                    if (request.db.lookupInt("_owner_", "meetings", Integer.parseInt(view.getKeyValue()), -1) != request.getUser().getId())
                        view.setColumn(new Column("title").setIsReadOnly(true));
                return view;
            }
        }.addInsertHook(this).addUpdateHook(this).setAccessPolicy(new RecordOwnerAccessPolicy() {

            @Override
            public boolean canUpdateRow(String from, int id, Request request) {
                return true;
            }

            @Override
            public boolean showEditButtonForRow(View view, Request request) {
                return true;
            }
        }.add().delete().edit()).setRecordName("Meeting").setColumnNamesForm(new String[] { "title", "days", "_owner_" }).setColumnNamesTable(new String[] { "title" }).setColumn(new Column("days").setInputRenderer(new MeetingInputRenderer()).setLabelRenderer(new AddButtonLabelRenderer("meeting.addDay()"))).setColumn(new Column("_owner_").setDefaultToUserId().setIsHidden(true)).setColumn(new Column("title").setIsRequired(true)).addRelationshipDef(new OneToManyLink("meeting_people", "people_id"));
        view_def.getViewTheme().setEditText("set times");
        return view_def;
    }
    if (name.equals("meeting_people"))
        return new ViewDef(name).setDialogModes(View.Mode.ADD_FORM).setRecordName("Person").setColumnNamesTable(new String[] { "color", "people_id" }).setColumn(new Column("color").setDisplayName("").setValueRenderer(new MeetingColorRenderer(), false)).setColumn(new Column("days").setInputRenderer(new MeetingInputRenderer()).setLabelRenderer(new AddButtonLabelRenderer("addDay()"))).setColumn(new LookupColumn("people_id", "people", "first,last").setDisplayName("Person"));
    return null;
}
Also used : OneToManyLink(db.OneToManyLink) Request(app.Request) ViewDef(db.ViewDef) View(db.View) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) LookupColumn(db.column.LookupColumn) LookupColumn(db.column.LookupColumn) Column(db.column.Column) AddButtonLabelRenderer(db.AddButtonLabelRenderer)

Example 14 with ViewDef

use of db.ViewDef in project common by zenlunatics.

the class Minutes method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals(m_table))
        return addHooks(new MinutesViewDef(name, m_table, m_access_policy, m_name));
    if (name.equals(m_table + "_attachments")) {
        ViewDef view_def = new ViewDef(name);
        view_def.setRecordName("Attachment");
        view_def.setColumn(new FileColumn("filename", view_def, m_table + "/attachments").setAllowEditing(false).setDirColumn(m_table + "_id").setTitleColumn("filename"));
        return view_def;
    }
    return null;
}
Also used : ViewDef(db.ViewDef) FileColumn(db.column.FileColumn)

Example 15 with ViewDef

use of db.ViewDef in project common by zenlunatics.

the class Admin method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.startsWith("admin__")) {
        String table = name.substring(7);
        ViewDef view_def = new ViewDef(name, table, null) {

            @Override
            public View newView(Request request) {
                if (!request.getUser().isAdministrator())
                    return null;
                return super.newView(request);
            }
        };
        view_def.setAllowQuickEdit(true);
        view_def.setRecordName(table);
        view_def.setShowTableColumnPicker(true, null);
        DBConnection db = new DBConnection(site);
        JDBCTable jdbc_table = db.getTable(table);
        if (jdbc_table.getColumn("_order_") != null)
            view_def.setReorderable(new Reorderable());
        for (String column_name : jdbc_table.getColumnNamesAll()) if (column_name.equals("_owner_"))
            view_def.setColumn(new LookupColumn(column_name, "people", "first,last").setAllowNoSelection(true).setShowFormLink(true));
        else if (column_name.endsWith("_id") && jdbc_table.getColumn(column_name).getType() == Types.INTEGER) {
            String one_table = column_name.substring(0, column_name.length() - 3);
            if (one_table.equals("people"))
                view_def.setColumn(new LookupColumn(column_name, one_table, "first,last").setAllowNoSelection(true).setShowFormLink(true));
            else if (db.getTable(one_table) != null) {
                String[] column_names = db.getTable(one_table).getColumnNames();
                if (column_names.length > 0)
                    view_def.setColumn(new LookupColumn(column_name, one_table, column_names[0]).setAllowNoSelection(true).setShowFormLink(true));
            }
        }
        for (String[] foreign_key : db.getForeignKeys(table)) if (foreign_key[1].equals(table + "_id"))
            view_def.addRelationshipDef(new OneToMany(foreign_key[0]));
        db.close();
        return view_def;
    }
    return null;
}
Also used : DBConnection(db.DBConnection) LookupColumn(db.column.LookupColumn) JDBCTable(db.JDBCTable) Request(app.Request) ViewDef(db.ViewDef) Reorderable(db.Reorderable) OneToMany(db.OneToMany)

Aggregations

ViewDef (db.ViewDef)18 Column (db.column.Column)9 Request (app.Request)8 LookupColumn (db.column.LookupColumn)8 JDBCColumn (db.JDBCColumn)7 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)6 OneToMany (db.OneToMany)5 View (db.View)5 DBConnection (db.DBConnection)4 NameValuePairs (db.NameValuePairs)4 Select (db.Select)4 ArrayList (java.util.ArrayList)4 JDBCTable (db.JDBCTable)3 AccessPolicy (db.access.AccessPolicy)3 RoleAccessPolicy (db.access.RoleAccessPolicy)3 FileColumn (db.column.FileColumn)3 IOException (java.io.IOException)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 FormHook (db.FormHook)2