David Schmidt > CatalystX-Resource-0.003_002 > CatalystX::Resource::TraitFor::Controller::Resource::Sortable

Download:
CatalystX-Resource-0.003_002.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.003_002   Source   Latest Release: CatalystX-Resource-0.010001

NAME ^

CatalystX::Resource::TraitFor::Controller::Resource::Sortable - makes your resource sortable

VERSION ^

version 0.003_002

SYNOPSIS ^

    # TestApp.pm
    'Controller::Resource::Artist' => {
        resultset_key => 'artists_rs',
        resources_key => 'artists',
        resource_key => 'artist',
        form_class => 'TestApp::Form::Resource::Artist',
        model => 'DB::Resource::Artist',
        redirect_mode => 'list',
        traits => ['Sortable'],
        actions => {
            base => {
                PathPart => 'artists',
            },
        },
    },

    # TestApp/Schema/Result/Resource/Artist.pm
    __PACKAGE__->load_components(qw/ Ordered Core /);
    __PACKAGE__->table('artist');
    __PACKAGE__->add_columns(
        ...,
        'position',
        {
            data_type => 'integer',
            is_numeric => 1,
            is_nullable => 0,
        },
    );

    __PACKAGE__->resultset_attributes({ order_by => 'position' });
    __PACKAGE__->position_column('position');

DESCRIPTION ^

adds these paths to your Controller which call move_previous/move_next on your resource item as provided by DBIx::Class::Ordered

Make sure the schema for your sortable resource has a 'position' column.

    /resource/*/move_previous
    /resource/*/move_next

For nested resources you need to set a grouping_column Example: Artist has_many Albums has_many Songs

    # TestApp/Schema/Result/Resource/Song.pm
    __PACKAGE__->grouping_column('album_id');

After a move operation you will always be redirected to the referer If no referer header is foudn you'll be redirected to '/'

ACTIONS ^

move_next

    will switch the resource with the next one

move_previous

    will switch the resource with the previous one

move_to

    move resource to denoted position

AUTHOR ^

David Schmidt <davewood@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2011 by David Schmidt.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: