Mojolicious-Command-Author-generate-automake_app

 view release on metacpan or  search on metacpan

lib/Mojolicious/Command/Author/generate/callbackery_app/lib/App/GuiPlugin/Song.pm  view on Meta::CPAN

        },
        {
            label => trm('Composer'),
            type => 'string',
            width => '2*',
            key => 'song_composer',
            sortable => true,
        },
        {
            label => trm('Page'),
            type => 'number',
            width => '1*',
            key => 'song_page',
            sortable => true,
        },
#        {
#            label => trm('Size'),
#            type => 'number',
#            format => {
#                unitPrefix => 'metric',
#                maximumFractionDigits => 2,
#                postfix => 'Byte',
#                locale => 'en'
#            },
#            width => '1*',
#            key => 'song_size',
#            sortable => true,
#        },
        {
            label => trm('Note'),
            type => 'string',
            width => '3*',
            key => 'song_note',
            sortable => true,
        },
#       {
#            label => trm('Created'),
#            type => 'date',
#            format => 'yyyy-MM-dd HH:mm:ss Z',
#            width => '3*',
#            key => 'song_date',
#            sortable => true,
#       },
        
     ]
};

=head2 actionCfg

Only users who can write get any actions presented.

=cut

has actionCfg => sub {
    my $self = shift;
    return [] if $self->user and not $self->user->may('write');

    return [
        {
            label => trm('Add Song'),
            action => 'popup',
            addToContextMenu => false,
            name => 'songFormAdd',
            key => 'add',
            popupTitle => trm('New Song'),
            set => {
                minHeight => 600,
                minWidth => 500
            },
            backend => {
                plugin => 'SongForm',
                config => {
                    type => 'add'
                }
            }
        },
        {
            action => 'separator'
        },
        {
            label => trm('Edit Song'),
            action => 'popup',
            addToContextMenu => true,
            defaultAction => true,
            key => 'edit',
            name => 'songFormEdit',
            buttonSet => {
                enabled => false,
            },
            popupTitle => trm('Edit Song'),
            backend => {
                plugin => 'SongForm',
                config => {
                    type => 'edit'
                }
            }
        },
        {
            label => trm('Delete Song'),
            action => 'submitVerify',
            addToContextMenu => true,
            question => trm('Do you really want to delete the selected Song '),
            key => 'delete',
            buttonSet => {
                enabled => false,
            },
            actionHandler => sub {
                my $self = shift;
                my $args = shift;
                my $id = $args->{selection}{song_id};
                die mkerror(4992,"You have to select a song first")
                    if not $id;
                my $db = $self->user->db;
                if ($db->deleteData('song',$id) == 1){
                    return {
                         action => 'reload',
                    };
                }
                die mkerror(4993,"Faild to remove song $id");
                return {};
            }
        }
    ];
};

sub db {
    shift->user->mojoSqlDb;
};

sub _getFilter {
    my $self = shift;
    my $search = shift;
    my $filter = '';
    if ( $search ){
        $filter = "WHERE song_title LIKE ".$self->db->dbh->quote('%'.$search);
    }
    return $filter;
}

sub getTableRowCount {
    my $self = shift;
    my $args = shift;
    my $filter = $self->_getFilter($args->{formData}{song_title});
    return $self->db->query("SELECT count(song_id) AS count FROM song $filter")->hash->{count};
}

sub getTableData {
    my $self = shift;
    my $args = shift;
    my $filter = $self->_getFilter($args->{formData}{song_title});



( run in 0.935 second using v1.01-cache-2.11-cpan-364913b4093 )