CallBackery

 view release on metacpan or  search on metacpan

lib/CallBackery/GuiPlugin/Users.pm  view on Meta::CPAN

    my $self = shift;
    my $admin = ( not $self->user or $self->user->may('admin'));
    return [
        {
            label => trm('UserId'),
            type => 'number',
            width => '1*',
            key => 'cbuser_id',
            sortable => true,
            primary => true,
        },
        {
            label => trm('Username'),
            type => 'string',
            width => '3*',
            key => 'cbuser_login',
            sortable => true,
        },
        {
            label => trm('Given Name'),
            type => 'string',
            width => '4*',
            key => 'cbuser_given',
            sortable => true,
        },
        {
            label => trm('Family Name'),
            type => 'string',
            width => '4*',
            key => 'cbuser_family',
            sortable => true,
        },
        {
            label => trm('Rights'),
            type => 'string',
            sortable => false,
            width => '8*',
            key => 'cbuser_cbrights',
        },
        $admin ? ({
            label => trm('Note'),
            type => 'string',
            width => '8*',
            key => 'cbuser_note',
        }):(),
     ]
};

=head2 actionCfg

=cut

has actionCfg => sub {
    my $self = shift;
    # we must be in admin mode if no user property is set to have be able to prototype all forms variants
    my $admin = ( not $self->user or $self->user->may('admin'));
    return [
        $admin ? ({
            label => trm('Add User'),
            action => 'popup',
            addToContextMenu => true,
            key => 'add',
            popupTitle => trm('New User'),
            backend => {
                plugin => 'UserForm',
                config => {
                    type => 'add'
                }
            }
        }) : (),
        {
            label => trm('Edit User'),
            action => 'popup',
            addToContextMenu => true,
            defaultAction => true,
            key => 'edit',
            popupTitle => trm('Edit User'),
            actionHandler => sub {
                my $self = shift;
                my $args = shift;
                my $id = $args->{selection}{cbuser_id};
                die mkerror(393,trm('You have to select a user first'))
                    if not $id;
            },
            set => {
                height => 340,
                width => 500
            },
            backend => {
                plugin => 'UserForm',
                config => {
                    type => 'edit'
                }
            }
        },
        $admin ? ({
            label => trm('Delete User'),
            action => 'submitVerify',
            addToContextMenu => true,
            question => trm('Do you really want to delete the selected user ?'),
            key => 'delete',
            actionHandler => sub {
                my $self = shift;
                my $args = shift;
                my $id = $args->{selection}{cbuser_id};
                die mkerror(4992,trm("You have to select a user first"))
                    if not $id;
                die mkerror(4993,trm("You can not delete the user you are logged in with"))
                    if $id == $self->user->userId;
                my $db = $self->user->db;

                if ($db->deleteData('cbuser',$id) == 1){
                    return {
                         action => 'reload',
                    };
                }
                die mkerror(4993,trm("Faild to remove user %1",$id));
            }
        }) : (),
    ];
};

=head1 METHODS

All the methods of L<CallBackery::GuiPlugin::AbstractForm> plus:

=cut


sub currentUserFilter {
    my $self = shift;
    if (not $self->user->may('admin')){
        return 'WHERE cbuser_id = ' . $self->user->mojoSqlDb->dbh->quote($self->user->userId);
    }
    return '';
}

sub getTableRowCount {
    my $self = shift;
    my $args = shift;
    my $db = $self->user->mojoSqlDb;
    if ($self->user->may('admin')){
        return [$db->dbh->selectrow_array('SELECT count(cbuser_id) FROM '
            . $db->dbh->quote_identifier('cbuser'))]->[0];
    }
    return 1;
}

sub getTableData {
    my $self = shift;
    my $args = shift;
    my $db = $self->user->mojoSqlDb;
    my $SORT ='';
    if ($args->{sortColumn}){
        $SORT = 'ORDER BY '.$db->dbh->quote_identifier($args->{sortColumn});
        $SORT .= $args->{sortDesc} ? ' DESC' : ' ASC';
    }
    my $WHERE = '';
    if (not $self->user->may('admin')){



( run in 1.096 second using v1.01-cache-2.11-cpan-39bf76dae61 )