Search in sources :

Example 6 with RecordOwnerAccessPolicy

use of db.access.RecordOwnerAccessPolicy 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)

Aggregations

ViewDef (db.ViewDef)6 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)6 Column (db.column.Column)6 LookupColumn (db.column.LookupColumn)5 Request (app.Request)4 JDBCColumn (db.JDBCColumn)3 OneToMany (db.OneToMany)3 View (db.View)3 DBConnection (db.DBConnection)2 FormHook (db.FormHook)2 LinkValueRenderer (db.LinkValueRenderer)2 NameValuePairs (db.NameValuePairs)2 AccessPolicy (db.access.AccessPolicy)2 BooleanColumn (db.column.BooleanColumn)2 TextAreaColumn (db.column.TextAreaColumn)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PersonColumn (app.PersonColumn)1 AddButtonLabelRenderer (db.AddButtonLabelRenderer)1 ManyToMany (db.ManyToMany)1