Solstice::SortService - Create the Solstice::Buttons necessary for managing a sortable table.


Solstice documentation  | view source Contained in the Solstice distribution.

Index


NAME

Top

Solstice::SortService - Create the Solstice::Buttons necessary for managing a sortable table.

SYNOPSIS

Top



    #takes three arguments - a preference service in which to store the data, and
    #the key names for the field and direction preference
    my $sort_service = Solstice::SortService->new($pref_service, "sort_field_preference_name", "sort_dir_preference_name");

    #flush may be necessary if used in a controller, as many controller functions run twice per click
    $sort_service->flush();




    #add the fields to sort on.
    $sort_service->addSortField({
            label       => $lang_service->getString('tool_header'),
            button_name => 'tool_sort_button',
            sort_func   => sub {
                lc $a->getApplicationName() cmp lc $b->getApplicationName() ||
                lc $a->getImplementationName() cmp lc $b->getImplementationName()
            },
            action      => 'sort',
            default     => 1,
        });

    $sort_service->addSortField({
            label       => $lang_service->getString('tool_project'),
            button_name => 'project_sort_button',
            action      => 'sort',
            sort_func   => sub {
                lc $a->getImplementationName() cmp lc $b->getImplementationName()
            },
            rev_sort_func    => sub {
                #some optional reverse sort function - otherwise the order
                #given by sort_func is just reversed
            },
        });




    #make use of the sort method
    my $iterator = $list->iterator();
    $iterator->sort($sort_service->getSortMethod());




    #in the view, create the service (with the same params!) and put the auto-created buttons into
    #the param hash
    my $sort_service = Solstice::SortService->new($pref_service, "sort_field_preference_name", "sort_dir_preference_name");

    return {
        %params,
        $self->processChildViews(),
        $sort_service->getSortLinks(),
    }




DESCRIPTION

Top

Export

None by default.

Methods

new()
sortDateTime($datetime_a, $datetime_b)

Generic datetime object sorting method. Handles the case where either datetime object is undefined.

AUTHOR

Top

Catalyst Research & Development Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 191 $

COPYRIGHT

Top


Solstice documentation  | view source Contained in the Solstice distribution.